github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/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 Go chaincode. 9 10 * Use the `--path` flag to indicate the location of the chaincode. 11 The path must be a fully qualified path or a path relative to your present working directory. 12 * Use the `--label` flag to provide a chaincode package label of `myccv1` 13 that your organization will use to identify the package. 14 15 ``` 16 peer lifecycle chaincode package mycc.tar.gz --path $CHAINCODE_DIR --lang golang --label myccv1 17 ``` 18 19 ### peer lifecycle chaincode install example 20 21 After the chaincode is packaged, you can use the `peer chaincode install` command 22 to install the chaincode on your peers. 23 24 * Install the `mycc.tar.gz ` package on `peer0.org1.example.com:7051` (the 25 peer defined by `--peerAddresses`). 26 27 ``` 28 peer lifecycle chaincode install mycc.tar.gz --peerAddresses peer0.org1.example.com:7051 29 ``` 30 If successful, the command will return the package identifier. The 31 package ID is the package label combined with a hash of the chaincode 32 package taken by the peer. 33 ``` 34 2019-03-13 13:48:53.691 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nEmycc:ebd89878c2bbccf62f68c36072626359376aa83c36435a058d453e8dbfd894cc" > 35 2019-03-13 13:48:53.691 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 36 ``` 37 38 ### peer lifecycle chaincode queryinstalled example 39 40 You need to use the chaincode package identifier to approve a chaincode 41 definition for your organization. You can find the package ID for the 42 chaincodes you have installed by using the 43 `peer lifecycle chaincode queryinstalled` command: 44 45 ``` 46 peer lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051 47 ``` 48 49 A successful command will return the package ID associated with the 50 package label. 51 52 ``` 53 Get installed chaincodes on peer: 54 Package ID: myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9, Label: myccv1 55 ``` 56 57 * You can also use the `--output` flag to have the CLI format the output as 58 JSON. 59 60 ``` 61 peer lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051 --output json 62 ``` 63 64 If successful, the command will return the chaincodes you have installed as JSON. 65 66 ``` 67 { 68 "installed_chaincodes": [ 69 { 70 "package_id": "mycc_1:aab9981fa5649cfe25369fce7bb5086a69672a631e4f95c4af1b5198fe9f845b", 71 "label": "mycc_1", 72 "references": { 73 "mychannel": { 74 "chaincodes": [ 75 { 76 "name": "mycc", 77 "version": "1" 78 } 79 ] 80 } 81 } 82 } 83 ] 84 } 85 ``` 86 87 ### peer lifecycle chaincode getinstalledpackage example 88 89 You can retrieve an installed chaincode package from a peer using the 90 `peer lifecycle chaincode getinstalledpackage` command. Use the package 91 identifier returned by `queryinstalled`. 92 93 * Use the `--package-id` flag to pass in the chaincode package identifier. Use 94 the `--output-directory` flag to specify where to write the chaincode package. 95 If the output directory is not specified, the chaincode package will be written 96 in the current directory. 97 98 ``` 99 peer lifecycle chaincode getinstalledpackage --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --output-directory /tmp --peerAddresses peer0.org1.example.com:7051 100 ``` 101 102 ### peer lifecycle chaincode calculatepackageid example 103 104 You can calculate the package ID from a packaged chaincode without installing the chaincode on peers 105 using the `peer lifecycle chaincode calculatepackageid` command. 106 This command will be useful, for example, in the following cases: 107 108 * When multiple chaincode packages with the same label name are installed, 109 it is possible to identify which ID corresponds to which package later. 110 * To check whether a particular chaincode package is installed or not without 111 installing that package. 112 113 Calcuate the package ID for the `mycc.tar.gz` package: 114 115 ``` 116 peer lifecycle chaincode calculatepackageid mycc.tar.gz 117 ``` 118 119 A successful command will return the package ID for the packaged chaincode. 120 121 ``` 122 myccv1:cc7bb5f50a53c207f68d37e9423c32f968083282e5ffac00d41ffc5768dc1873 123 ``` 124 125 * You can also use the `--output` flag to have the CLI format the output as JSON. 126 127 ``` 128 peer lifecycle chaincode calculatepackageid mycc.tar.gz --output json 129 ``` 130 131 If successful, the command will return the chaincode package ID as JSON. 132 133 ``` 134 { 135 "package_id": "myccv1:cc7bb5f50a53c207f68d37e9423c32f968083282e5ffac00d41ffc5768dc1873" 136 } 137 ``` 138 139 ### peer lifecycle chaincode approveformyorg example 140 141 Once the chaincode package has been installed on your peers, you can approve 142 a chaincode definition for your organization. The chaincode definition includes 143 the important parameters of chaincode governance, including the chaincode name, 144 version and the endorsement policy. 145 146 Here is an example of the `peer lifecycle chaincode approveformyorg` command, 147 which approves the definition of a chaincode named `mycc` at version `1.0` on 148 channel `mychannel`. 149 150 * Use the `--package-id` flag to pass in the chaincode package identifier. Use 151 the `--signature-policy` flag to define an endorsement policy for the chaincode. 152 Use the `init-required` flag to request the execution of the `Init` 153 function to initialize the chaincode. 154 155 ``` 156 export ORDERER_CA=/opt/gopath/src/github.com/hechain20/hechain/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 157 158 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')" 159 160 2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050 161 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051 162 ``` 163 164 * You can also use the `--channel-config-policy` flag use a policy inside 165 the channel configuration as the chaincode endorsement policy. The default 166 endorsement policy is `Channel/Application/Endorsement` 167 168 ``` 169 export ORDERER_CA=/opt/gopath/src/github.com/hechain20/hechain/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 170 171 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 172 173 2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050 174 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051 175 ``` 176 177 ### peer lifecycle chaincode queryapproved example 178 179 You can query an organization's approved chaincode definition by using the `peer lifecycle chaincode queryapproved` command. 180 You can use this command to see the details (including package ID) of approved chaincode definitions. 181 182 * Here is an example of the `peer lifecycle chaincode queryapproved` command, 183 which queries the approved definition of a chaincode named `mycc` at sequence number `1` on 184 channel `mychannel`. 185 186 ``` 187 peer lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 1 188 189 Approved chaincode definition for chaincode 'mycc' on channel 'mychannel': 190 sequence: 1, version: 1, init-required: true, package-id: mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830, endorsement plugin: escc, validation plugin: vscc 191 ``` 192 193 If NO package is specified for the approved definition, this command will display an empty package ID. 194 195 * You can also use this command without specifying the sequence number in order to query the latest approved definition (latest: the newer of the currently defined sequence number and the next sequence number). 196 197 ``` 198 peer lifecycle chaincode queryapproved -C mychannel -n mycc 199 200 Approved chaincode definition for chaincode 'mycc' on channel 'mychannel': 201 sequence: 3, version: 3, init-required: false, package-id: mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830, endorsement plugin: escc, validation plugin: vscc 202 ``` 203 204 * You can also use the `--output` flag to have the CLI format the output as 205 JSON. 206 207 - When querying an approved chaincode definition for which package is specified 208 209 ``` 210 peer lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 1 --output json 211 ``` 212 213 If successful, the command will return a JSON that has the approved chaincode definition for chaincode `mycc` at sequence number `1` on channel `mychannel`. 214 215 ``` 216 { 217 "sequence": 1, 218 "version": "1", 219 "endorsement_plugin": "escc", 220 "validation_plugin": "vscc", 221 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 222 "collections": {}, 223 "init_required": true, 224 "source": { 225 "Type": { 226 "LocalPackage": { 227 "package_id": "mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830" 228 } 229 } 230 } 231 } 232 ``` 233 234 - When querying an approved chaincode definition for which package is NOT specified 235 236 ``` 237 peer lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 2 --output json 238 ``` 239 240 If successful, the command will return a JSON that has the approved chaincode definition for chaincode `mycc` at sequence number `2` on channel `mychannel`. 241 242 ``` 243 { 244 "sequence": 2, 245 "version": "2", 246 "endorsement_plugin": "escc", 247 "validation_plugin": "vscc", 248 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 249 "collections": {}, 250 "source": { 251 "Type": { 252 "Unavailable": {} 253 } 254 } 255 } 256 ``` 257 258 ### peer lifecycle chaincode checkcommitreadiness example 259 260 You can check whether a chaincode definition is ready to be committed using the 261 `peer lifecycle chaincode checkcommitreadiness` command, which will return 262 successfully if a subsequent commit of the definition is expected to succeed. It 263 also outputs which organizations have approved the chaincode definition. If an 264 organization has approved the chaincode definition specified in the command, the 265 command will return a value of true. You can use this command to learn whether enough 266 channel members have approved a chaincode definition to meet the 267 `/Channel/Application/Endorsement` policy (a majority by default) before the 268 definition can be committed to a channel. 269 270 * Here is an example of the `peer lifecycle chaincode checkcommitreadiness` command, 271 which checks a chaincode named `mycc` at version `1.0` on channel `mychannel`. 272 273 ``` 274 export ORDERER_CA=/opt/gopath/src/github.com/hechain20/hechain/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 275 276 peer lifecycle chaincode checkcommitreadiness -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --name mycc --version 1.0 --init-required --sequence 1 277 ``` 278 279 If successful, the command will return the organizations that have approved 280 the chaincode definition. 281 282 ``` 283 Chaincode definition for chaincode 'mycc', version '1.0', sequence '1' on channel 284 'mychannel' approval status by org: 285 Org1MSP: true 286 Org2MSP: true 287 ``` 288 289 * You can also use the `--output` flag to have the CLI format the output as 290 JSON. 291 292 ``` 293 export ORDERER_CA=/opt/gopath/src/github.com/hechain20/hechain/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 294 295 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 296 ``` 297 298 If successful, the command will return a JSON map that shows if an organization 299 has approved the chaincode definition. 300 301 ``` 302 { 303 "Approvals": { 304 "Org1MSP": true, 305 "Org2MSP": true 306 } 307 } 308 ``` 309 310 ### peer lifecycle chaincode commit example 311 312 Once a sufficient number of organizations approve a chaincode definition for 313 their organizations (a majority by default), one organization can commit the 314 definition the channel using the `peer lifecycle chaincode commit` command: 315 316 * This command needs to target the peers of other organizations on the channel 317 to collect their organization endorsement for the definition. 318 319 ``` 320 export ORDERER_CA=/opt/gopath/src/github.com/hechain20/hechain/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 321 322 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 323 324 2019-03-18 16:14:27.258 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org2.example.com:9051 325 2019-03-18 16:14:27.321 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org1.example.com:7051 326 ``` 327 328 ### peer lifecycle chaincode querycommitted example 329 330 You can query the chaincode definitions that have been committed to a channel by 331 using the `peer lifecycle chaincode querycommitted` command. You can use this 332 command to query the current definition sequence number before upgrading a 333 chaincode. 334 335 * You need to supply the chaincode name and channel name in order to query a 336 specific chaincode definition and the organizations that have approved it. 337 338 ``` 339 export ORDERER_CA=/opt/gopath/src/github.com/hechain20/hechain/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 340 341 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --name mycc --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 342 343 Committed chaincode definition for chaincode 'mycc' on channel 'mychannel': 344 Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc 345 Approvals: [Org1MSP: true, Org2MSP: true] 346 ``` 347 348 * You can also specify just the channel name in order to query all chaincode 349 definitions on that channel. 350 351 ``` 352 export ORDERER_CA=/opt/gopath/src/github.com/hechain20/hechain/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 353 354 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 355 356 Committed chaincode definitions on channel 'mychannel': 357 Name: mycc, Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc 358 Name: yourcc, Version: 2, Sequence: 3, Endorsement Plugin: escc, Validation Plugin: vscc 359 ``` 360 361 * You can also use the `--output` flag to have the CLI format the output as 362 JSON. 363 364 - For querying a specific chaincode definition 365 366 ``` 367 export ORDERER_CA=/opt/gopath/src/github.com/hechain20/hechain/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 368 369 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --name mycc --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 --output json 370 ``` 371 372 If successful, the command will return a JSON that has committed chaincode definition for chaincode 'mycc' on channel 'mychannel'. 373 374 ``` 375 { 376 "sequence": 1, 377 "version": "1", 378 "endorsement_plugin": "escc", 379 "validation_plugin": "vscc", 380 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 381 "collections": {}, 382 "init_required": true, 383 "approvals": { 384 "Org1MSP": true, 385 "Org2MSP": true 386 } 387 } 388 ``` 389 390 The `validation_parameter` is base64 encoded. An example of the command to decode it is as follows. 391 392 ``` 393 echo EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA== | base64 -d 394 395 /Channel/Application/Endorsement 396 ``` 397 398 - For querying all chaincode definitions on that channel 399 400 ``` 401 export ORDERER_CA=/opt/gopath/src/github.com/hechain20/hechain/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 402 403 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 --output json 404 ``` 405 406 If successful, the command will return a JSON that has committed chaincode definitions on channel 'mychannel'. 407 408 ``` 409 { 410 "chaincode_definitions": [ 411 { 412 "name": "mycc", 413 "sequence": 1, 414 "version": "1", 415 "endorsement_plugin": "escc", 416 "validation_plugin": "vscc", 417 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 418 "collections": {}, 419 "init_required": true 420 }, 421 { 422 "name": "yourcc", 423 "sequence": 3, 424 "version": "2", 425 "endorsement_plugin": "escc", 426 "validation_plugin": "vscc", 427 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 428 "collections": {} 429 } 430 ] 431 } 432 ``` 433 434 435 <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>.