Last active
April 12, 2019 14:01
-
-
Save aschmidt75/877cb0b6fee521f25a1cda2b1b1c369d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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