Skip to content

Commit

Permalink
Fix put recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
bandreghetti committed Feb 10, 2021
1 parent 8bfb21b commit b5c056e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions assets/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,30 @@ func (a *Asset) PutNew(stub shim.ChaincodeStubInterface) (map[string]interface{}
func putRecursive(stub shim.ChaincodeStubInterface, object map[string]interface{}, root bool) (map[string]interface{}, errors.ICCError) {
var err error

objAsAsset, err := NewAsset(object)
objAsKey, err := NewKey(object)
if err != nil {
return nil, errors.WrapError(err, "unable to create asset object")
}

if !root {
exists, err := objAsAsset.ExistsInLedger(stub)
exists, err := objAsKey.ExistsInLedger(stub)
if err != nil {
return nil, errors.WrapError(err, "failed checking if asset exists")
}
if exists {
asset, err := objAsAsset.GetRecursive(stub)
asset, err := objAsKey.GetRecursive(stub)
return *asset, err
}
}

objAsAsset, err := NewAsset(object)
if err != nil {
return nil, errors.WrapError(err, "unable to create asset object")
}

putAsset, err := objAsAsset.put(stub)
if err != nil {
return nil, errors.WrapError(err, "failed to put asset")
return nil, errors.WrapError(err, fmt.Sprintf("failed to put asset of type %s", objAsAsset.TypeTag()))
}

subAssets := objAsAsset.Type().SubAssets()
Expand Down Expand Up @@ -145,7 +150,7 @@ func putRecursive(stub shim.ChaincodeStubInterface, object map[string]interface{
}
putSubAsset, err := putRecursive(stub, obj, false)
if err != nil {
return nil, errors.WrapError(err, "failed to put sub-asset recursively")
return nil, errors.WrapError(err, fmt.Sprintf("failed to put sub-asset %s recursively", subAsset.Tag))
}
objArray[idx] = putSubAsset
}
Expand Down

0 comments on commit b5c056e

Please sign in to comment.