Hyperledger Fabric- HistoryQueryIterator using nodejs

谁说胖子不能爱 提交于 2019-12-02 12:33:04

问题


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().

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);
         })
     }

}

The above code gives [object Object].

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


回答1:


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



来源:https://stackoverflow.com/questions/56327994/hyperledger-fabric-historyqueryiterator-using-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!