简体   繁体   English

Hyperledger Fabric Version 2: How to query Block Header such as data hash, previous hash by using Fabric Node SDK 2.2

[英]Hyperledger Fabric Version 2: How to query Block Header such as data hash, previous hash by using Fabric Node SDK 2.2

I am trying to build a decentralized app that able to do show the block header like data hash, the previous hash of the block when a user submits a new transaction.我正在尝试构建一个去中心化的应用程序,它能够在用户提交新交易时显示块 header 之类的数据 hash,之前的 hash 块。 However, It seems like the new version of Fabric Node SDK 2.2 removes the function queryblock.但是,新版本的Fabric Node SDK 2.2似乎删除了 function 查询块。

I refer on the documentation at https://hyperledger.github.io/fabric-sdk-node/release-2.2/module-fabric-network.html and currently still looking for some workaround to show the block info of the user's transaction. I refer on the documentation at https://hyperledger.github.io/fabric-sdk-node/release-2.2/module-fabric-network.html and currently still looking for some workaround to show the block info of the user's transaction.

The ideal output that I wish to achieved is almost similar to what Hyperledger Explorer provide.The reference can be check at:我希望实现的理想 output 与 Hyperledger Explorer 提供的几乎相似。参考可以在以下位置查看:

which show the information such as Number of Blocks, Data Hash, Previous Hash and other Block Information regarding the hash.其中显示了有关 hash 的块数、数据 Hash、以前的 Hash 和其他块信息等信息。

Some information that I able to gather我能够收集到的一些信息

  1. There are some information like BlockEvent that have the name blockData in the interface BlockEvent .blockData接口中有一些信息,例如 BlockEvent,其名称为BlockEvent However, I can't seem to find it when npm install i fabric-network .但是,当npm install i fabric-network时,我似乎找不到它。

  2. Since the user can query and check their hash with the ledger, a key or hash need to be returned to the user upon transaction success.由于用户可以通过账本查询查看自己的hash,因此需要在交易成功后将key或者hash返回给用户。 Is there any API function for this?有没有 API function 呢? So far, I able to found there are getTransactionId() in the class Transaction .到目前为止,我发现 class Transaction中有getTransactionId() But is this one that I need to use?但这是我需要使用的吗?

StackOverflow reference that I had gone over:我已经阅读过的 StackOverflow 参考:

All of the reference since to deal with the old version of node SDK which is version 1.4.所有参考自处理旧版本节点 SDK 即版本 1.4。

You can query block number by call function GetBlockByNumber of qscc contract.您可以通过调用qscc合约的 function GetBlockByNumber来查询区块号。 Example:例子:

const contract = network.getContract('qscc');
const resultByte = await contract.evaluateTransaction(
    'GetBlockByNumber',
    channelName,
    String(blockNum)
);
const resultJson = BlockDecoder.decode(resultByte);
logger.debug('queryBlock', resultJson);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM