Hyperledger Fabric-使用Node.js的HistoryQueryIterator [英] Hyperledger Fabric- HistoryQueryIterator using nodejs

查看:139
本文介绍了Hyperledger Fabric-使用Node.js的HistoryQueryIterator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用nodejs创建超级账本链代码,fabric-shim对我来说是新的. 我正在尝试使用getHistoryForKey()来获取资产的历史记录.

I am trying to create hyperledger chaincode using nodejs and fabric-shim is new to me. I am trying to fetch history of an asset using getHistoryForKey().

我尝试使用while遍历HistoryQueryIterator,但未成功.

I tried iterating through HistoryQueryIterator using while but i was not successful.

@Transaction()
public async getAllHistory(ctx:Context,key:string):Promise<void>{
    const history = await ctx.stub.getHistoryForKey(key);
     while(history.next()){
         history.next().then(value =>{
            console.info("================>",value.toString());
         })
         .catch(err =>{
            console.info("ERROR",err);
         })
     }

}

上面的代码给出了[object Object].

如果有人可以向我指出正确的方向,那将会有所帮助.

If someone could point me in the right direction it would be helpful.

推荐答案

您可以在Hyperledger Fabric官方样本(chaincodes/marbles02)中找到有关如何使用getHistoryForKey的示例.

You can find an example about how to use getHistoryForKey in the official Hyperledger Fabric samples ( chaincodes/marbles02).

https://github .com/hyperledger/fabric-samples/blob/release-1.4/chaincode/marbles02/node/marbles_chaincode.js

这篇关于Hyperledger Fabric-使用Node.js的HistoryQueryIterator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆