Skip to content

Commit

Permalink
✨ Update store and restore asset type list to use helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
andremacedopv committed Jan 19, 2023
1 parent 9acbfa7 commit 449f945
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions assets/assetListFuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,8 @@ func ReplaceAssetType(assetType AssetType, l []AssetType) []AssetType {

// StoreAssetList stores the current assetList on the blockchain
func StoreAssetList(stub *sw.StubWrapper) errors.ICCError {
list := AssetTypeList()
listJson, err := json.Marshal(list)
if err != nil {
return errors.NewCCError("error marshaling asset list", http.StatusInternalServerError)
}
assetList := AssetTypeList()
l := ArrayFromAssetTypeList(assetList)

listKey, err := NewKey(map[string]interface{}{
"@assetType": "assetTypeListData",
Expand All @@ -92,7 +89,7 @@ func StoreAssetList(stub *sw.StubWrapper) errors.ICCError {
}
listMap := (map[string]interface{})(*listAsset)

listMap["list"] = listJson
listMap["list"] = l

_, err = listAsset.Update(stub, listMap)
if err != nil {
Expand All @@ -102,7 +99,7 @@ func StoreAssetList(stub *sw.StubWrapper) errors.ICCError {
listMap := map[string]interface{}{
"@assetType": "assetTypeListData",
"id": "primary",
"list": listJson,
"list": l,
}

listAsset, err := NewAsset(listMap)
Expand Down Expand Up @@ -141,15 +138,9 @@ func RestoreAssetList(stub *sw.StubWrapper) errors.ICCError {
}
listMap := (map[string]interface{})(*listAsset)

listJson := listMap["list"].([]byte)

var newList []AssetType
nerr := json.Unmarshal(listJson, &newList)
if nerr != nil {
return errors.NewCCError("error unmarshaling asset list", http.StatusInternalServerError)
}
l := AssetTypeListFromArray(listMap["list"].([]map[string]interface{}))

ReplaceAssetList(newList)
ReplaceAssetList(l)
}

return nil
Expand Down

0 comments on commit 449f945

Please sign in to comment.