Have the submitTransaction look at the results of submit.

The results of the submit must be returned by the chaincode.

Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
This commit is contained in:
Bret Harrison 2020-10-20 16:55:46 -04:00 committed by denyeart
parent 15740deec1
commit 524ee2d63f
2 changed files with 12 additions and 3 deletions

View file

@ -128,8 +128,16 @@ async function main() {
// This will be sent to both peers and if both peers endorse the transaction, the endorsed proposal will be sent
// to the orderer to be committed by each of the peer's to the channel ledger.
console.log('\n--> Submit Transaction: CreateAsset, creates new asset with ID, color, owner, size, and appraisedValue arguments');
await contract.submitTransaction('CreateAsset', 'asset13', 'yellow', '5', 'Tom', '1300');
console.log('*** Result: committed');
result = await contract.submitTransaction('CreateAsset', 'asset13', 'yellow', '5', 'Tom', '1300');
// The "submitTransaction" returns the value generated by the chaincode. Notice how we normally do not
// look at this value as the chaincodes are not returning a value. So for demonstration purposes we
// have the javascript version of the chaincode return a value on the function 'CreateAsset'.
// This value will be the same as the 'ReadAsset' results for the newly created asset.
// The other chaincode versions could be updated to also return a value.
// Having the chaincode return a value after after doing a create or update could avoid the application
// from making an "evaluateTransaction" call to get information on the asset added by the chaincode
// during the create or update.
console.log(`*** Result committed: ${prettyJSONString(result.toString())}`);
console.log('\n--> Evaluate Transaction: ReadAsset, function returns an asset with a given assetID');
result = await contract.evaluateTransaction('ReadAsset', 'asset13');

View file

@ -72,7 +72,8 @@ class AssetTransfer extends Contract {
Owner: owner,
AppraisedValue: appraisedValue,
};
return ctx.stub.putState(id, Buffer.from(JSON.stringify(asset)));
ctx.stub.putState(id, Buffer.from(JSON.stringify(asset)));
return JSON.stringify(asset);
}
// ReadAsset returns the asset stored in the world state with given id.