Skip to content

Commit

Permalink
✨ Allow list of ATs on dynamic creation
Browse files Browse the repository at this point in the history
  • Loading branch information
andremacedopv committed Jan 12, 2023
1 parent a281c6a commit d625387
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions transactions/createAssetType.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,49 @@ var CreateAssetType = Transaction{
{
Tag: "assetType",
Description: "Asset Type to be created.",
DataType: "@object",
DataType: "[]@object",
Required: true,
},
},
Routine: func(stub *sw.StubWrapper, req map[string]interface{}) ([]byte, errors.ICCError) {
// This is safe to do because validation is done before calling routine
assetType := req["assetType"].(map[string]interface{})
assetTypes := req["assetType"].([]interface{})
list := make([]assets.AssetType, 0)

for _, assetType := range assetTypes {
assetTypeMap := assetType.(map[string]interface{})

props := make([]assets.AssetProp, len(assetTypeMap["props"].([]interface{})))
for i, prop := range assetTypeMap["props"].([]interface{}) {
propMap := prop.(map[string]interface{})

props := make([]assets.AssetProp, len(assetType["props"].([]interface{})))
for i, prop := range assetType["props"].([]interface{}) {
propMap := prop.(map[string]interface{})
writersArray := propMap["writers"].([]interface{})
writers := make([]string, len(writersArray))
for j, writer := range writersArray {
writers[j] = writer.(string)
}

writersArray := propMap["writers"].([]interface{})
writers := make([]string, len(writersArray))
for j, writer := range writersArray {
writers[j] = writer.(string)
props[i] = assets.AssetProp{
Tag: propMap["tag"].(string),
Label: propMap["label"].(string),
Required: propMap["required"].(bool),
DataType: propMap["dataType"].(string),
IsKey: propMap["isKey"].(bool),
Writers: writers,
}
}

props[i] = assets.AssetProp{
Tag: propMap["tag"].(string),
Label: propMap["label"].(string),
Required: propMap["required"].(bool),
DataType: propMap["dataType"].(string),
IsKey: propMap["isKey"].(bool),
Writers: writers,
var newAssetType = assets.AssetType{
Tag: assetTypeMap["tag"].(string),
Label: assetTypeMap["label"].(string),
Description: assetTypeMap["description"].(string),
Props: props,
}
}

var newAssetType = assets.AssetType{
Tag: assetType["tag"].(string),
Label: assetType["label"].(string),
Description: assetType["description"].(string),
Props: props,
list = append(list, newAssetType)
}

// TODO: Check if asset type already exists

// Add asset type to assetTypeList
list := make([]assets.AssetType, 0)
list = append(list, newAssetType)

assets.UpdateAssetList(list)

resBytes, err := json.Marshal(list)
Expand Down

0 comments on commit d625387

Please sign in to comment.