Fix ledger queries chaincode-go InitLedger (#293)

The InitLedger was not writing the composite key for the color index.
Therefore TransferAssetByColor was not working.

Now InitLedger will call CreateAsset which creates both the asset
and the color index entry.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
This commit is contained in:
denyeart 2020-08-11 17:51:05 -04:00 committed by GitHub
parent 155a3e7e26
commit 8e2535ee65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -436,15 +436,10 @@ func (t *SimpleChaincode) InitLedger(ctx contractapi.TransactionContextInterface
}
for _, asset := range assets {
assetBytes, err := json.Marshal(asset)
err := t.CreateAsset(ctx, asset.ID, asset.Color, asset.Size, asset.Owner, asset.AppraisedValue)
if err != nil {
return err
}
err = ctx.GetStub().PutState(asset.ID, assetBytes)
if err != nil {
return fmt.Errorf("failed to put to world state. %v", err)
}
}
return nil