github.com/Hnampk/my-fabric@v0.0.0-20201028083322-75069da399c0/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 `--label` flag to provide a chaincode package label of `myccv1`
    11      that your organization will use to identify the package.
    12  
    13      ```
    14      peer lifecycle chaincode package mycc.tar.gz --path github.com/hyperledger/fabric-samples/chaincode/abstore/go/ --lang golang --label myccv1
    15      ```
    16  
    17  ### peer lifecycle chaincode install example
    18  
    19  After the chaincode is packaged, you can use the `peer chaincode install` command
    20  to install the chaincode on your peers.
    21  
    22    * Install the `mycc.tar.gz ` package on `peer0.org1.example.com:7051` (the
    23      peer defined by `--peerAddresses`).
    24  
    25      ```
    26      peer lifecycle chaincode install mycc.tar.gz --peerAddresses peer0.org1.example.com:7051
    27      ```
    28      If successful, the command will return the package identifier. The
    29      package ID is the package label combined with a hash of the chaincode
    30      package taken by the peer.
    31      ```
    32      2019-03-13 13:48:53.691 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nEmycc:ebd89878c2bbccf62f68c36072626359376aa83c36435a058d453e8dbfd894cc" >
    33      2019-03-13 13:48:53.691 UTC [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: mycc:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9
    34      ```
    35  
    36  ### peer lifecycle chaincode queryinstalled example
    37  
    38  You need to use the chaincode package identifier to approve a chaincode
    39  definition for your organization. You can find the package ID for the
    40  chaincodes you have installed by using the
    41  `peer lifecycle chaincode queryinstalled` command:
    42  
    43  ```
    44  peer lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051
    45  ```
    46  
    47  A successful command will return the package ID associated with the
    48  package label.
    49  
    50  ```
    51  Get installed chaincodes on peer:
    52  Package ID: myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9, Label: myccv1
    53  ```
    54  
    55    * You can also use the `--output` flag to have the CLI format the output as
    56      JSON.
    57  
    58      ```
    59      peer lifecycle chaincode queryinstalled --peerAddresses peer0.org1.example.com:7051 --output json
    60      ```
    61  
    62      If successful, the command will return the chaincodes you have installed as JSON.
    63  
    64      ```
    65      {
    66        "installed_chaincodes": [
    67          {
    68            "package_id": "mycc_1:aab9981fa5649cfe25369fce7bb5086a69672a631e4f95c4af1b5198fe9f845b",
    69            "label": "mycc_1",
    70            "references": {
    71              "mychannel": {
    72                "chaincodes": [
    73                  {
    74                    "name": "mycc",
    75                    "version": "1"
    76                  }
    77                ]
    78              }
    79            }
    80          }
    81        ]
    82      }
    83      ```
    84  
    85  ### peer lifecycle chaincode getinstalledpackage example
    86  
    87  You can retrieve an installed chaincode package from a peer using the
    88  `peer lifecycle chaincode getinstalledpackage` command. Use the package
    89  identifier returned by `queryinstalled`.
    90  
    91    * Use the `--package-id` flag to pass in the chaincode package identifier. Use
    92    the `--output-directory` flag to specify where to write the chaincode package.
    93    If the output directory is not specified, the chaincode package will be written
    94    in the current directory.
    95  
    96    ```
    97    peer lifecycle chaincode getinstalledpackage --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --output-directory /tmp --peerAddresses peer0.org1.example.com:7051
    98    ```
    99  
   100  
   101  ### peer lifecycle chaincode approveformyorg example
   102  
   103  Once the chaincode package has been installed on your peers, you can approve
   104  a chaincode definition for your organization. The chaincode definition includes
   105  the important parameters of chaincode governance, including the chaincode name,
   106  version and the endorsement policy.
   107  
   108  Here is an example of the `peer lifecycle chaincode approveformyorg` command,
   109  which approves the definition of a chaincode  named `mycc` at version `1.0` on
   110  channel `mychannel`.
   111  
   112    * Use the `--package-id` flag to pass in the chaincode package identifier. Use
   113      the `--signature-policy` flag to define an endorsement policy for the chaincode.
   114      Use the `init-required` flag to request the execution of the `Init`
   115      function to initialize the chaincode.
   116  
   117      ```
   118      export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
   119  
   120      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')"
   121  
   122      2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
   123      2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051
   124      ```
   125  
   126    * You can also use the `--channel-config-policy` flag use a policy inside
   127      the channel configuration as the chaincode endorsement policy. The default
   128      endorsement policy is `Channel/Application/Endorsement`
   129  
   130      ```
   131      export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
   132  
   133      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
   134  
   135      2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
   136      2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051
   137      ```
   138  
   139  ### peer lifecycle chaincode checkcommitreadiness example
   140  
   141  You can check whether a chaincode definition is ready to be committed using the
   142  `peer lifecycle chaincode checkcommitreadiness` command, which will return
   143  successfully if a subsequent commit of the definition is expected to succeed. It
   144  also outputs which organizations have approved the chaincode definition. If an
   145  organization has approved the chaincode definition specified in the command, the
   146  command will return a value of true. You can use this command to learn whether enough
   147  channel members have approved a chaincode definition to meet the
   148  `Application/Channel/Endorsement` policy (a majority by default) before the
   149  definition can be committed to a channel.
   150  
   151    * Here is an example of the `peer lifecycle chaincode checkcommitreadiness` command,
   152      which checks a chaincode named `mycc` at version `1.0` on channel `mychannel`.
   153  
   154      ```
   155      export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
   156  
   157      peer lifecycle chaincode checkcommitreadiness -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --name mycc --version 1.0 --init-required --sequence 1
   158      ```
   159  
   160      If successful, the command will return the organizations that have approved
   161      the chaincode definition.
   162  
   163      ```
   164      Chaincode definition for chaincode 'mycc', version '1.0', sequence '1' on channel
   165      'mychannel' approval status by org:
   166      Org1MSP: true
   167      Org2MSP: true
   168      ```
   169  
   170    * You can also use the `--output` flag to have the CLI format the output as
   171      JSON.
   172  
   173      ```
   174      export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
   175  
   176      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
   177      ```
   178  
   179      If successful, the command will return a JSON map that shows if an organization
   180      has approved the chaincode definition.
   181  
   182      ```
   183      {
   184         "Approvals": {
   185            "Org1MSP": true,
   186            "Org2MSP": true
   187         }
   188      }
   189      ```
   190  
   191  ### peer lifecycle chaincode commit example
   192  
   193  Once a sufficient number of organizations approve a chaincode definition for
   194  their organizations (a majority by default), one organization can commit the
   195  definition the channel using the `peer lifecycle chaincode commit` command:
   196  
   197    * This command needs to target the peers of other organizations on the channel
   198      to collect their organization endorsement for the definition.
   199  
   200      ```
   201      export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
   202  
   203      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
   204  
   205      2019-03-18 16:14:27.258 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org2.example.com:9051
   206      2019-03-18 16:14:27.321 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org1.example.com:7051
   207      ```
   208  
   209  ### peer lifecycle chaincode querycommitted example
   210  
   211  You can query the chaincode definitions that have been committed to a channel by
   212  using the `peer lifecycle chaincode querycommitted` command. You can use this
   213  command to query the current definition sequence number before upgrading a
   214  chaincode.
   215  
   216    * You need to supply the chaincode name and channel name in order to query a
   217      specific chaincode definition and the organizations that have approved it.
   218  
   219      ```
   220      export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
   221  
   222      peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --name mycc --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051
   223  
   224      Committed chaincode definition for chaincode 'mycc' on channel 'mychannel':
   225      Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc
   226      Approvals: [Org1MSP: true, Org2MSP: true]
   227      ```
   228  
   229    * You can also specify just the channel name in order to query all chaincode
   230    definitions on that channel.
   231  
   232      ```
   233      export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
   234  
   235      peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051
   236  
   237      Committed chaincode definitions on channel 'mychannel':
   238      Name: mycc, Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc
   239      Name: yourcc, Version: 2, Sequence: 3, Endorsement Plugin: escc, Validation Plugin: vscc
   240      ```
   241  
   242    * You can also use the `--output` flag to have the CLI format the output as
   243      JSON.
   244  
   245      - For querying a specific chaincode definition
   246  
   247        ```
   248        export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
   249  
   250        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
   251        ```
   252  
   253        If successful, the command will return a JSON that has committed chaincode definition for chaincode 'mycc' on channel 'mychannel'.
   254  
   255        ```
   256        {
   257          "sequence": 1,
   258          "version": "1",
   259          "endorsement_plugin": "escc",
   260          "validation_plugin": "vscc",
   261          "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==",
   262          "collections": {},
   263          "init_required": true,
   264          "approvals": {
   265            "Org1MSP": true,
   266            "Org2MSP": true
   267          }
   268        }
   269        ```
   270  
   271        The `validation_parameter` is base64 encoded. An example of the command to decode it is as follows.
   272  
   273        ```
   274        echo EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA== | base64 -d
   275  
   276         /Channel/Application/Endorsement
   277        ```
   278  
   279      - For querying all chaincode definitions on that channel
   280  
   281        ```
   282        export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
   283  
   284        peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051 --output json
   285        ```
   286  
   287        If successful, the command will return a JSON that has committed chaincode definitions on channel 'mychannel'.
   288  
   289        ```
   290        {
   291          "chaincode_definitions": [
   292            {
   293              "name": "mycc",
   294              "sequence": 1,
   295              "version": "1",
   296              "endorsement_plugin": "escc",
   297              "validation_plugin": "vscc",
   298              "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==",
   299              "collections": {},
   300              "init_required": true
   301            },
   302            {
   303              "name": "yourcc",
   304              "sequence": 3,
   305              "version": "2",
   306              "endorsement_plugin": "escc",
   307              "validation_plugin": "vscc",
   308              "validation_parameter": "EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==",
   309              "collections": {}
   310            }
   311          ]
   312        }
   313        ```
   314  
   315  
   316  <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>.