Hyperledger Fabric 2.x 动态更新智能合约
  avfPzsq5zrlL 2023年11月02日 69 0

Hyperledger Fabric 2.x 动态更新智能合约_区块链

一、说明

在上一篇文章中分享了智能合约的安装与使用,如果业务有变更代码需要修改怎么办呢?本文分享如何对已安装的合约进行版本更新。
 

二、环境准备

区块链网络安装:《Hyperledger Fabric 2.x 环境搭建》

智能合约安装:《Hyperledger Fabric 2.x 自定义智能合约》

 
执行以下命令,可以看到已安装的合约信息:

peer lifecycle chaincode queryinstalled

Hyperledger Fabric 2.x 动态更新智能合约_区块链_02


三、重新打包代码

重新把最新的合约源代码打包:

peer lifecycle chaincode package mycc.tar.gz --path /opt/app/my-fabric-chaincode-java --lang java --label mycc


四、重新安装合约

再次分别为 peer0.org1peer0.org2 两个机构安装合约:

peer lifecycle chaincode install mycc.tar.gz

执行以下命令,重新查看已安装的合约信息:

peer lifecycle chaincode queryinstalled

可以发现新增加了一条 Label 名称相同 Package ID 不一样的记录:

Hyperledger Fabric 2.x 动态更新智能合约_智能合约_03


五、重新审批

再次分别为 peer0.org1peer0.org2 两个机构审批合约:

peer lifecycle chaincode approveformyorg \
-o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls \
--cafile ${MSP_PATH}/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem \
--channelID mychannel \
--name mycc \
--version 1.1 \
--package-id mycc:ecd2abc60ea098508aeefc135d8838787e9c1e3b8e411386a23ca56b7dfed758 \
--sequence 2

package-id:需填入新安装的 Package ID

sequence:因为是审批第二个合约,所以需要填 2

version:只是标识符,可改可不改

 
执行以下命令,检查节点审批状态:

peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 1.1 --sequence 2 --output json

返回:

{
"approvals": {
"Org1MSP": true,
"Org2MSP": true
}
}


六、重新提交

执行以下命令,向通道提交合约:

peer lifecycle chaincode commit \
-o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls \
--cafile ${MSP_PATH}/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem \
--channelID mychannel \
--name mycc \
--peerAddresses localhost:7051 \
--tlsRootCertFiles ${MSP_PATH}/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt \
--peerAddresses localhost:9051 \
--tlsRootCertFiles ${MSP_PATH}/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt \
--version 1.1 \
--sequence 2

需要把 sequenceversion 改为审批时的值


七、查看已提交合约

执行一下命令:

peer lifecycle chaincode querycommitted --channelID mychannel --name mycc --output json

可以看到现在通道 mychannel 名字为 mycc 的合约已经更新为 1.1 版本:

{
"sequence": 2,
"version": "1.1",
"endorsement_plugin": "escc",
"validation_plugin": "vscc",
"validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==",
"collections": {},
"approvals": {
"Org1MSP": true,
"Org2MSP": true
}
}
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
avfPzsq5zrlL