Skip to content

Instantly share code, notes, and snippets.

@aschmidt75
Last active April 12, 2019 14:01
Show Gist options
  • Select an option

  • Save aschmidt75/877cb0b6fee521f25a1cda2b1b1c369d to your computer and use it in GitHub Desktop.

Select an option

Save aschmidt75/877cb0b6fee521f25a1cda2b1b1c369d to your computer and use it in GitHub Desktop.
func (cci *PreciousCargoChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
function, _ := stub.GetFunctionAndParameters()
if invType, found := cci.handlers[function]; found {
// from invType as reflect.Type, create a new object and
// cast its interface to InvocationHandler.
inv := reflect.New(invType).Interface().(InvocationHandler)
// let it check its input
if err := inv.checkParseArguments(stub); err != nil {
return shim.Error(err.Error())
}
// run the transaction
if err := inv.process(stub); err != nil {
return shim.Error(err.Error())
}
// send out the response
r, err := json.Marshal(inv.getResponse(stub))
if err != nil {
return shim.Error("internal JSON marshal error (response)")
}
return shim.Success([]byte(r))
}
return shim.Error("Invalid function name.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment