mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-19 16:15:09 +00:00
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:
parent
15740deec1
commit
524ee2d63f
2 changed files with 12 additions and 3 deletions
|
|
@ -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
|
// 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.
|
// 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');
|
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');
|
result = await contract.submitTransaction('CreateAsset', 'asset13', 'yellow', '5', 'Tom', '1300');
|
||||||
console.log('*** Result: committed');
|
// 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');
|
console.log('\n--> Evaluate Transaction: ReadAsset, function returns an asset with a given assetID');
|
||||||
result = await contract.evaluateTransaction('ReadAsset', 'asset13');
|
result = await contract.evaluateTransaction('ReadAsset', 'asset13');
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,8 @@ class AssetTransfer extends Contract {
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
AppraisedValue: appraisedValue,
|
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.
|
// ReadAsset returns the asset stored in the world state with given id.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue