To get the historic data of the chaincode, you can use the ChaincodeStubInterface API.
This retrieves entire histroy for a given key. It is iterative and so you can see the changes made for the
given key.
Look at the following example:
historyIer, err := stub.GetHistoryForKey(yourKey)
if err != nil {
fmt.Println(errMsg)
return shim.Error(errMsg)
}
if historyIer.HasNext() {
modification, err := historyIer.Next()
if err != nil {
fmt.Println(errMsg)
return shim.Error(errMsg)
}
fmt.Println("Returning information related to", string(modification.Value))
}
To make this work, you have the set the value of "enableHistoryDatabase" in core.yaml under the ledger section
as true as shown below:
ledger:
history:
# enableHistoryDatabase - options are true or false
# Indicates if the history of key updates should be stored.
# All history 'index' will be stored in goleveldb, regardless if using
# CouchDB or alternate database for the state.
enableHistoryDatabase: true