admin管理员组文章数量:1609986
写在前面:7.1和7.2都是使用fabcar例子进行的实验,体会了将链码安装到peer上,以及更新、查询记录。
7.3中是以Commercial paper 为例子,在不同用户之间实现 发布物品信息、购买、赎回 功能。
1、前提准备:
确保 node 版本在8.9.0以上(7.2中介绍了如何更新),Docker 在18.06以上,还需要安装visual studio方便之后查看代码。
安装VS:
打开VS官网:https://code.visualstudio/Download
选择linux 64位
在vs压缩包所在位置,打开终端,输入:
sudo dpkg -i code_1.35.0-1559611369_amd64.deb
✨中间 code_1.35.0-1559611369_amd64 根据你自己下载的压缩包的名字而定。
这样之后VS安装成功
2、 Create the network
cd fabric-samples/commercial-paper
./network-starter.sh
我们可以使用docker network 来查看各container的信息
docker network inspect net_test
3、 Monitor the network as MagnetoCorp
打开实时监控:
./organization/magnetocorp/configuration/cli/monitordocker.sh net_test
4、Examine the commercial paper smart contract
打开一个新的终端:(可以使用文件夹打开到指定目录下,右键 打开终端)
cd commercial-paper/organization/magnetocorp
code contract
✨这一步 会自动调用vs打开代码,代码结构如图:
5、Deploy the smart contract to the channel
①Install and approve the smart contract as MagnetoCorp
cd commercial-paper/organization/magnetocorp
source magnetocorp.sh
peer lifecycle chaincode package cp.tar.gz --lang node --path ./contract --label cp_0
peer lifecycle chaincode install cp.tar.gz
✨在这里安装链码的时候,是报错了’‘’Error: failed to endorse chaincode install: rpc error: code = Unavailable desc = transport is closing‘’‘ 但是在第三步打开的监控器中看到的是执行成功,看到了Package ID。’‘’ INFO 04c Successfully installed chaincode with package ID ‘cp_0:50533b6cdf6c97d077641bb86e32dfbcbb9912ae15342672ee6449697eee90a3’
‘’‘’
查询一下:
peer lifecycle chaincode queryinstalled
的确是有的,安装成功!
export PACKAGE_ID=cp_0:50533b6cdf6c97d077641bb86e32dfbcbb9912ae15342672ee6449697eee90a3
✨package_ID根据自己电脑上显示的来。
peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example --channelID mychannel --name papercontract -v 0 --package-id $PACKAGE_ID --sequence 1 --tls --cafile $ORDERER_CA
②Install and approve the smart contract as DigiBank
cd commercial-paper/organization/digibank/
source digibank.sh
peer lifecycle chaincode package cp.tar.gz --lang node --path ./contract --label cp_0
peer lifecycle chaincode install cp.tar.gz
peer lifecycle chaincode queryinstalled
export PACKAGE_ID=cp_0:1ba598be4fa7195c9756baad61d85995685abe44771df95c41dafdba3fe43997
✨ID!!!
peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example --channelID mychannel --name papercontract -v 0 --package-id $PACKAGE_ID --sequence 1 --tls --cafile $ORDERER_CA
③Commit the chaincode definition to the channel
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example --peerAddresses localhost:7051 --tlsRootCertFiles ${PEER0_ORG1_CA} --peerAddresses localhost:9051 --tlsRootCertFiles ${PEER0_ORG2_CA} --channelID mychannel --name papercontract -v 0 --sequence 1 --tls --cafile $ORDERER_CA --waitForEvent
6、发布Issue
cd commercial-paper/organization/magnetocorp/application/
通过ls可以看到该目录下的文件
ls
可以通过 code issue.js 看一下发布信息的代码
① 安装依赖:
cd commercial-paper/organization/magnetocorp/application/
npm install
安装的依赖 node_modules
② 将身份信息加载到wallet中
node addToWallet.js
查询一下:
ls ../identity/user/isabella/wallet/
③发布Issue application
node issue.js
7、购买buy
cd commercial-paper/organization/digibank/application/
可以通过code buy.js 查看buy的具体实现过程
npm install
node addToWallet.js
node buy.js
8、赎回redeem
node redeem.js
9、 Clean up
cd fabric-samples/commercial-paper
./network-clean.sh
🆗!!!7.3完结~
本文标签: 文档FabricHyperledgerTutorialpaper
版权声明:本文标题:Hyperledger fabric 2.0(文档7.3 Commercial paper tutorial) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1728587119a1165024.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论