ITPub博客

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

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

原创 区块链 作者:小程序开发 时间:2022-07-12 13:35:03 0 删除 编辑

file

一、说明

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

 

二、环境准备

 

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

peer lifecycle chaincode queryinstalled

file

 

三、重新打包代码

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

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

 

四、重新安装合约

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

peer lifecycle chaincode install mycc.tar.gz

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

peer lifecycle chaincode queryinstalled

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

file

 

五、重新审批

再次分别为  peer0.org1 和  peer0.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

需要把  sequence 和  version 改为审批时的值

 

 

七、查看已提交合约

执行一下命令:

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
	}
}

 


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70019616/viewspace-2905333/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
自橙一派www.zcypai.com公司专注于微信领域内的系统开发,主营业务包括有微信公众号开发和微信小程序开发等,提供运维指导,软件使用及推广引流服务。

注册时间:2022-07-03

  • 博文量
    15
  • 访问量
    11384