Hyperledger Fabric-使用Node.js的HistoryQueryIterator [英] Hyperledger Fabric- HistoryQueryIterator using nodejs
问题描述
我正在尝试使用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).
这篇关于Hyperledger Fabric-使用Node.js的HistoryQueryIterator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!