The Invoke function

The Invoke() function, as its name implies, is executed when an application wants to invoke a specific function in the Chaincode. The calling application will pass the particular function name to be executed, with the needed arguments. In our code we will define the following Invoke() function:

func (t *FoodContract) Invoke(stub shim.ChaincodeStubInterface) pb.Response {                    function, args := stub.GetFunctionAndParameters()                    if function == "createRawFood" {                                         return t.createRawFood(stub, args)                    } else if function == "manufactureProcessing" {                                          return t.manufactureProcessing(stub, args)                    } else if function == "wholesalerDistribute" {                                          return t.wholesalerDistribute(stub, args)                    } else if function == "initiateShipment" {                                   return ...

Get Blockchain By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.