更新chaincode的过程,其实就是重新部署一次的过程。
新的chaincode部署后,会直接替换掉旧的chaincode。
步骤
1. 修改代码
我们还是使用之前的代码,不同的是,我们稍微做一点修改,在InitLedger函数中的数组中,多加一条数据
{ID: "asset7", Color: "white", Size: 20, Owner: "Michel", AppraisedValue: 900},
新的项目代码见这里:[异次元传送门]()
2. 打包chaincode
这里注意更新版本号
peer lifecycle chaincode package hello2.tar.gz --path ./chaincode-go-v2 --lang golang --label hello_2.0
3. 安装chaincode
先把包拷贝到peer容器中
docker cp hello2.tar.gz Container:PATH
执行安装和查询
peer lifecycle chaincode install ./hello2.tar.gz peer lifecycle chaincode queryinstalled
4. 批准chaincode
注意更新版本号,以及sequence值,sequence的值可由以下命令查到的结果加1
peer lifecycle chaincode querycommitted --channelID channel1 --name hello
批准chaincode
peer lifecycle chaincode approveformyorg -o orderer1.orgA:7050 --channelID channel1 --name hello --version 2.0 --package-id hello_2.0:56ad2efdc95e3bb0c9cbdd338544d615ae8bceba516f7752fec66cd8e92fd942 --sequence 2 --tls --cafile /etc/hyperledger/fabric/tls/root-orgA.crt
5. 提交chaincode到channel
先查询下有多少组织批准了chaincode
peer lifecycle chaincode checkcommitreadiness --channelID channel1 --name hello --version 2.0 --sequence 2 --output json
提交chaincode
peer lifecycle chaincode commit -o orderer1.orgA:7050 --channelID channel1 --name hello --version 2.0 --sequence 2 --tls --cafile /etc/hyperledger/fabric/tls/root-orgA.crt --peerAddresses peer1.orgA:8050 --tlsRootCertFiles /etc/hyperledger/fabric/tls/root-orgA.crt --peerAddresses peer1.orgB:8051 --tlsRootCertFiles /etc/hyperledger/fabric/tls/root-orgB.crt
查询下提交结果:
peer lifecycle chaincode querycommitted --channelID channel1 --name hello
可以看到版本号和sequence都变了。
另外还可以通过docker ps, 观察运行chaincode的容器,此时也变成了新的
6. 调用下新的chaincode
调用更新后的接口:
peer chaincode invoke -o orderer1.orgA:7050 --tls --cafile /etc/hyperledger/fabric/tls/root-orgA.crt -C channel1 -n hello --peerAddre sses peer1.orgA:8050 --tlsRootCertFiles /etc/hyperledger/fabric/tls/root-orgA.crt -c '{"function":"InitLedger","Args":[]}'
查询数据
peer chaincode query -C channel1 -n hello -c '{"Args":["GetAllAssets"]}'
可以看到我们新增加的记录出现了:
{ID: "asset7", Color: "white", Size: 20, Owner: "Michel", AppraisedValue: 900}
小结
可以看到,更新chaincode过程,基本上是个重新部署的过程,唯一需要注意name得和旧的chaincode保持一致,把版本号和sequence号升高即可
Next
现在chaincode也部署好了,整个fabric尽在少侠掌握中了,但你是否需要一个运维监控系统,来了解下整个fabric网络的健康状况呢?
需要的话就来施展飞行奇术吧:[fabric的运维监控]()
回复 how to buy cheap cytotec 取消回复