获取特定 Channel 的区块链信息

本文详细介绍如何在Hyperledger Fabric中查询通道的高度信息及特定区块的详细内容,包括设置环境变量、使用peer channel fetch命令获取最新、最旧或指定区块,并将区块信息转换为json格式以供进一步分析。

1.获得channel高度:

peer channel getinfo -c $CHANNEL_NAME

可得到返回结果类似如下:

Blockchain info: {"height":6,"currentBlockHash":"cUJls9tYyVfJ6nENRMmRzYgXEwNhSBeSpbXSQSibkJU=","previousBlockHash":"M5er0eSSxwcSDk6xNoG4keykTB/OEg9vOiYXFtOh698="}

2.获取特定的 Block 的详细内容:

2.1设置当前环境:

export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.wisedu.com/users/Admin@org1.wisedu.com/msp
export CORE_PEER_ADDRESS=peer0.org1.wisedu.com:7051

2.2使用peer channel fetch

peer channel fetch newest mychannel.block -o orderer.wisedu.com:7050 -c mychannel

获取最新的区块,并保存为以mychannel.block命名的区块(若省略,则自动保存为mychannel_newest.block)。

peer channel fetch newest -o orderer.wisedu.com:7050 -c mychannel

peer channel fetch [newest|oldest|config|(block number)] [<outputFile>] [Flags]

即fetch后可以跟newest、oldest、config(最近的配置信息)、区块号(如5),输出文件名可以省略(默认为mychannel_newest.block、mychannel_oldest.block、mychannel_config.block、mychannel_(block number).block)。

2.3将mychannel_newest.block从cli容器中拷贝之本地路径(在e2e_standalone下输入):

sudo docker cp e707f6b649a3:/opt/gopath/src/github.com/hyperledger/fabric/peer/mychannel_newest.block /home/matrix/e2e_standalone

2.4将其转换为json文件(在e2e_standalone下输入),即可查看具体信息:

configtxgen --inspectBlock mychannel_newest.block > mychannel_newest.json

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值