如何在Hyperledger Fabric中检查区块链高度

4

我正在使用Hyperledger Fabric v.1.0进行开发 - 实际上是一名新手。如何检查链的高度?是否有命令或其他工具可以用来查询区块链高度?谢谢。

5个回答

8

好的,您有几个选项可以实现:

  1. 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
(说明:该句为提示文字,建议不翻译)
  1. 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"`
    }
    

这个包含了有关当前账本高度的信息。


谢谢 Artem。您的回答更加优雅和灵活。 - saradiss

7

另一种选择。 使用命令行cli peer(例如docker exec -it cli bash)您可以执行以下操作:

peer channel getinfo -c mychannel


0

0

看起来我发现了一些有用的东西 - 或许有点繁琐,但总比没有强:

命令:

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

谢谢


它从0开始,所以你得到的结果应该加1。 - malajisi

-1

1
此答案涉及Hyperledger Fabric v0.5的存档和已废弃的原始代码库。REST API已在v1.0.x中被弃用和移除,并正在开发一个新的REST SDK来代替它。 - christo4ferris
谢谢更新。那么这是正确的链接吗?- http://fabricrepo.readthedocs.io/en/stable/API/CoreAPI/#rest-api - Paul Keogh
不,新的REST SDK 相当初级。仓库在这里:https://github.com/hyperledger/fabric-sdk-rest 但仍在开发中。 - christo4ferris

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接