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