github.com/yous1230/fabric@v2.0.0-beta.0.20191224111736-74345bee6ac2+incompatible/docs/wrappers/peer_lifecycle_chaincode_postscript.md (about) 1 2 ## Example Usage 3 4 ### peer lifecycle chaincode package example 5 6 A chaincode needs to be packaged before it can be installed on your peers. 7 This example uses the `peer lifecycle chaincode package` command to package 8 a Golang chaincode. 9 10 * Use the `--label` flag to provide a chaincode package label of `myccv1` 11 that your organization will use to identify the package. 12 13 ``` 14 peer lifecycle chaincode package mycc.tar.gz --path github.com/hyperledger/fabric-samples/chaincode/abstore/go/ --lang golang --label myccv1 15 ``` 16 17 ### peer lifecycle chaincode install example 18 19 After the chaincode is packaged, you can use the `peer chaincode install` command 20 to install the chaincode on your peers. 21 22 * Install the `mycc.tar.gz ` package on `peer0.org1.example.com:7051` (the 23 peer defined by `--peerAddresses`). 24 25 ``` 26 peer lifecycle chaincode install mycc.tar.gz --peerAddresses peer0.org1.example.com:7051 27 ``` 28 If successful, the command will return the package identifier. The 29 package ID is the package label combined with a hash of the chaincode 30 package taken by the peer. 31 ``` 32 2019-03-13 13:48:53.691 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nEmycc:ebd89878c2bbccf62f68c36072626359376aa83c36435a058d453e8dbfd894cc" > 33 2019-03-13 13:48:53.691 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 34 ``` 35 36 ### peer lifecycle chaincode queryinstalled example 37 38 You need to use the chaincode package identifier to approve a chaincode 39 definition for your organization. You can find the package ID for the 40 chaincodes you have installed by using the 41 `peer lifecycle chaincode queryinstalled` command: 42 43 ``` 44 peer lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051 45 ``` 46 47 A successful command will return the package ID associated with the 48 package label. 49 50 ``` 51 Get installed chaincodes on peer: 52 Package ID: myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9, Label: myccv1 53 ``` 54 55 ### peer lifecycle chaincode getinstalledpackage example 56 57 You can retrieve an installed chaincode package from a peer using the 58 `peer lifecycle chaincode getinstalledpackage` command. Use the package 59 identifier returned by `queryinstalled`. 60 61 * Use the `--package-id` flag to pass in the chaincode package identifier. Use 62 the `--output-directory` flag to specify where to write the chaincode package. 63 If the output directory is not specified, the chaincode package will be written 64 in the current directory. 65 66 ``` 67 peer lifecycle chaincode getinstalledpackage --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --output-directory /tmp --peerAddresses peer0.org1.example.com:7051 68 ``` 69 70 71 ### peer lifecycle chaincode approveformyorg example 72 73 Once the chaincode package has been installed on your peers, you can approve 74 a chaincode definition for your organization. The chaincode definition includes 75 the important parameters of chaincode governance, including the chaincode name, 76 version and the endorsement policy. 77 78 Here is an example of the `peer lifecycle chaincode approveformyorg` command, 79 which approves the definition of a chaincode named `mycc` at version `1.0` on 80 channel `mychannel`. 81 82 * Use the `--package-id` flag to pass in the chaincode package identifier. Use 83 the `--signature-policy` flag to define an endorsement policy for the chaincode. 84 Use the `init-required` flag to request the execution of the `Init` 85 function to initialize the chaincode. 86 87 ``` 88 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 89 90 peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --tls --cafile $ORDERER_CA --channelID mychannel --name mycc --version 1.0 --init-required --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --sequence 1 --signature-policy "AND ('Org1MSP.peer','Org2MSP.peer')" 91 92 2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050 93 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051 94 ``` 95 96 * You can also use the `--channel-config-policy` flag use a policy inside 97 the channel configuration as the chaincode endorsement policy. The default 98 endorsement policy is `Channel/Application/Endorsement` 99 100 ``` 101 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 102 103 peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --tls --cafile $ORDERER_CA --channelID mychannel --name mycc --version 1.0 --init-required --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --sequence 1 --channel-config-policy Channel/Application/Admins 104 105 2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050 106 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051 107 ``` 108 109 ### peer lifecycle chaincode checkcommitreadiness example 110 111 You can check whether a chaincode definition is ready to be committed using the 112 `peer lifecycle chaincode checkcommitreadiness` command, which will return 113 successfully if a subsequent commit of the definition is expected to succeed. It 114 also outputs which organizations have approved the chaincode definition. If an 115 organization has approved the chaincode definition specified in the command, the 116 command will return a value of true. You can use this command to learn whether enough 117 channel members have approved a chaincode definition to meet the 118 `Application/Channel/Endorsement` policy (a majority by default) before the 119 definition can be committed to a channel. 120 121 * Here is an example of the `peer lifecycle chaincode checkcommitreadiness` command, 122 which checks a chaincode named `mycc` at version `1.0` on channel `mychannel`. 123 124 ``` 125 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 126 127 peer lifecycle chaincode checkcommitreadiness -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --name mycc --version 1.0 --init-required --sequence 1 128 ``` 129 130 If successful, the command will return the organizations that have approved 131 the chaincode definition. 132 133 ``` 134 Chaincode definition for chaincode 'mycc', version '1.0', sequence '1' on channel 135 'mychannel' approval status by org: 136 Org1MSP: true 137 Org2MSP: true 138 ``` 139 140 * You can also use the `--output` flag to have the CLI format the output as 141 JSON. 142 143 ``` 144 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 145 146 peer lifecycle chaincode checkcommitreadiness -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --name mycc --version 1.0 --init-required --sequence 1 --output json 147 ``` 148 149 If successful, the command will return a JSON map that shows if an organization 150 has approved the chaincode definition. 151 152 ``` 153 { 154 "Approvals": { 155 "Org1MSP": true, 156 "Org2MSP": true 157 } 158 } 159 ``` 160 161 ### peer lifecycle chaincode commit example 162 163 Once a sufficient number of organizations approve a chaincode definition for 164 their organizations (a majority by default), one organization can commit the 165 definition the channel using the `peer lifecycle chaincode commit` command: 166 167 * This command needs to target the peers of other organizations on the channel 168 to collect their organization endorsement for the definition. 169 170 ``` 171 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 172 173 peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID mychannel --name mycc --version 1.0 --sequence 1 --init-required --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 --peerAddresses peer0.org2.example.com:9051 174 175 2019-03-18 16:14:27.258 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org2.example.com:9051 176 2019-03-18 16:14:27.321 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org1.example.com:7051 177 ``` 178 179 ### peer lifecycle chaincode querycommitted example 180 181 You can query the chaincode definitions that have been committed to a channel by 182 using the `peer lifecycle chaincode querycommitted` command. You can use this 183 command to query the current definition sequence number before upgrading a 184 chaincode. 185 186 * You need to supply the chaincode name and channel name in order to query a 187 specific chaincode definition and the organizations that have approved it. 188 189 ``` 190 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 191 192 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --name mycc --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 193 194 Committed chaincode definition for chaincode 'mycc' on channel 'mychannel': 195 Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc 196 Approvals: [Org1MSP: true, Org2MSP: true] 197 ``` 198 199 * You can also specify just the channel name in order to query all chaincode 200 definitions on that channel. 201 202 ``` 203 export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 204 205 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 206 207 Committed chaincode definitions on channel 'mychannel': 208 Name: mycc, Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc 209 Name: yourcc, Version: 2, Sequence: 3, Endorsement Plugin: escc, Validation Plugin: vscc 210 ``` 211 212 <a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.