官术网_书友最值得收藏!

Invoking the assermgr chaincode

Next, we can start to invoke the remaining chaincode methods: Order, Ship, and Distribute

  1. To order the device from OEM, we need to pass three parameters to the chaincode—assetId, Comment, and Location. Here, assetId is 100, and we will assume that Location is New York.
  2. Now, issue invoke to call the Order method in the assetmgr chaincode. The command is as follows:
    peer chaincode invoke -n mycc -c '{"Args":["Order", "100", "initial order from  
school", "New York"]}' -C myc

  1. If all goes well, you should see the following result. The log shows that the chaincode has been invoked successfully. We can see that the result is successfully saved to blockchain:
  1. In our assetmgr, we have defined a query method. We can invoke this method to verify whether the records have been saved in the Fabric blockchain. Issue the following query command with assetId as 100:
     peer chaincode query -C myc -n mycc -c '{"Args":["query","100"]}'

We can find the asset with an assetId of 100 from the Fabric ledger:

  1. Once the OEM receives the order, it starts to work and produce the iPad device. Then, the OEM ships the device to the school. To do this, issue the following Ship command with assetId, Comment, and Location:
peer chaincode invoke -n mycc -c '{"Args":["Ship", "100", "OEM deliver ipad to school", "New Jersey"]}' -C myc

The following screenshot will be the output of the previous code:

  1. Once the device is received, the school will distribute the device to the student. Issue the following Distribute command with assetId, Comment, and Location:
peer chaincode invoke -n mycc -c '{"Args":["Distribute", "100", "Distribute device to student", "New York"]}' -C myc

We should see the following result:

  1. We have now completed the entire process for our demo use case. As we discussed earlier, blockchain is a ledger system; it will keep track of all transactions. Once records are saved to the blockchain, they cannot be altered. We should be able to see this historical transaction data. In our asset manager example, we issued the Order, Ship, and Distribute commands and the related chaincode was invoked. All related asset transaction records should be kept in the blockchain. Let's verify this by issuing the getHistory command:
peer chaincode query -C myc -n mycc -c '{"Args":["getHistory","100"]}'

This command will provide the following results:

As we can see, the getHistory command returns all of the transaction records we invoked from Fabric blockchain.

主站蜘蛛池模板: 云霄县| 从化市| 安徽省| 高安市| 阜宁县| 聂荣县| 江都市| 南华县| 福州市| 美姑县| 策勒县| 长葛市| 准格尔旗| 明星| 屏南县| 来安县| 阿勒泰市| 阜阳市| 甘泉县| 阿图什市| 门头沟区| 蒙阴县| 永年县| 琼中| 尼木县| 南岸区| 开封县| 井冈山市| 滁州市| 鄂托克前旗| 枣庄市| 滁州市| 肥乡县| 四川省| 上栗县| 巨鹿县| 彰化市| 陇川县| 盖州市| 绵阳市| 合肥市|