November 2018
Intermediate to advanced
528 pages
13h 21m
English
The final important function to define is the Query function. It is called when the application queries the Chaincode state. In our case Query definition is straightforward: we just need to pass a key—orderId—to get, in result, the corresponding food struct, as follows :
func (f *FoodContract) 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 { sonResp := "{\"Error\":\"Failed to get state for " + ENIITY + "\"}" return shim.Error(jsonResp) } if Avalbytes == nil { jsonResp := "{\"Error\":\"Nil order ...Read now
Unlock full access