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