简体   繁体   中英

Hyperledger Fabric- HistoryQueryIterator using nodejs

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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