github.com/kaituanwang/hyperledger@v2.0.1+incompatible/docs/wrappers/peer_channel_postscript.md (about)

     1  ## Example Usage
     2  
     3  ### peer channel create examples
     4  
     5  Here's an example that uses the `--orderer` global flag on the `peer channel
     6  create` command.
     7  
     8  * Create a sample channel `mychannel` defined by the configuration transaction
     9    contained in file `./createchannel.tx`. Use the orderer at `orderer.example.com:7050`.
    10  
    11    ```
    12    peer channel create -c mychannel -f ./createchannel.tx --orderer orderer.example.com:7050
    13  
    14    2018-02-25 08:23:57.548 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    15    2018-02-25 08:23:57.626 UTC [channelCmd] InitCmdFactory -> INFO 019 Endorser and orderer connections initialized
    16    2018-02-25 08:23:57.834 UTC [channelCmd] readBlock -> INFO 020 Received block: 0
    17    2018-02-25 08:23:57.835 UTC [main] main -> INFO 021 Exiting.....
    18  
    19    ```
    20  
    21    Block 0 is returned indicating that the channel has been successfully created.
    22  
    23  Here's an example of the `peer channel create` command option.
    24  
    25  * Create a new channel `mychannel` for the network, using the orderer at ip
    26    address `orderer.example.com:7050`.  The configuration update transaction
    27    required to create this channel is defined the file `./createchannel.tx`.
    28    Wait 30 seconds for the channel to be created.
    29  
    30    ```
    31      peer channel create -c mychannel --orderer orderer.example.com:7050 -f ./createchannel.tx -t 30s
    32  
    33      2018-02-23 06:31:58.568 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    34      2018-02-23 06:31:58.669 UTC [channelCmd] InitCmdFactory -> INFO 019 Endorser and orderer connections initialized
    35      2018-02-23 06:31:58.877 UTC [channelCmd] readBlock -> INFO 020 Received block: 0
    36      2018-02-23 06:31:58.878 UTC [main] main -> INFO 021 Exiting.....
    37  
    38      ls -l
    39  
    40      -rw-r--r-- 1 root root 11982 Feb 25 12:24 mychannel.block
    41  
    42    ```
    43  
    44    You can see that channel `mychannel` has been successfully created, as
    45    indicated in the output where block 0 (zero) is added to the blockchain for
    46    this channel and returned to the peer, where it is stored in the local
    47    directory as `mychannel.block`.
    48  
    49    Block zero is often called the *genesis block* as it provides the starting
    50    configuration for the channel.  All subsequent updates to the channel will be
    51    captured as configuration blocks on the channel's blockchain, each of which
    52    supersedes the previous configuration.
    53  
    54  ### peer channel fetch example
    55  
    56  Here's some examples of the `peer channel fetch` command.
    57  
    58  * Using the `newest` option to retrieve the most recent channel block, and
    59    store it in   the file `mychannel.block`.
    60  
    61    ```
    62    peer channel fetch newest mychannel.block -c mychannel --orderer orderer.example.com:7050
    63  
    64    2018-02-25 13:10:16.137 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    65    2018-02-25 13:10:16.144 UTC [channelCmd] readBlock -> INFO 00a Received block: 32
    66    2018-02-25 13:10:16.145 UTC [main] main -> INFO 00b Exiting.....
    67  
    68    ls -l
    69  
    70    -rw-r--r-- 1 root root 11982 Feb 25 13:10 mychannel.block
    71  
    72    ```
    73  
    74    You can see that the retrieved block is number 32, and that the information
    75    has been written to the file `mychannel.block`.
    76  
    77  * Using the `(block number)` option to retrieve a specific block -- in this
    78    case, block number 16 -- and store it in the default block file.
    79  
    80    ```
    81    peer channel fetch 16  -c mychannel --orderer orderer.example.com:7050
    82  
    83    2018-02-25 13:46:50.296 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
    84    2018-02-25 13:46:50.302 UTC [channelCmd] readBlock -> INFO 00a Received block: 16
    85    2018-02-25 13:46:50.302 UTC [main] main -> INFO 00b Exiting.....
    86  
    87    ls -l
    88  
    89    -rw-r--r-- 1 root root 11982 Feb 25 13:10 mychannel.block
    90    -rw-r--r-- 1 root root  4783 Feb 25 13:46 mychannel_16.block
    91  
    92    ```
    93  
    94    You can see that the retrieved block is number 16, and that the information
    95    has been written to the default file `mychannel_16.block`.
    96  
    97    For configuration blocks, the block file can be decoded using the
    98    [`configtxlator` command](./configtxlator.html). See this command for an example
    99    of decoded output. User transaction blocks can also be decoded, but a user
   100    program must be written to do this.
   101  
   102  ### peer channel getinfo example
   103  
   104  Here's an example of the `peer channel getinfo` command.
   105  
   106  * Get information about the local peer for channel `mychannel`.
   107  
   108    ```
   109    peer channel getinfo -c mychannel
   110  
   111    2018-02-25 15:15:44.135 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
   112    Blockchain info: {"height":5,"currentBlockHash":"JgK9lcaPUNmFb5Mp1qe1SVMsx3o/22Ct4+n5tejcXCw=","previousBlockHash":"f8lZXoAn3gF86zrFq7L1DzW2aKuabH9Ow6SIE5Y04a4="}
   113    2018-02-25 15:15:44.139 UTC [main] main -> INFO 006 Exiting.....
   114  
   115    ```
   116  
   117    You can see that the latest block for channel `mychannel` is block 5.  You
   118    can also see the cryptographic hashes for the most recent blocks in the
   119    channel's blockchain.
   120  
   121  ### peer channel join example
   122  
   123  Here's an example of the `peer channel join` command.
   124  
   125  * Join a peer to the channel defined in the genesis block identified by the file
   126    `./mychannel.genesis.block`. In this example, the channel block was
   127    previously retrieved by the `peer channel fetch` command.
   128  
   129    ```
   130    peer channel join -b ./mychannel.genesis.block
   131  
   132    2018-02-25 12:25:26.511 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
   133    2018-02-25 12:25:26.571 UTC [channelCmd] executeJoin -> INFO 006 Successfully submitted proposal to join channel
   134    2018-02-25 12:25:26.571 UTC [main] main -> INFO 007 Exiting.....
   135  
   136    ```
   137  
   138    You can see that the peer has successfully made a request to join the channel.
   139  
   140  ### peer channel list example
   141  
   142    Here's an example of the `peer channel list` command.
   143  
   144    * List the channels to which a peer is joined.
   145  
   146      ```
   147      peer channel list
   148  
   149      2018-02-25 14:21:20.361 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
   150      Channels peers has joined:
   151      mychannel
   152      2018-02-25 14:21:20.372 UTC [main] main -> INFO 006 Exiting.....
   153  
   154      ```
   155  
   156      You can see that the peer is joined to channel `mychannel`.
   157  
   158  ### peer channel signconfigtx example
   159  
   160  Here's an example of the `peer channel signconfigtx` command.
   161  
   162  * Sign the `channel update` transaction defined in the file
   163    `./updatechannel.tx`. The example lists the configuration transaction file
   164    before and after the command.
   165  
   166    ```
   167    ls -l
   168  
   169    -rw-r--r--  1 anthonyodowd  staff   284 25 Feb 18:16 updatechannel.tx
   170  
   171    peer channel signconfigtx -f updatechannel.tx
   172  
   173    2018-02-25 18:16:44.456 GMT [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
   174    2018-02-25 18:16:44.459 GMT [main] main -> INFO 002 Exiting.....
   175  
   176    ls -l
   177  
   178    -rw-r--r--  1 anthonyodowd  staff  2180 25 Feb 18:16 updatechannel.tx
   179  
   180    ```
   181  
   182    You can see that the peer has successfully signed the configuration
   183    transaction by the increase in the size of the file `updatechannel.tx` from
   184    284 bytes to 2180 bytes.
   185  
   186  ### peer channel update example
   187  
   188  Here's an example of the `peer channel update` command.
   189  
   190  * Update the channel `mychannel` using the configuration transaction defined in
   191    the file `./updatechannel.tx`. Use the orderer at ip address
   192    `orderer.example.com:7050` to send the configuration transaction to all peers
   193    in the channel to update their copy of the channel configuration.
   194  
   195    ```
   196    peer channel update -c mychannel -f ./updatechannel.tx -o orderer.example.com:7050
   197  
   198    2018-02-23 06:32:11.569 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
   199    2018-02-23 06:32:11.626 UTC [main] main -> INFO 010 Exiting.....
   200  
   201    ```
   202  
   203    At this point, the channel `mychannel` has been successfully updated.
   204  
   205  <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>.