December 2018
Intermediate to advanced
222 pages
6h 6m
English
Queries are how you read data from the ledger. The query function is used to query the chaincode's state. As we put claim data in the ledger with claimId, in order to read the current claim, we call GetState, passing claimId as key, as follows:
func (c *ClaimContract) query(stub shim.ChaincodeStubInterface, args []string) pb.Response { var ENIITY string var err error if len(args) != 1 { return shim.Error("Incorrect number of arguments. Expected ENIITY Name") } ENIITY = args[0] Avalbytes, err := stub.GetState(ENIITY) if err != nil { jsonResp := "{\"Error\":\"Failed to get state for " + ENIITY + "\"}" return shim.Error(jsonResp) } if Avalbytes == nil { jsonResp := "{\"Error\":\"Nil order for " + ENIITY + "\"}" return shim.Error(jsonResp) ...Read now
Unlock full access