Fix ledger queries chaincode-go InitLedger

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:
David Enyeart 2020-08-11 17:43:17 -04:00
parent 155a3e7e26
commit 0106b57b4f

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