December 2018
Intermediate to advanced
222 pages
6h 6m
English
As its name indicates, the gethistory function reads a claim of all historical values records for a key, as well as the TxId and claim value.
We first define the AuditHistory struct, which has TxId and value. GetHistoryForKey returns the list of results with resultsIterator, which contains all historical transaction records. We iterate through these records and add them to an array of AuditHistory. Later, we convert it to JSON byte and send the data back as a response, as follows:
func (c *ClaimContract) getHistory(stub shim.ChaincodeStubInterface, args []string) pb.Response { type AuditHistory struct { TxId string `json:"txId"` Value Claim `json:"value"` } var history []AuditHistory var claim Claim if len(args) != 1 { return shim.Error("Incorrect ...Read now
Unlock full access