1. Description
In the previous article, I shared the installation and use of smart contracts. What if the business code needs to be modified? This article shares how to update the version of the installed contract.
2. Environmental preparation
Blockchain network installation: "Hyperledger Fabric 2.x Environment Construction"
Smart contract installation: "Hyperledger Fabric 2.x Custom Smart Contract"
Execute the following command to see the installed contract information:
peer lifecycle chaincode queryinstalled
3. Repackage the code
Repackage the latest contract source code:
peer lifecycle chaincode package mycc.tar.gz --path /opt/app/my-fabric-chaincode-java --lang java --label mycc
4. Reinstall the contract
Install the contracts again for the two institutions peer0.org1
and peer0.org2
:
peer lifecycle chaincode install mycc.tar.gz
Execute the following command to view the installed contract information again:
peer lifecycle chaincode queryinstalled
It can be found that a new record with the same Label name but different Package ID has been added:
5. Re-approval
Approved contracts for two institutions, peer0.org1
and peer0.org2
, respectively:
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 : Fill in the newly installedPackage ID
sequence : Because it is to approve the second contract, you need to fill2
version : just an identifier, which can be changed or not
Execute the following command to check the node approval status:
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name mycc --version 1.1 --sequence 2 --output json
return:
{
"approvals": {
"Org1MSP": true,
"Org2MSP": true
}
}
6. Resubmit
Execute the following command to submit the contract to the channel:
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 and version need to be changed to the value at the time of approval
7. View submitted contracts
Execute the following command:
peer lifecycle chaincode querycommitted --channelID mychannel --name mycc --output json
It can be seen that the contract with channel mychannel
name mycc
has been updated to version 1.1
:
{
"sequence": 2,
"version": "1.1",
"endorsement_plugin": "escc",
"validation_plugin": "vscc",
"validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==",
"collections": {},
"approvals": {
"Org1MSP": true,
"Org2MSP": true
}
}
Scan the QR code to follow for a surprise!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。