github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/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 Golang 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  ### peer lifecycle chaincode getinstalledpackage example
    56  
    57  You can retrieve an installed chaincode package from a peer using the
    58  `peer lifecycle chaincode getinstalledpackage` command. Use the package
    59  identifier returned by `queryinstalled`.
    60  
    61    * Use the `--package-id` flag to pass in the chaincode package identifier. Use
    62    the `--output-directory` flag to specify where to write the chaincode package.
    63    If the output directory is not specified, the chaincode package will be written
    64    in the current directory.
    65  
    66    ```
    67    peer lifecycle chaincode getinstalledpackage --package-id myccv1:a7ca45a7cc85f1d89c905b775920361ed089a364e12a9b6d55ba75c965ddd6a9 --output-directory /tmp --peerAddresses peer0.org1.example.com:7051
    68    ```
    69  
    70  
    71  ### peer lifecycle chaincode approveformyorg example
    72  
    73  Once the chaincode package has been installed on your peers, you can approve
    74  a chaincode definition for your organization. The chaincode definition includes
    75  the important parameters of chaincode governance, including the chaincode name,
    76  version and the endorsement policy.
    77  
    78  Here is an example of the `peer lifecycle chaincode approveformyorg` command,
    79  which approves the definition of a chaincode  named `mycc` at version `1.0` on
    80  channel `mychannel`.
    81  
    82    * Use the `--package-id` flag to pass in the chaincode package identifier. Use
    83      the `--signature-policy` flag to define an endorsement policy for the chaincode.
    84      Use the ``init-required`` flag to request the execution of the ``Init``
    85      function to initialize the chaincode.
    86  
    87      ```
    88      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
    89      .
    90      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')"
    91      .
    92      2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
    93      2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051
    94      ```
    95  
    96    * You can also use the ``--channel-config-policy`` flag use a policy inside
    97      the channel configuration as the chaincode endorsement policy. The default
    98      endorsement policy is ``Channel/Application/Endorsement``
    99  
   100      ```
   101      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
   102      .
   103      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
   104      .
   105      2019-03-18 16:04:09.046 UTC [cli.lifecycle.chaincode] InitCmdFactory -> INFO 001 Retrieved channel (mychannel) orderer endpoint: orderer.example.com:7050
   106      2019-03-18 16:04:11.253 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [efba188ca77889cc1c328fc98e0bb12d3ad0abcda3f84da3714471c7c1e6c13c] committed with status (VALID) at peer0.org1.example.com:7051
   107      ```
   108  
   109  ### peer lifecycle chaincode checkcommitreadiness example
   110  
   111  You can check whether a chaincode definition is ready to be committed using the
   112  ``peer lifecycle chaincode checkcommitreadiness command, which will return
   113  successfully if a subsequent commit of the definition is expected to succeed. It 
   114  also outputs which organizations have approved the chaincode definition. If an
   115  organization has approved the chaincode definition specified in the command, the
   116  command will return a value of true. You can use this command to learn whether enough
   117  channel members have approved a chaincode definition to meet the
   118  ``Application/Channel/Endorsement`` policy (a majority by default) before the
   119  definition can be committed to a channel.
   120  
   121       * ```
   122      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
   123      .
   124      peer lifecycle chaincode checkcommitreadiness -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --name mycc --version 1.0 --init-required --sequence 1
   125      ```
   126  
   127      If successful, the command will return the organizations that have approved
   128      the chaincode definition.
   129  
   130      ```
   131      Chaincode definition for chaincode 'mycc', version '1.0', sequence '1' on channel
   132      'mychannel' approval status by org:
   133      Org1MSP: true
   134      Org2MSP: true
   135      ```
   136  
   137      * You can also use the `--output` flag to have the CLI format the output as
   138      JSON.
   139  
   140      ```
   141      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
   142      .
   143      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
   144      ```
   145  
   146      If successful, the command will return a JSON map that shows if an organization
   147      has approved the chaincode definition.
   148  
   149      ```
   150      {
   151         "Approvals": {
   152            "Org1MSP": true,
   153            "Org2MSP": true
   154         }
   155      }
   156      ```
   157  
   158  ### peer lifecycle chaincode commit example
   159  
   160  Once a sufficient number of organizations approve a chaincode definition for
   161  their organizations (a majority by default), one organization can commit the
   162  definition the channel using the ``peer lifecycle chaincode commit`` command:
   163  
   164    * This command needs to target the peers of other organizations on the channel
   165      to collect their organization endorsement for the definition.
   166  
   167      ```
   168      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
   169      .
   170      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
   171      .
   172      2019-03-18 16:14:27.258 UTC [chaincodeCmd] ClientWait -> INFO 001 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org2.example.com:9051
   173      2019-03-18 16:14:27.321 UTC [chaincodeCmd] ClientWait -> INFO 002 txid [b6f657a14689b27d69a50f39590b3949906b5a426f9d7f0dcee557f775e17882] committed with status (VALID) at peer0.org1.example.com:7051
   174      ```
   175  
   176  ### peer lifecycle chaincode querycommitted example
   177  
   178  You can query the chaincode definitions that have been committed to a channel by
   179  using the ``peer lifecycle chaincode querycommitted`` command. You can use this
   180  command to query the current definition sequence number before upgrading a
   181  chaincode.
   182  
   183    * You need to supply the chaincode name and channel name in order to query a 
   184      specific chaincode definition and the organizations that have approved it.
   185  
   186      ```
   187      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
   188      .
   189      peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --name mycc --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051
   190      .
   191      Committed chaincode definition for chaincode 'mycc' on channel 'mychannel':
   192      Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc
   193      Approvals: [Org1MSP: true, Org2MSP: true]
   194      ```
   195  
   196    * You can also specify just the channel name in order to query all chaincode
   197    definitions on that channel.
   198  
   199      ```
   200      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
   201      .
   202      peer lifecycle chaincode querycommitted -o orderer.example.com:7050 --channelID mychannel --tls --cafile $ORDERER_CA --peerAddresses peer0.org1.example.com:7051
   203      .
   204      Committed chaincode definitions on channel 'mychannel':
   205      Name: mycc, Version: 1, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc
   206      Name: yourcc, Version: 2, Sequence: 3, Endorsement Plugin: escc, Validation Plugin: vscc
   207      ```
   208  
   209  <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>.