0 votes
1 view
in Blockchain by (12.2k points)

I am using IBM bluemix blockchain service to try out some smart contract logic for my asset sharing demo. 

Is there any way to query the asset modified history in hyperledger fabric network. 

I have checked with documentations for both fabric 0.6 and 1.0 versions, but I can find only the stub.pushState(key,value_json) and stub.getState(key) to interact width the ledger.

But using stub.getState(key), I can fetch only the latest entry of the key, but how can I fetch and display the series of changes/modifications written for the same key. I have iterated through the block using {peeraddress}/Block/getBlock/{Block}, but I am getting the encrypted transaction payloads only since its security is on. I am not getting the idea to display the history of asset modifications for the same key.

Please suggest me the correct way to do this. 

Thanks in advance

1 Answer

0 votes
by (28.6k points)

Hi, please refer to the code below to use GetHistoryForKey() API :

historyIter, err := stub.GetHistoryForKey(key)

    if err != nil {
        errMsg := fmt.Sprintf("[ERROR] cannot retrieve history for key <%s>, due to %s", key, err)
        fmt.Println(errMsg)
        return shim.Error(errMsg)
    }

    for historyIter.HasNext() {
        modification, err := historyIer.Next()
        if err != nil {
            errMsg := fmt.Sprintf("[ERROR] cannot read record modification for key %s, id <%s>, due to %s", key, err)
            fmt.Println(errMsg)
            return shim.Error(errMsg)
        }
        fmt.Println("Returning information about", string(modification.Value))

}

for more clarifications I'd recommend you to read about API description

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...