One 、 explain
In the last article, I shared the installation and use of smart contract , What if the business changes and the code needs to be modified ? This article shares how to version update installed contracts .
Two 、 Environmental preparation
Blockchain network installation :《Hyperledger Fabric 2.x Environment building 》
Smart contract installation :《Hyperledger Fabric 2.x Custom smart contracts 》
Execute the following command , You can see the installed contract information :
peer lifecycle chaincode queryinstalled
3、 ... and 、 Repackaging 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
Four 、 Reinstall the contract
Again, they are peer0.org1
and peer0.org2
Two agency installation contracts :
peer lifecycle chaincode install mycc.tar.gz
Execute the following command , Review the installed contract information :
peer lifecycle chaincode queryinstalled
It can be found that a new one has been added Label The same name Package ID Different records :
5、 ... and 、 Re approve
Again, they are peer0.org1
and peer0.org2
Two agencies approve contracts :
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 new installationPackage ID
sequence: Because it's the second contract , So you need to fill in2
version: Just the identifier , It can be changed but not changed
Execute the following command , Check 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、 ... and 、 To resubmit
Execute the following command , 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
Need to put sequence and version Change to the value at the time of approval
7、 ... and 、 View submitted contracts
Execute the order :
peer lifecycle chaincode querycommitted --channelID mychannel --name mycc --output json
You can see the passage now mychannel
The name is mycc
Your contract has been updated to 1.1
edition :
{
"sequence": 2,
"version": "1.1",
"endorsement_plugin": "escc",
"validation_plugin": "vscc",
"validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==",
"collections": {},
"approvals": {
"Org1MSP": true,
"Org2MSP": true
}
}
Code scanning, attention, surprise !