ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 1. 释义 提取指定区块并写入文件。 ## 2. 使用方法 ``` ~$ peer channel fetch <newest|oldest|config|(number)> [outputfile] [flags] ``` ## 3. 命令标志 ``` -c, --channelID string In case of a newChain command, the channel ID to create. It must be all lower case, less than 250 characters long and match the regular expression: [a-z][a-z0-9.-]* -h, --help help for fetch ``` 全局标志: ``` --cafile string Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint --certfile string Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint --clientauth Use mutual TLS when communicating with the orderer endpoint --connTimeout duration Timeout for client to connect (default 3s) --keyfile string Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint -o, --orderer string Ordering service endpoint --ordererTLSHostnameOverride string The hostname override to use when validating the TLS connection to the orderer. --tls Use TLS when communicating with the orderer endpoint ``` ## 4. 示例代码 下面的示例使用`newest`选项获取最新的通道区块,并存入文件mychannel.block: ``` peer channel fetch newest mychannel.block -c mychannel --orderer orderer.example.com:7050 2018-02-25 13:10:16.137 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 2018-02-25 13:10:16.144 UTC [channelCmd] readBlock -> INFO 00a Received block: 32 2018-02-25 13:10:16.145 UTC [main] main -> INFO 00b Exiting..... ``` 查看获取到的文件: ``` ~$ ls -l -rw-r--r-- 1 root root 11982 Feb 25 13:10 mychannel.block ``` 你可以看到获取到的区块序号为32,区块信息写入文件mychannel.block。 下面的示例使用区块序号选项提取指定的区块 —— 在本例中为16 —— 并存入默认区块文件: ``` ~$ peer channel fetch 16 -c mychannel --orderer orderer.example.com:7050 2018-02-25 13:46:50.296 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized 2018-02-25 13:46:50.302 UTC [channelCmd] readBlock -> INFO 00a Received block: 16 2018-02-25 13:46:50.302 UTC [main] main -> INFO 00b Exiting..... ``` 查看获取到的文件: ``` ~$ ls -l -rw-r--r-- 1 root root 11982 Feb 25 13:10 mychannel.block -rw-r--r-- 1 root root 4783 Feb 25 13:46 mychannel_16.block ``` 可以看到获取到的区块编号为16,该区块信息被写入默认文件mychannel\_16.block。 对于配置区块,可以使用configtxlatore命令解码区块文件。用户交易区块也可以解码,但需要编写一个额外的程序来完成这一工作。