Hands-On Blockchain with Hyperledger
by Nitin Gaur, Luc Desrosiers, Venkatraman Ramakrishna, Petr Novotny, Salman A. Baset, Anthony O'Dowd
Creating an asset
Now that we can implement our first chaincode function, we will move on and implement a requestTrade function, which will create a new trade agreement with the status REQUESTED and then record that agreement on the ledger.
The implementation of the function is shown in the following snippet. As you will see, in line 9 we verify that the invoker is a member of ImporterOrg and has permission to invoke the function. From lines 13 to 21 we validate and extract the arguments. In line 23, we create a new instance of TradeAgreement initiated with the received arguments. As we learned earlier, the ledger stores values in the form of arrays of bytes. Thus, in line 24 we serialize TradeAgreement with JSON into an array of bytes. In ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access