Query

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)
}
return shim.Success(Avalbytes)
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.140.238