我正在使用Hyperledger Fabric v.1.0进行开发 - 实际上是一名新手。如何检查链的高度?是否有命令或其他工具可以用来查询区块链高度?谢谢。
我正在使用Hyperledger Fabric v.1.0进行开发 - 实际上是一名新手。如何检查链的高度?是否有命令或其他工具可以用来查询区块链高度?谢谢。
好的,您有几个选项可以实现:
You can leverage peer cli
command line tool to obtain latest available block by running
peer channel fetch newest -o ordererIP:7050 -c mychannel last.block
configtxlator
解码块内容,具体操作如下:curl -X POST --data-binary @last.block http://localhost:7059/protolator/decode/common.Block
configtxlator
)Alternative path assumes you are going to use one of available SDK's to invoke QSCC (Query System ChainCode) with GetChainInfo
command. This will return you back following structure:
type BlockchainInfo struct {
Height uint64 `protobuf:"varint,1,opt,name=height" json:"height,omitempty"`
CurrentBlockHash []byte `protobuf:"bytes,2,opt,name=currentBlockHash,proto3" json:"currentBlockHash,omitempty"`
PreviousBlockHash []byte `protobuf:"bytes,3,opt,name=previousBlockHash,proto3" json:"previousBlockHash,omitempty"`
}
这个包含了有关当前账本高度的信息。
另一种选择。
使用命令行cli peer
(例如docker exec -it cli bash
)您可以执行以下操作:
peer channel getinfo -c mychannel
看起来我发现了一些有用的东西 - 或许有点繁琐,但总比没有强:
命令:
docker logs -f peer0.org1.example.com 2>&1 | grep blockNo
检查输出中的“最新”行,类似于:
2017-07-18 19:40:39.586 UTC [historyleveldb] Commit -> DEBU b75b Channel [mychannel]: Updates committed to history database for blockNo [34]
所以,如果我没错的话,在这种情况下块高度是:34
谢谢
你还应该能够使用面料CORE API(JSON / REST)。
请参阅区块链GET / chain操作的文档;
https://github.com/hyperledger-archives/fabric/blob/master/docs/API/CoreAPI.md#rest-api