Skip to content

Commit

Permalink
🐛 Fix defaultValues initialization while updating assetType
Browse files Browse the repository at this point in the history
  • Loading branch information
andremacedopv committed Jan 25, 2023
1 parent fb34355 commit 684fe23
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions assets/dynamicAssetTypeConfig.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package assets

// ? Is there a way to not allow an asset be modified outside a transaction?

// dynamicAssetTypeConfig is the configuration data for the Dynamic assetTypes feature
var dynamicAssetTypeConfig = DynamicAssetType{}

Expand Down
4 changes: 3 additions & 1 deletion transactions/deleteAssetType.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
sw "github.com/goledgerdev/cc-tools/stubwrapper"
)

// ? Allow delete cascade?

// DeleteAssetType is the transaction which deletes a dynamic Asset Type
var DeleteAssetType = Transaction{
Tag: "deleteAssetType",
Expand Down Expand Up @@ -140,7 +142,7 @@ func handleRegisteredAssets(stub *sw.StubWrapper, tag string, force bool) ([]int

_, err = asset.Delete(stub)
if err != nil {
return nil, errors.WrapError(err, "could not force delete asset")
return nil, errors.WrapError(err, "could not force delete AssetType assets")
}
}

Expand Down
14 changes: 7 additions & 7 deletions transactions/updateAssetType.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,19 @@ func initilizeDefaultValues(stub *sw.StubWrapper, assetTag string, defaultValues
return nil, errors.WrapErrorWithStatus(err, "failed to unmarshal queryResponse values", http.StatusInternalServerError)
}

for _, propMap := range defaultValuesMap {
propTag := propMap["tag"].(string)
if _, ok := data[propTag]; !ok {
data[propTag] = propMap["defaultValue"]
}
}

asset, err := assets.NewAsset(data)
if err != nil {
return nil, errors.WrapError(err, "could not assemble asset type")
}
assetMap := (map[string]interface{})(asset)

for _, propMap := range defaultValuesMap {
propTag := propMap["tag"].(string)
if _, ok := assetMap[propTag]; !ok {
assetMap[propTag] = propMap["defaultValue"]
}
}

assetMap, err = asset.Update(stub, assetMap)
if err != nil {
return nil, errors.WrapError(err, "failed to update asset")
Expand Down

0 comments on commit 684fe23

Please sign in to comment.