github.com/osdi23p228/fabric@v0.0.0-20221218062954-77808885f5db/docs/source/commands/peerlifecycle.md (about) 1 # peer lifecycle chaincode 2 3 The `peer lifecycle chaincode` subcommand allows administrators to use the 4 Fabric chaincode lifecycle to package a chaincode, install it on your peers, 5 approve a chaincode definition for your organization, and then commit the 6 definition to a channel. The chaincode is ready to be used after the definition 7 has been successfully committed to the channel. For more information, visit 8 [Fabric chaincode lifecycle](../chaincode_lifecycle.html). 9 10 *Note: These instructions use the Fabric chaincode lifecycle introduced in the 11 v2.0 release. If you would like to use the old lifecycle to install and 12 instantiate a chaincode, visit the [peer chaincode](peerchaincode.html) command 13 reference.* 14 15 ## Syntax 16 17 The `peer lifecycle chaincode` command has the following subcommands: 18 19 * package 20 * install 21 * queryinstalled 22 * getinstalledpackage 23 * approveformyorg 24 * queryapproved 25 * checkcommitreadiness 26 * commit 27 * querycommitted 28 29 Each peer lifecycle chaincode subcommand is described together with its options in its own 30 section in this topic. 31 32 ## peer lifecycle 33 ``` 34 Perform _lifecycle operations 35 36 Usage: 37 peer lifecycle [command] 38 39 Available Commands: 40 chaincode Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted 41 42 Flags: 43 -h, --help help for lifecycle 44 45 Use "peer lifecycle [command] --help" for more information about a command. 46 ``` 47 48 49 ## peer lifecycle chaincode 50 ``` 51 Perform chaincode operations: package|install|queryinstalled|getinstalledpackage|approveformyorg|queryapproved|checkcommitreadiness|commit|querycommitted 52 53 Usage: 54 peer lifecycle chaincode [command] 55 56 Available Commands: 57 approveformyorg Approve the chaincode definition for my org. 58 checkcommitreadiness Check whether a chaincode definition is ready to be committed on a channel. 59 commit Commit the chaincode definition on the channel. 60 getinstalledpackage Get an installed chaincode package from a peer. 61 install Install a chaincode. 62 package Package a chaincode 63 queryapproved Query an org's approved chaincode definition from its peer. 64 querycommitted Query the committed chaincode definitions by channel on a peer. 65 queryinstalled Query the installed chaincodes on a peer. 66 67 Flags: 68 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 69 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 70 --clientauth Use mutual TLS when communicating with the orderer endpoint 71 --connTimeout duration Timeout for client to connect (default 3s) 72 -h, --help help for chaincode 73 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 74 -o, --orderer string Ordering service endpoint 75 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer 76 --tls Use TLS when communicating with the orderer endpoint 77 --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint 78 79 Use "peer lifecycle chaincode [command] --help" for more information about a command. 80 ``` 81 82 83 ## peer lifecycle chaincode package 84 ``` 85 Package a chaincode and write the package to a file. 86 87 Usage: 88 peer lifecycle chaincode package [outputfile] [flags] 89 90 Flags: 91 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 92 -h, --help help for package 93 --label string The package label contains a human-readable description of the package 94 -l, --lang string Language the chaincode is written in (default "golang") 95 -p, --path string Path to the chaincode 96 --peerAddresses stringArray The addresses of the peers to connect to 97 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 98 99 Global Flags: 100 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 101 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 102 --clientauth Use mutual TLS when communicating with the orderer endpoint 103 --connTimeout duration Timeout for client to connect (default 3s) 104 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 105 -o, --orderer string Ordering service endpoint 106 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer 107 --tls Use TLS when communicating with the orderer endpoint 108 --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint 109 ``` 110 111 112 ## peer lifecycle chaincode install 113 ``` 114 Install a chaincode on a peer. 115 116 Usage: 117 peer lifecycle chaincode install [flags] 118 119 Flags: 120 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 121 -h, --help help for install 122 --peerAddresses stringArray The addresses of the peers to connect to 123 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 124 125 Global Flags: 126 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 127 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 128 --clientauth Use mutual TLS when communicating with the orderer endpoint 129 --connTimeout duration Timeout for client to connect (default 3s) 130 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 131 -o, --orderer string Ordering service endpoint 132 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer 133 --tls Use TLS when communicating with the orderer endpoint 134 --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint 135 ``` 136 137 138 ## peer lifecycle chaincode queryinstalled 139 ``` 140 Query the installed chaincodes on a peer. 141 142 Usage: 143 peer lifecycle chaincode queryinstalled [flags] 144 145 Flags: 146 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 147 -h, --help help for queryinstalled 148 -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format. 149 --peerAddresses stringArray The addresses of the peers to connect to 150 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 151 152 Global Flags: 153 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 154 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 155 --clientauth Use mutual TLS when communicating with the orderer endpoint 156 --connTimeout duration Timeout for client to connect (default 3s) 157 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 158 -o, --orderer string Ordering service endpoint 159 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer 160 --tls Use TLS when communicating with the orderer endpoint 161 --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint 162 ``` 163 164 165 ## peer lifecycle chaincode getinstalledpackage 166 ``` 167 Get an installed chaincode package from a peer. 168 169 Usage: 170 peer lifecycle chaincode getinstalledpackage [outputfile] [flags] 171 172 Flags: 173 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 174 -h, --help help for getinstalledpackage 175 --output-directory string The output directory to use when writing a chaincode install package to disk. Default is the current working directory. 176 --package-id string The identifier of the chaincode install package 177 --peerAddresses stringArray The addresses of the peers to connect to 178 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 179 180 Global Flags: 181 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 182 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 183 --clientauth Use mutual TLS when communicating with the orderer endpoint 184 --connTimeout duration Timeout for client to connect (default 3s) 185 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 186 -o, --orderer string Ordering service endpoint 187 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer 188 --tls Use TLS when communicating with the orderer endpoint 189 --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint 190 ``` 191 192 193 ## peer lifecycle chaincode approveformyorg 194 ``` 195 Approve the chaincode definition for my organization. 196 197 Usage: 198 peer lifecycle chaincode approveformyorg [flags] 199 200 Flags: 201 --channel-config-policy string The endorsement policy associated to this chaincode specified as a channel config policy reference 202 -C, --channelID string The channel on which this command should be executed 203 --collections-config string The fully qualified path to the collection JSON file including the file name 204 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 205 -E, --endorsement-plugin string The name of the endorsement plugin to be used for this chaincode 206 -h, --help help for approveformyorg 207 --init-required Whether the chaincode requires invoking 'init' 208 -n, --name string Name of the chaincode 209 --package-id string The identifier of the chaincode install package 210 --peerAddresses stringArray The addresses of the peers to connect to 211 --sequence int The sequence number of the chaincode definition for the channel 212 --signature-policy string The endorsement policy associated to this chaincode specified as a signature policy 213 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 214 -V, --validation-plugin string The name of the validation plugin to be used for this chaincode 215 -v, --version string Version of the chaincode 216 --waitForEvent Whether to wait for the event from each peer's deliver filtered service signifying that the transaction has been committed successfully (default true) 217 --waitForEventTimeout duration Time to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully (default 30s) 218 219 Global Flags: 220 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 221 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 222 --clientauth Use mutual TLS when communicating with the orderer endpoint 223 --connTimeout duration Timeout for client to connect (default 3s) 224 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 225 -o, --orderer string Ordering service endpoint 226 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer 227 --tls Use TLS when communicating with the orderer endpoint 228 --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint 229 ``` 230 231 232 ## peer lifecycle chaincode queryapproved 233 ``` 234 Query an organization's approved chaincode definition from its peer. 235 236 Usage: 237 peer lifecycle chaincode queryapproved [flags] 238 239 Flags: 240 -C, --channelID string The channel on which this command should be executed 241 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 242 -h, --help help for queryapproved 243 -n, --name string Name of the chaincode 244 -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format. 245 --peerAddresses stringArray The addresses of the peers to connect to 246 --sequence int The sequence number of the chaincode definition for the channel 247 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 248 249 Global Flags: 250 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 251 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 252 --clientauth Use mutual TLS when communicating with the orderer endpoint 253 --connTimeout duration Timeout for client to connect (default 3s) 254 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 255 -o, --orderer string Ordering service endpoint 256 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer 257 --tls Use TLS when communicating with the orderer endpoint 258 --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint 259 ``` 260 261 262 ## peer lifecycle chaincode checkcommitreadiness 263 ``` 264 Check whether a chaincode definition is ready to be committed on a channel. 265 266 Usage: 267 peer lifecycle chaincode checkcommitreadiness [flags] 268 269 Flags: 270 --channel-config-policy string The endorsement policy associated to this chaincode specified as a channel config policy reference 271 -C, --channelID string The channel on which this command should be executed 272 --collections-config string The fully qualified path to the collection JSON file including the file name 273 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 274 -E, --endorsement-plugin string The name of the endorsement plugin to be used for this chaincode 275 -h, --help help for checkcommitreadiness 276 --init-required Whether the chaincode requires invoking 'init' 277 -n, --name string Name of the chaincode 278 -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format. 279 --peerAddresses stringArray The addresses of the peers to connect to 280 --sequence int The sequence number of the chaincode definition for the channel 281 --signature-policy string The endorsement policy associated to this chaincode specified as a signature policy 282 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 283 -V, --validation-plugin string The name of the validation plugin to be used for this chaincode 284 -v, --version string Version of the chaincode 285 286 Global Flags: 287 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 288 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 289 --clientauth Use mutual TLS when communicating with the orderer endpoint 290 --connTimeout duration Timeout for client to connect (default 3s) 291 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 292 -o, --orderer string Ordering service endpoint 293 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer 294 --tls Use TLS when communicating with the orderer endpoint 295 --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint 296 ``` 297 298 299 ## peer lifecycle chaincode commit 300 ``` 301 Commit the chaincode definition on the channel. 302 303 Usage: 304 peer lifecycle chaincode commit [flags] 305 306 Flags: 307 --channel-config-policy string The endorsement policy associated to this chaincode specified as a channel config policy reference 308 -C, --channelID string The channel on which this command should be executed 309 --collections-config string The fully qualified path to the collection JSON file including the file name 310 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 311 -E, --endorsement-plugin string The name of the endorsement plugin to be used for this chaincode 312 -h, --help help for commit 313 --init-required Whether the chaincode requires invoking 'init' 314 -n, --name string Name of the chaincode 315 --peerAddresses stringArray The addresses of the peers to connect to 316 --sequence int The sequence number of the chaincode definition for the channel 317 --signature-policy string The endorsement policy associated to this chaincode specified as a signature policy 318 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 319 -V, --validation-plugin string The name of the validation plugin to be used for this chaincode 320 -v, --version string Version of the chaincode 321 --waitForEvent Whether to wait for the event from each peer's deliver filtered service signifying that the transaction has been committed successfully (default true) 322 --waitForEventTimeout duration Time to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully (default 30s) 323 324 Global Flags: 325 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 326 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 327 --clientauth Use mutual TLS when communicating with the orderer endpoint 328 --connTimeout duration Timeout for client to connect (default 3s) 329 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 330 -o, --orderer string Ordering service endpoint 331 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer 332 --tls Use TLS when communicating with the orderer endpoint 333 --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint 334 ``` 335 336 337 ## peer lifecycle chaincode querycommitted 338 ``` 339 Query the committed chaincode definitions by channel on a peer. Optional: provide a chaincode name to query a specific definition. 340 341 Usage: 342 peer lifecycle chaincode querycommitted [flags] 343 344 Flags: 345 -C, --channelID string The channel on which this command should be executed 346 --connectionProfile string The fully qualified path to the connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information 347 -h, --help help for querycommitted 348 -n, --name string Name of the chaincode 349 -O, --output string The output format for query results. Default is human-readable plain-text. json is currently the only supported format. 350 --peerAddresses stringArray The addresses of the peers to connect to 351 --tlsRootCertFiles stringArray If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag 352 353 Global Flags: 354 --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint 355 --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint 356 --clientauth Use mutual TLS when communicating with the orderer endpoint 357 --connTimeout duration Timeout for client to connect (default 3s) 358 --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint 359 -o, --orderer string Ordering service endpoint 360 --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer 361 --tls Use TLS when communicating with the orderer endpoint 362 --tlsHandshakeTimeShift duration The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint 363 ``` 364 365 366 ## Example Usage 367 368 ### peer lifecycle chaincode package example 369 370 A chaincode needs to be packaged before it can be installed on your peers. 371 This example uses the `peer lifecycle chaincode package` command to package 372 a Go chaincode. 373 374 * Use the `--path` flag to indicate the location of the chaincode. 375 The path must be a fully qualified path or a path relative to your present working directory. 376 * Use the `--label` flag to provide a chaincode package label of `myccv1` 377 that your organization will use to identify the package. 378 379 ``` 380 peer lifecycle chaincode package mycc.tar.gz --path $CHAINCODE_DIR --lang golang --label myccv1 381 ``` 382 383 ### peer lifecycle chaincode install example 384 385 After the chaincode is packaged, you can use the `peer chaincode install` command 386 to install the chaincode on your peers. 387 388 * Install the `mycc.tar.gz ` package on `peer0.org1.example.com:7051` (the 389 peer defined by `--peerAddresses`). 390 391 ``` 392 peer lifecycle chaincode install mycc.tar.gz --peerAddresses peer0.org1.example.com:7051 393 ``` 394 If successful, the command will return the package identifier. The 395 package ID is the package label combined with a hash of the chaincode 396 package taken by the peer. 397 ``` 398 2019-03-13 13:48:53.691 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nEmycc:ebd89878c2bbccf62f68c36072626359376aa83c36435a058d453e8dbfd894cc" > 399 2019-03-13 13:48:53.691 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 400 ``` 401 402 ### peer lifecycle chaincode queryinstalled example 403 404 You need to use the chaincode package identifier to approve a chaincode 405 definition for your organization. You can find the package ID for the 406 chaincodes you have installed by using the 407 `peer lifecycle chaincode queryinstalled` command: 408 409 ``` 410 peer lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051 411 ``` 412 413 A successful command will return the package ID associated with the 414 package label. 415 416 ``` 417 Get installed chaincodes on peer: 418 Package ID: myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9, Label: myccv1 419 ``` 420 421 * You can also use the `--output` flag to have the CLI format the output as 422 JSON. 423 424 ``` 425 peer lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051 --output json 426 ``` 427 428 If successful, the command will return the chaincodes you have installed as JSON. 429 430 ``` 431 { 432 "installed_chaincodes": [ 433 { 434 "package_id": "mycc_1:aab9981fa5649cfe25369fce7bb5086a69672a631e4f95c4af1b5198fe9f845b", 435 "label": "mycc_1", 436 "references": { 437 "mychannel": { 438 "chaincodes": [ 439 { 440 "name": "mycc", 441 "version": "1" 442 } 443 ] 444 } 445 } 446 } 447 ] 448 } 449 ``` 450 451 ### peer lifecycle chaincode getinstalledpackage example 452 453 You can retrieve an installed chaincode package from a peer using the 454 `peer lifecycle chaincode getinstalledpackage` command. Use the package 455 identifier returned by `queryinstalled`. 456 457 * Use the `--package-id` flag to pass in the chaincode package identifier. Use 458 the `--output-directory` flag to specify where to write the chaincode package. 459 If the output directory is not specified, the chaincode package will be written 460 in the current directory. 461 462 ``` 463 peer lifecycle chaincode getinstalledpackage --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --output-directory /tmp --peerAddresses peer0.org1.example.com:7051 464 ``` 465 466 467 ### peer lifecycle chaincode approveformyorg example 468 469 Once the chaincode package has been installed on your peers, you can approve 470 a chaincode definition for your organization. The chaincode definition includes 471 the important parameters of chaincode governance, including the chaincode name, 472 version and the endorsement policy. 473 474 Here is an example of the `peer lifecycle chaincode approveformyorg` command, 475 which approves the definition of a chaincode named `mycc` at version `1.0` on 476 channel `mychannel`. 477 478 * Use the `--package-id` flag to pass in the chaincode package identifier. Use 479 the `--signature-policy` flag to define an endorsement policy for the chaincode. 480 Use the `init-required` flag to request the execution of the `Init` 481 function to initialize the chaincode. 482 483 ``` 484 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 485 486 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')" 487 488 2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050 489 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051 490 ``` 491 492 * You can also use the `--channel-config-policy` flag use a policy inside 493 the channel configuration as the chaincode endorsement policy. The default 494 endorsement policy is `Channel/Application/Endorsement` 495 496 ``` 497 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 498 499 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 500 501 2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050 502 2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051 503 ``` 504 505 ### peer lifecycle chaincode queryapproved example 506 507 You can query an organization's approved chaincode definition by using the `peer lifecycle chaincode queryapproved` command. 508 You can use this command to see the details (including package ID) of approved chaincode definitions. 509 510 * Here is an example of the `peer lifecycle chaincode queryapproved` command, 511 which queries the approved definition of a chaincode named `mycc` at sequence number `1` on 512 channel `mychannel`. 513 514 ``` 515 peer lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 1 516 517 Approved chaincode definition for chaincode 'mycc' on channel 'mychannel': 518 sequence: 1, version: 1, init-required: true, package-id: mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830, endorsement plugin: escc, validation plugin: vscc 519 ``` 520 521 If NO package is specified for the approved definition, this command will display an empty package ID. 522 523 * 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). 524 525 ``` 526 peer lifecycle chaincode queryapproved -C mychannel -n mycc 527 528 Approved chaincode definition for chaincode 'mycc' on channel 'mychannel': 529 sequence: 3, version: 3, init-required: false, package-id: mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830, endorsement plugin: escc, validation plugin: vscc 530 ``` 531 532 * You can also use the `--output` flag to have the CLI format the output as 533 JSON. 534 535 - When querying an approved chaincode definition for which package is specified 536 537 ``` 538 peer lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 1 --output json 539 ``` 540 541 If successful, the command will return a JSON that has the approved chaincode definition for chaincode `mycc` at sequence number `1` on channel `mychannel`. 542 543 ``` 544 { 545 "sequence": 1, 546 "version": "1", 547 "endorsement_plugin": "escc", 548 "validation_plugin": "vscc", 549 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 550 "collections": {}, 551 "init_required": true, 552 "source": { 553 "Type": { 554 "LocalPackage": { 555 "package_id": "mycc_1:d02f72000e7c0f715840f51cb8d72d70bc1ba230552f8445dded0ec8b6e0b830" 556 } 557 } 558 } 559 } 560 ``` 561 562 - When querying an approved chaincode definition for which package is NOT specified 563 564 ``` 565 peer lifecycle chaincode queryapproved -C mychannel -n mycc --sequence 2 --output json 566 ``` 567 568 If successful, the command will return a JSON that has the approved chaincode definition for chaincode `mycc` at sequence number `2` on channel `mychannel`. 569 570 ``` 571 { 572 "sequence": 2, 573 "version": "2", 574 "endorsement_plugin": "escc", 575 "validation_plugin": "vscc", 576 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 577 "collections": {}, 578 "source": { 579 "Type": { 580 "Unavailable": {} 581 } 582 } 583 } 584 ``` 585 586 ### peer lifecycle chaincode checkcommitreadiness example 587 588 You can check whether a chaincode definition is ready to be committed using the 589 `peer lifecycle chaincode checkcommitreadiness` command, which will return 590 successfully if a subsequent commit of the definition is expected to succeed. It 591 also outputs which organizations have approved the chaincode definition. If an 592 organization has approved the chaincode definition specified in the command, the 593 command will return a value of true. You can use this command to learn whether enough 594 channel members have approved a chaincode definition to meet the 595 `Application/Channel/Endorsement` policy (a majority by default) before the 596 definition can be committed to a channel. 597 598 * Here is an example of the `peer lifecycle chaincode checkcommitreadiness` command, 599 which checks a chaincode named `mycc` at version `1.0` on channel `mychannel`. 600 601 ``` 602 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 603 604 peer lifecycle chaincode checkcommitreadiness -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --name mycc --version 1.0 --init-required --sequence 1 605 ``` 606 607 If successful, the command will return the organizations that have approved 608 the chaincode definition. 609 610 ``` 611 Chaincode definition for chaincode 'mycc', version '1.0', sequence '1' on channel 612 'mychannel' approval status by org: 613 Org1MSP: true 614 Org2MSP: true 615 ``` 616 617 * You can also use the `--output` flag to have the CLI format the output as 618 JSON. 619 620 ``` 621 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 622 623 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 624 ``` 625 626 If successful, the command will return a JSON map that shows if an organization 627 has approved the chaincode definition. 628 629 ``` 630 { 631 "Approvals": { 632 "Org1MSP": true, 633 "Org2MSP": true 634 } 635 } 636 ``` 637 638 ### peer lifecycle chaincode commit example 639 640 Once a sufficient number of organizations approve a chaincode definition for 641 their organizations (a majority by default), one organization can commit the 642 definition the channel using the `peer lifecycle chaincode commit` command: 643 644 * This command needs to target the peers of other organizations on the channel 645 to collect their organization endorsement for the definition. 646 647 ``` 648 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 649 650 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 651 652 2019-03-18 16:14:27.258 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org2.example.com:9051 653 2019-03-18 16:14:27.321 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org1.example.com:7051 654 ``` 655 656 ### peer lifecycle chaincode querycommitted example 657 658 You can query the chaincode definitions that have been committed to a channel by 659 using the `peer lifecycle chaincode querycommitted` command. You can use this 660 command to query the current definition sequence number before upgrading a 661 chaincode. 662 663 * You need to supply the chaincode name and channel name in order to query a 664 specific chaincode definition and the organizations that have approved it. 665 666 ``` 667 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 668 669 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --name mycc --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 670 671 Committed chaincode definition for chaincode 'mycc' on channel 'mychannel': 672 Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc 673 Approvals: [Org1MSP: true, Org2MSP: true] 674 ``` 675 676 * You can also specify just the channel name in order to query all chaincode 677 definitions on that channel. 678 679 ``` 680 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 681 682 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 683 684 Committed chaincode definitions on channel 'mychannel': 685 Name: mycc, Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc 686 Name: yourcc, Version: 2, Sequence: 3, Endorsement Plugin: escc, Validation Plugin: vscc 687 ``` 688 689 * You can also use the `--output` flag to have the CLI format the output as 690 JSON. 691 692 - For querying a specific chaincode definition 693 694 ``` 695 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 696 697 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 698 ``` 699 700 If successful, the command will return a JSON that has committed chaincode definition for chaincode 'mycc' on channel 'mychannel'. 701 702 ``` 703 { 704 "sequence": 1, 705 "version": "1", 706 "endorsement_plugin": "escc", 707 "validation_plugin": "vscc", 708 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 709 "collections": {}, 710 "init_required": true, 711 "approvals": { 712 "Org1MSP": true, 713 "Org2MSP": true 714 } 715 } 716 ``` 717 718 The `validation_parameter` is base64 encoded. An example of the command to decode it is as follows. 719 720 ``` 721 echo EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA== | base64 -d 722 723 /Channel/Application/Endorsement 724 ``` 725 726 - For querying all chaincode definitions on that channel 727 728 ``` 729 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 730 731 peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 --output json 732 ``` 733 734 If successful, the command will return a JSON that has committed chaincode definitions on channel 'mychannel'. 735 736 ``` 737 { 738 "chaincode_definitions": [ 739 { 740 "name": "mycc", 741 "sequence": 1, 742 "version": "1", 743 "endorsement_plugin": "escc", 744 "validation_plugin": "vscc", 745 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 746 "collections": {}, 747 "init_required": true 748 }, 749 { 750 "name": "yourcc", 751 "sequence": 3, 752 "version": "2", 753 "endorsement_plugin": "escc", 754 "validation_plugin": "vscc", 755 "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==", 756 "collections": {} 757 } 758 ] 759 } 760 ``` 761 762 763 <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>.