github.com/osdi23p228/fabric@v0.0.0-20221218062954-77808885f5db/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 103 ### peer lifecycle chaincode approveformyorg example 104 105 Once the chaincode package has been installed on your peers, you can approve 106 a chaincode definition for your organization. The chaincode definition includes 107 the important parameters of chaincode governance, including the chaincode name, 108 version and the endorsement policy. 109 110 Here is an example of the `peer lifecycle chaincode approveformyorg` command, 111 which approves the definition of a chaincode named `mycc` at version `1.0` on 112 channel `mychannel`. 113 114 * Use the `--package-id` flag to pass in the chaincode package identifier. Use 115 the `--signature-policy` flag to define an endorsement policy for the chaincode. 116 Use the `init-required` flag to request the execution of the `Init` 117 function to initialize the chaincode. 118 119 ``` 120 export ORDERER_CA=/opt/gopath/src/github.com/osdi23p228/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 121 122 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')" 123 124 2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050 125 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051 126 ``` 127 128 * You can also use the `--channel-config-policy` flag use a policy inside 129 the channel configuration as the chaincode endorsement policy. The default 130 endorsement policy is `Channel/Application/Endorsement` 131 132 ``` 133 export ORDERER_CA=/opt/gopath/src/github.com/osdi23p228/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 134 135 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 136 137 2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050 138 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051 139 ``` 140 141 ### peer lifecycle chaincode queryapproved example 142 143 You can query an organization's approved chaincode definition by using the `peer lifecycle chaincode queryapproved` command. 144 You can use this command to see the details (including package ID) of approved chaincode definitions. 145 146 * Here is an example of the `peer lifecycle chaincode queryapproved` command, 147 which queries the approved definition of a chaincode named `mycc` at sequence number `1` on 148 channel `mychannel`. 149 150 ``` 151 peer lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 1 152 153 Approved chaincode definition for chaincode 'mycc' on channel 'mychannel': 154 sequence: 1, version: 1, init-required: true, package-id: mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830, endorsement plugin: escc, validation plugin: vscc 155 ``` 156 157 If NO package is specified for the approved definition, this command will display an empty package ID. 158 159 * 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). 160 161 ``` 162 peer lifecycle chaincode queryapproved -C mychannel -n mycc 163 164 Approved chaincode definition for chaincode 'mycc' on channel 'mychannel': 165 sequence: 3, version: 3, init-required: false, package-id: mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830, endorsement plugin: escc, validation plugin: vscc 166 ``` 167 168 * You can also use the `--output` flag to have the CLI format the output as 169 JSON. 170 171 - When querying an approved chaincode definition for which package is specified 172 173 ``` 174 peer lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 1 --output json 175 ``` 176 177 If successful, the command will return a JSON that has the approved chaincode definition for chaincode `mycc` at sequence number `1` on channel `mychannel`. 178 179 ``` 180 { 181 "sequence": 1, 182 "version": "1", 183 "endorsement_plugin": "escc", 184 "validation_plugin": "vscc", 185 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 186 "collections": {}, 187 "init_required": true, 188 "source": { 189 "Type": { 190 "LocalPackage": { 191 "package_id": "mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830" 192 } 193 } 194 } 195 } 196 ``` 197 198 - When querying an approved chaincode definition for which package is NOT specified 199 200 ``` 201 peer lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 2 --output json 202 ``` 203 204 If successful, the command will return a JSON that has the approved chaincode definition for chaincode `mycc` at sequence number `2` on channel `mychannel`. 205 206 ``` 207 { 208 "sequence": 2, 209 "version": "2", 210 "endorsement_plugin": "escc", 211 "validation_plugin": "vscc", 212 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 213 "collections": {}, 214 "source": { 215 "Type": { 216 "Unavailable": {} 217 } 218 } 219 } 220 ``` 221 222 ### peer lifecycle chaincode checkcommitreadiness example 223 224 You can check whether a chaincode definition is ready to be committed using the 225 `peer lifecycle chaincode checkcommitreadiness` command, which will return 226 successfully if a subsequent commit of the definition is expected to succeed. It 227 also outputs which organizations have approved the chaincode definition. If an 228 organization has approved the chaincode definition specified in the command, the 229 command will return a value of true. You can use this command to learn whether enough 230 channel members have approved a chaincode definition to meet the 231 `Application/Channel/Endorsement` policy (a majority by default) before the 232 definition can be committed to a channel. 233 234 * Here is an example of the `peer lifecycle chaincode checkcommitreadiness` command, 235 which checks a chaincode named `mycc` at version `1.0` on channel `mychannel`. 236 237 ``` 238 export ORDERER_CA=/opt/gopath/src/github.com/osdi23p228/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 239 240 peer lifecycle chaincode checkcommitreadiness -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --name mycc --version 1.0 --init-required --sequence 1 241 ``` 242 243 If successful, the command will return the organizations that have approved 244 the chaincode definition. 245 246 ``` 247 Chaincode definition for chaincode 'mycc', version '1.0', sequence '1' on channel 248 'mychannel' approval status by org: 249 Org1MSP: true 250 Org2MSP: true 251 ``` 252 253 * You can also use the `--output` flag to have the CLI format the output as 254 JSON. 255 256 ``` 257 export ORDERER_CA=/opt/gopath/src/github.com/osdi23p228/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 258 259 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 260 ``` 261 262 If successful, the command will return a JSON map that shows if an organization 263 has approved the chaincode definition. 264 265 ``` 266 { 267 "Approvals": { 268 "Org1MSP": true, 269 "Org2MSP": true 270 } 271 } 272 ``` 273 274 ### peer lifecycle chaincode commit example 275 276 Once a sufficient number of organizations approve a chaincode definition for 277 their organizations (a majority by default), one organization can commit the 278 definition the channel using the `peer lifecycle chaincode commit` command: 279 280 * This command needs to target the peers of other organizations on the channel 281 to collect their organization endorsement for the definition. 282 283 ``` 284 export ORDERER_CA=/opt/gopath/src/github.com/osdi23p228/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 285 286 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 287 288 2019-03-18 16:14:27.258 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org2.example.com:9051 289 2019-03-18 16:14:27.321 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org1.example.com:7051 290 ``` 291 292 ### peer lifecycle chaincode querycommitted example 293 294 You can query the chaincode definitions that have been committed to a channel by 295 using the `peer lifecycle chaincode querycommitted` command. You can use this 296 command to query the current definition sequence number before upgrading a 297 chaincode. 298 299 * You need to supply the chaincode name and channel name in order to query a 300 specific chaincode definition and the organizations that have approved it. 301 302 ``` 303 export ORDERER_CA=/opt/gopath/src/github.com/osdi23p228/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 304 305 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --name mycc --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 306 307 Committed chaincode definition for chaincode 'mycc' on channel 'mychannel': 308 Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc 309 Approvals: [Org1MSP: true, Org2MSP: true] 310 ``` 311 312 * You can also specify just the channel name in order to query all chaincode 313 definitions on that channel. 314 315 ``` 316 export ORDERER_CA=/opt/gopath/src/github.com/osdi23p228/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 317 318 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 319 320 Committed chaincode definitions on channel 'mychannel': 321 Name: mycc, Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc 322 Name: yourcc, Version: 2, Sequence: 3, Endorsement Plugin: escc, Validation Plugin: vscc 323 ``` 324 325 * You can also use the `--output` flag to have the CLI format the output as 326 JSON. 327 328 - For querying a specific chaincode definition 329 330 ``` 331 export ORDERER_CA=/opt/gopath/src/github.com/osdi23p228/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 332 333 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 334 ``` 335 336 If successful, the command will return a JSON that has committed chaincode definition for chaincode 'mycc' on channel 'mychannel'. 337 338 ``` 339 { 340 "sequence": 1, 341 "version": "1", 342 "endorsement_plugin": "escc", 343 "validation_plugin": "vscc", 344 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 345 "collections": {}, 346 "init_required": true, 347 "approvals": { 348 "Org1MSP": true, 349 "Org2MSP": true 350 } 351 } 352 ``` 353 354 The `validation_parameter` is base64 encoded. An example of the command to decode it is as follows. 355 356 ``` 357 echo EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA== | base64 -d 358 359 /Channel/Application/Endorsement 360 ``` 361 362 - For querying all chaincode definitions on that channel 363 364 ``` 365 export ORDERER_CA=/opt/gopath/src/github.com/osdi23p228/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 366 367 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 --output json 368 ``` 369 370 If successful, the command will return a JSON that has committed chaincode definitions on channel 'mychannel'. 371 372 ``` 373 { 374 "chaincode_definitions": [ 375 { 376 "name": "mycc", 377 "sequence": 1, 378 "version": "1", 379 "endorsement_plugin": "escc", 380 "validation_plugin": "vscc", 381 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 382 "collections": {}, 383 "init_required": true 384 }, 385 { 386 "name": "yourcc", 387 "sequence": 3, 388 "version": "2", 389 "endorsement_plugin": "escc", 390 "validation_plugin": "vscc", 391 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 392 "collections": {} 393 } 394 ] 395 } 396 ``` 397 398 399 <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>.