how to get modification history of asset?

0 votes
I am working on Bluemix and i want to fetch the asset modification history in Hyperledger fabric. i have gone around the documentation and i found stub.pushState(key,value_json) and stub.getState(key). I tried using this but realized that this can fetch only for latest key. But i want to fetch set of modification key and display it. i iterated on blocks using {peeraddress}/Block/getBlock/{Block} but i get decrypted info and cant display it.. How to do it?
Jul 9, 2018 in Blockchain by slayer
• 29,170 points
364 views

1 answer to this question.

0 votes

You can use GetHistoryForKey() API as shown below:

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

The link to the interface is : https://github.com/hyperledger/fabric/blob/release/core/chaincode/shim/interfaces.go#L164

Some functions in Query System Chaincode are:

const (
    GetChainInfo       string = "GetChainInfo"
    GetBlockByNumber   string = "GetBlockByNumber"
    GetBlockByHash     string = "GetBlockByHash"
    GetTransactionByID string = "GetTransactionByID"
    GetBlockByTxID     string = "GetBlockByTxID"
)

you can find more on: https://github.com/hyperledger/fabric/blob/release/core/scc/qscc/query.go#L40

answered Jul 9, 2018 by digger
• 26,550 points

Related Questions In Blockchain

0 votes
1 answer

How to write a program to get details of ERC tokens?

You can use Javascript with the Metamask ...READ MORE

answered Jul 13, 2018 in Blockchain by slayer
• 29,170 points
47 views
0 votes
1 answer

How to check history of blockchain.info wallet?

In the link you mentioned(https://blockchain.info/q), there are ...READ MORE

answered Jul 23, 2018 in Blockchain by slayer
• 29,170 points
50 views
0 votes
1 answer

How to get the current state of a smart contract?

Hey, you gotta provide the contract code, and ...READ MORE

answered Aug 1, 2018 in Blockchain by Perry
• 17,020 points
49 views
0 votes
1 answer
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 26,550 points
77 views
+1 vote
1 answer

How do i change the names of validating peers in IBM Bluemix blockchain?

IBM Bluemix Blockchain service Hyperledger Fabric v0.6 will ...READ MORE

answered Apr 10, 2018 in Blockchain by Perry
103 views
0 votes
1 answer

How to get return value of external function?

You can do this. I have shared ...READ MORE

answered Aug 13, 2018 in Blockchain by digger
• 26,550 points
26 views
0 votes
1 answer

How to get current value of bitcoin?

You can use json_decode to transform it ...READ MORE

answered Aug 20, 2018 in Blockchain by digger
• 26,550 points
53 views