Improve unmarshalling in asset-transfer-basic Go cc

Although the current code works thanks to Go being quite
forgiving when it comes to pointers, it doesn't exhibit
the best coding style. This patch addresses this.

Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
This commit is contained in:
Arnaud J Le Hors 2020-08-05 12:48:00 -07:00 committed by denyeart
parent e2817762f1
commit 42026e2fd4

View file

@ -82,13 +82,13 @@ func (s *SmartContract) ReadAsset(ctx contractapi.TransactionContextInterface, i
return nil, fmt.Errorf("the asset %s does not exist", id)
}
var asset *Asset
var asset Asset
err = json.Unmarshal(assetJSON, &asset)
if err != nil {
return nil, err
}
return asset, nil
return &asset, nil
}
// UpdateAsset updates an existing asset in the world state with provided parameters.
@ -173,12 +173,12 @@ func (s *SmartContract) GetAllAssets(ctx contractapi.TransactionContextInterface
return nil, err
}
var asset *Asset
var asset Asset
err = json.Unmarshal(queryResponse.Value, &asset)
if err != nil {
return nil, err
}
assets = append(assets, asset)
assets = append(assets, &asset)
}
return assets, nil