diff --git a/core/chaincode/exectransaction_test.go b/core/chaincode/exectransaction_test.go index 2773e159760..07e9602cd6a 100644 --- a/core/chaincode/exectransaction_test.go +++ b/core/chaincode/exectransaction_test.go @@ -700,8 +700,9 @@ func chaincodeInvokeChaincode(t *testing.T, user string) (err error) { // Invoke second chaincode passing the first chaincode's name as first param, // which will inturn invoke the first chaincode - f = spec1.ChaincodeID.Name - args = util.ToChaincodeArgs(f, "e", "1") + f = "invoke" + cid := spec1.ChaincodeID.Name + args = util.ToChaincodeArgs(f, cid, "e", "1") spec2 = &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID2, CtorMsg: &pb.ChaincodeInput{Args: args}, SecureContext: user} // Invoke chaincode @@ -890,7 +891,7 @@ func TestGetEvent(t *testing.T) { time.Sleep(time.Second) - args := util.ToChaincodeArgs("", "i", "am", "satoshi") + args := util.ToChaincodeArgs("invoke", "i", "am", "satoshi") spec = &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID, CtorMsg: &pb.ChaincodeInput{Args: args}} diff --git a/examples/chaincode/go/asset_management/asset_management.go b/examples/chaincode/go/asset_management/asset_management.go index 1734c2c672d..a7dc96256e4 100644 --- a/examples/chaincode/go/asset_management/asset_management.go +++ b/examples/chaincode/go/asset_management/asset_management.go @@ -252,23 +252,18 @@ func (t *AssetManagementChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]b } else if function == "transfer" { // Transfer ownership return t.transfer(stub, args) + } else if function == "query" { + // Query owner + return t.query(stub, args) } return nil, errors.New("Received unknown function invocation") } -// Query callback representing the query of a chaincode // Supported functions are the following: // "query(asset)": returns the owner of the asset. // Anyone can invoke this function. -func (t *AssetManagementChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) { - function, args := stub.GetFunctionAndParameters() - myLogger.Debugf("Query [%s]", function) - - if function != "query" { - return nil, errors.New("Invalid query function name. Expecting 'query' but found '" + function + "'") - } - +func (t *AssetManagementChaincode) query(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { var err error if len(args) != 1 { @@ -279,7 +274,7 @@ func (t *AssetManagementChaincode) Query(stub shim.ChaincodeStubInterface) ([]by // Who is the owner of the asset? asset := args[0] - myLogger.Debugf("Arg [%s]", string(asset)) + myLogger.Debugf("Query [%s]", string(asset)) var columns []shim.Column col1 := shim.Column{Value: &shim.Column_String_{String_: asset}} diff --git a/examples/chaincode/go/asset_management02/asset_management02.go b/examples/chaincode/go/asset_management02/asset_management02.go index 23e374aa05b..838351a9182 100755 --- a/examples/chaincode/go/asset_management02/asset_management02.go +++ b/examples/chaincode/go/asset_management02/asset_management02.go @@ -202,7 +202,7 @@ func (t *AssetManagementChaincode) Init(stub shim.ChaincodeStubInterface) ([]byt return nil, dHandler.createTable(stub) } -// Invoke method is the interceptor of all invocation transactions, its job is to direct +// Invoke method is the interceptor of all invocation transactions, its job is to direct // invocation transactions to intended APIs func (t *AssetManagementChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { function, args := stub.GetFunctionAndParameters() @@ -215,25 +215,13 @@ func (t *AssetManagementChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]b } else if function == "transferOwnership" { // Transfer ownership return t.transferOwnership(stub, args) - } - - return nil, errors.New("Received unknown function invocation") -} - -// Query method is the interceptor of all invocation transactions, its job is to direct -// query transactions to intended APIs, and return the result back to callers -func (t *AssetManagementChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) { - function, args := stub.GetFunctionAndParameters() - myLogger.Debugf("********************************Query****************************************") - - // Handle different functions - if function == "getOwnerContactInformation" { + } else if function == "getOwnerContactInformation" { return t.getOwnerContactInformation(stub, args) } else if function == "getBalance" { return t.getBalance(stub, args) } - return nil, errors.New("Received unknown function query invocation with function " + function) + return nil, errors.New("Received unknown function invocation") } func main() { diff --git a/examples/chaincode/go/asset_management_with_roles/asset_management_with_roles.go b/examples/chaincode/go/asset_management_with_roles/asset_management_with_roles.go index b2e2d729a90..c62e50a16d3 100644 --- a/examples/chaincode/go/asset_management_with_roles/asset_management_with_roles.go +++ b/examples/chaincode/go/asset_management_with_roles/asset_management_with_roles.go @@ -228,18 +228,15 @@ func (t *AssetManagementChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]b } else if function == "transfer" { // Transfer ownership return t.transfer(stub, args) + } else if function == "query" { + // Query asset + return t.query(stub, args) } return nil, errors.New("Received unknown function invocation") } -// Query callback representing the query of a chaincode -func (t *AssetManagementChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) { - function, args := stub.GetFunctionAndParameters() - if function != "query" { - return nil, errors.New("Invalid query function name. Expecting 'query' but found '" + function + "'") - } - +func (t *AssetManagementChaincode) query(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { var err error if len(args) != 1 { diff --git a/examples/chaincode/go/attributes_to_state/attributes_to_state.go b/examples/chaincode/go/attributes_to_state/attributes_to_state.go index d33a9327947..27dc662f117 100644 --- a/examples/chaincode/go/attributes_to_state/attributes_to_state.go +++ b/examples/chaincode/go/attributes_to_state/attributes_to_state.go @@ -58,21 +58,17 @@ func (t *Attributes2State) Init(stub shim.ChaincodeStubInterface) ([]byte, error return nil, nil } -// Invoke takes two arguements, a key and value, and stores these in the state func (t *Attributes2State) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { function, args := stub.GetFunctionAndParameters() if function == "delete" { return nil, t.delete(stub, args) + } else if function == "submit" { + return nil, t.setStateToAttributes(stub, args) + } else if function == "read" { + return t.query(stub, args) } - if function != "submit" { - return nil, errors.New("Invalid invoke function name. Expecting either \"delete\" or \"submit\"") - } - err := t.setStateToAttributes(stub, args) - if err != nil { - return nil, err - } - return nil, nil + return nil, errors.New("Invalid invoke function name. Expecting either \"delete\" or \"submit\" or \"read\"") } // delete Deletes an entity from the state, returning error if the entity was not found in the state. @@ -106,12 +102,7 @@ func (t *Attributes2State) delete(stub shim.ChaincodeStubInterface, args []strin return nil } -// Query callback representing the query of a chaincode -func (t *Attributes2State) Query(stub shim.ChaincodeStubInterface) ([]byte, error) { - function, args := stub.GetFunctionAndParameters() - if function != "read" { - return nil, errors.New("Invalid query function name. Expecting \"read\"") - } +func (t *Attributes2State) query(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { var attributeName string // Name of the attributeName to query. var err error diff --git a/examples/chaincode/go/authorizable_counter/authorizable_counter.go b/examples/chaincode/go/authorizable_counter/authorizable_counter.go index bf6736e5e5d..17bc9213b56 100755 --- a/examples/chaincode/go/authorizable_counter/authorizable_counter.go +++ b/examples/chaincode/go/authorizable_counter/authorizable_counter.go @@ -35,12 +35,8 @@ func (t *AuthorizableCounterChaincode) Init(stub shim.ChaincodeStubInterface) ([ return nil, err } -//Invoke Transaction makes increment counter -func (t *AuthorizableCounterChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { - function, _ := stub.GetFunctionAndParameters() - if function != "increment" { - return nil, errors.New("Invalid invoke function name. Expecting \"increment\"") - } +//Invoke makes increment counter +func (t *AuthorizableCounterChaincode) increment(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { val, err := stub.ReadCertAttribute("position") fmt.Printf("Position => %v error %v \n", string(val), err) isOk, _ := stub.VerifyAttribute("position", []byte("Software Engineer")) // Here the ABAC API is called to verify the attribute, just if the value is verified the counter will be incremented. @@ -62,12 +58,7 @@ func (t *AuthorizableCounterChaincode) Invoke(stub shim.ChaincodeStubInterface) } -// Query callback representing the query of a chaincode -func (t *AuthorizableCounterChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) { - function, _ := stub.GetFunctionAndParameters() - if function != "read" { - return nil, errors.New("Invalid query function name. Expecting \"read\"") - } +func (t *AuthorizableCounterChaincode) read(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { var err error // Get the state from the ledger @@ -87,6 +78,20 @@ func (t *AuthorizableCounterChaincode) Query(stub shim.ChaincodeStubInterface) ( return Avalbytes, nil } +// Invoke method is the interceptor of all invocation transactions, its job is to direct +// invocation transactions to intended APIs +func (t *AuthorizableCounterChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { + function, args := stub.GetFunctionAndParameters() + + // Handle different functions + if function == "increment" { + return t.increment(stub, args) + } else if function == "read" { + return t.read(stub, args) + } + return nil, errors.New("Received unknown function invocation, Expecting \"increment\" \"read\"") +} + func main() { err := shim.Start(new(AuthorizableCounterChaincode)) if err != nil { diff --git a/examples/chaincode/go/chaincode_example01/chaincode_example01.go b/examples/chaincode/go/chaincode_example01/chaincode_example01.go index 91fab817517..05eaaf2f84a 100644 --- a/examples/chaincode/go/chaincode_example01/chaincode_example01.go +++ b/examples/chaincode/go/chaincode_example01/chaincode_example01.go @@ -69,8 +69,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) ([]byte, error) return nil, nil } -func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { - _, args := stub.GetFunctionAndParameters() +func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { // Transaction makes payment of X units from A to B var err error X, err = strconv.Atoi(args[0]) @@ -84,9 +83,13 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, erro return nil, err } -// Query callback representing the query of a chaincode -func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) { - return nil, nil +func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { + function, args := stub.GetFunctionAndParameters() + if function == "invoke" { + return t.invoke(stub, args) + } + + return nil, errors.New("Invalid invoke function name. Expecting \"invoke\"") } func main() { diff --git a/examples/chaincode/go/chaincode_example02/chaincode_example02.go b/examples/chaincode/go/chaincode_example02/chaincode_example02.go index 3833cbe9466..d47ad28c649 100644 --- a/examples/chaincode/go/chaincode_example02/chaincode_example02.go +++ b/examples/chaincode/go/chaincode_example02/chaincode_example02.go @@ -71,18 +71,24 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) ([]byte, error) return nil, nil } -// Transaction makes payment of X units from A to B func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { function, args := stub.GetFunctionAndParameters() - if function == "delete" { + if function == "invoke" { + // Make payment of X units from A to B + return t.invoke(stub, args) + } else if function == "delete" { // Deletes an entity from its state return t.delete(stub, args) - } - if function == "query" { + } else if function == "query" { // the old "Query" is now implemtned in invoke return t.query(stub, args) } + return nil, errors.New("Invalid invoke function name. Expecting \"invoke\" \"delete\" \"query\"") +} + +// Transaction makes payment of X units from A to B +func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { var A, B string // Entities var Aval, Bval int // Asset holdings var X int // Transaction value diff --git a/examples/chaincode/go/chaincode_example03/chaincode_example03.go b/examples/chaincode/go/chaincode_example03/chaincode_example03.go index 1142ee2854c..5cb64f69067 100644 --- a/examples/chaincode/go/chaincode_example03/chaincode_example03.go +++ b/examples/chaincode/go/chaincode_example03/chaincode_example03.go @@ -58,15 +58,15 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) ([]byte, error) // Invoke is a no-op func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { - return nil, nil -} - -// Query callback representing the query of a chaincode -func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) { function, args := stub.GetFunctionAndParameters() - if function != "query" { - return nil, errors.New("Invalid query function name. Expecting \"query\"") + if function == "query" { + return t.query(stub, args) } + + return nil, errors.New("Invalid invoke function name. Expecting \"query\"") +} + +func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { var A string // Entity var Aval int // Asset holding var err error diff --git a/examples/chaincode/go/chaincode_example03/chaincode_example03_test.go b/examples/chaincode/go/chaincode_example03/chaincode_example03_test.go index 17fd376ba6a..1197445433a 100644 --- a/examples/chaincode/go/chaincode_example03/chaincode_example03_test.go +++ b/examples/chaincode/go/chaincode_example03/chaincode_example03_test.go @@ -44,7 +44,7 @@ func checkState(t *testing.T, stub *shim.MockStub, name string, value string) { func checkQuery(t *testing.T, scc *SimpleChaincode, stub *shim.MockStub, args [][]byte) { _, err := stub.MockInit("1", args) - bytes, err := scc.Query(stub) + bytes, err := scc.Invoke(stub) if err != nil { // expected failure fmt.Println("Query below is expected to fail") diff --git a/examples/chaincode/go/chaincode_example04/chaincode_example04.go b/examples/chaincode/go/chaincode_example04/chaincode_example04.go index ade18147229..f38f86418e2 100644 --- a/examples/chaincode/go/chaincode_example04/chaincode_example04.go +++ b/examples/chaincode/go/chaincode_example04/chaincode_example04.go @@ -58,25 +58,18 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) ([]byte, error) } // Invoke invokes another chaincode - chaincode_example02, upon receipt of an event and changes event state -func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { +func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { var event string // Event entity var eventVal int // State of event var err error - function, args := stub.GetFunctionAndParameters() - - if function == "query" { - return t.query(stub, args) + if len(args) != 3 { + return nil, errors.New("Incorrect number of arguments. Expecting 3") } - if len(args) != 2 { - return nil, errors.New("Incorrect number of arguments. Expecting 2") - } - - chainCodeToCall := function - - event = args[0] - eventVal, err = strconv.Atoi(args[1]) + chainCodeToCall := args[0] + event = args[1] + eventVal, err = strconv.Atoi(args[2]) if err != nil { return nil, errors.New("Expected integer value for event state change") } @@ -106,7 +99,6 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, erro return nil, nil } -// query callback representing the query of a chaincode func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { var event string // Event entity var err error @@ -134,6 +126,17 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) return []byte(jsonResp), nil } +func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { + function, args := stub.GetFunctionAndParameters() + if function == "invoke" { + return t.invoke(stub, args) + } else if function == "query" { + return t.query(stub, args) + } + + return nil, errors.New("Invalid invoke function name. Expecting \"invoke\" \"query\"") +} + func main() { err := shim.Start(new(SimpleChaincode)) if err != nil { diff --git a/examples/chaincode/go/chaincode_example04/chaincode_example04_test.go b/examples/chaincode/go/chaincode_example04/chaincode_example04_test.go index f2954519dd8..b9340d221ed 100644 --- a/examples/chaincode/go/chaincode_example04/chaincode_example04_test.go +++ b/examples/chaincode/go/chaincode_example04/chaincode_example04_test.go @@ -106,13 +106,13 @@ func TestExample04_Invoke(t *testing.T) { checkInit(t, stub, [][]byte{[]byte("init"), []byte("Event"), []byte("1")}) // Invoke A->B for 10 via Example04's chaincode - checkInvoke(t, stub, [][]byte{[]byte(chaincodeToInvoke), []byte("Event"), []byte("1")}) + checkInvoke(t, stub, [][]byte{[]byte("invoke"), []byte(chaincodeToInvoke), []byte("Event"), []byte("1")}) checkQuery(t, stub, "Event", eventResponse) checkQuery(t, stubEx2, "a", "101") checkQuery(t, stubEx2, "b", "232") // Invoke A->B for 10 via Example04's chaincode - checkInvoke(t, stub, [][]byte{[]byte(chaincodeToInvoke), []byte("Event"), []byte("1")}) + checkInvoke(t, stub, [][]byte{[]byte("invoke"), []byte(chaincodeToInvoke), []byte("Event"), []byte("1")}) checkQuery(t, stub, "Event", eventResponse) checkQuery(t, stubEx2, "a", "91") checkQuery(t, stubEx2, "b", "242") diff --git a/examples/chaincode/go/chaincode_example05/chaincode_example05.go b/examples/chaincode/go/chaincode_example05/chaincode_example05.go index fc333fac64a..9c7e3297b08 100644 --- a/examples/chaincode/go/chaincode_example05/chaincode_example05.go +++ b/examples/chaincode/go/chaincode_example05/chaincode_example05.go @@ -60,16 +60,11 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) ([]byte, error) } // Invoke queries another chaincode and updates its own state -func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { +func (t *SimpleChaincode) invoke(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { var sum string // Sum entity var Aval, Bval, sumVal int // value of sum entity - to be computed var err error - function, args := stub.GetFunctionAndParameters() - if function != "query" { - return t.query(stub, args) - } - if len(args) != 2 { return nil, errors.New("Incorrect number of arguments. Expecting 2") } @@ -120,13 +115,11 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, erro return []byte(strconv.Itoa(sumVal)), nil } -// query callback representing the query of a chaincode func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { var sum string // Sum entity var Aval, Bval, sumVal int // value of sum entity - to be computed var err error - // Can query another chaincode within query, but cannot put state or invoke another chaincode (in transaction context) if len(args) != 2 { return nil, errors.New("Incorrect number of arguments. Expecting 2") } @@ -173,6 +166,17 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) return []byte(strconv.Itoa(sumVal)), nil } +func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { + function, args := stub.GetFunctionAndParameters() + if function == "invoke" { + return t.invoke(stub, args) + } else if function == "query" { + return t.query(stub, args) + } + + return nil, errors.New("Invalid invoke function name. Expecting \"invoke\" \"query\"") +} + func main() { err := shim.Start(new(SimpleChaincode)) if err != nil { diff --git a/examples/chaincode/go/eventsender/eventsender.go b/examples/chaincode/go/eventsender/eventsender.go index 39452fa56f6..fc27368303a 100644 --- a/examples/chaincode/go/eventsender/eventsender.go +++ b/examples/chaincode/go/eventsender/eventsender.go @@ -45,8 +45,7 @@ func (t *EventSender) Init(stub shim.ChaincodeStubInterface) ([]byte, error) { } // Invoke function -func (t *EventSender) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { - _, args := stub.GetFunctionAndParameters() +func (t *EventSender) invoke(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { b, err := stub.GetState("noevents") if err != nil { return nil, errors.New("Failed to get state") @@ -71,7 +70,7 @@ func (t *EventSender) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { } // Query function -func (t *EventSender) Query(stub shim.ChaincodeStubInterface) ([]byte, error) { +func (t *EventSender) query(stub shim.ChaincodeStubInterface, args []string) ([]byte, error) { b, err := stub.GetState("noevents") if err != nil { return nil, errors.New("Failed to get state") @@ -80,6 +79,17 @@ func (t *EventSender) Query(stub shim.ChaincodeStubInterface) ([]byte, error) { return []byte(jsonResp), nil } +func (t *EventSender) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) { + function, args := stub.GetFunctionAndParameters() + if function == "invoke" { + return t.invoke(stub, args) + } else if function == "query" { + return t.query(stub, args) + } + + return nil, errors.New("Invalid invoke function name. Expecting \"invoke\" \"query\"") +} + func main() { err := shim.Start(new(EventSender)) if err != nil { diff --git a/examples/chaincode/go/invokereturnsvalue/invokereturnsvalue.go b/examples/chaincode/go/invokereturnsvalue/invokereturnsvalue.go index bd4b3e71194..04d05eb590c 100644 --- a/examples/chaincode/go/invokereturnsvalue/invokereturnsvalue.go +++ b/examples/chaincode/go/invokereturnsvalue/invokereturnsvalue.go @@ -131,11 +131,6 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, erro return []byte(fmt.Sprintf("{%d,%d}", Aval, Bval)), nil } -// Query callback representing the query of a chaincode. Not used in 1.0 (remove when interface is removed) -func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) { - return nil, nil -} - func main() { err := shim.Start(new(SimpleChaincode)) if err != nil { diff --git a/examples/chaincode/go/map/map.go b/examples/chaincode/go/map/map.go index c0536feebf0..8e85160d8aa 100644 --- a/examples/chaincode/go/map/map.go +++ b/examples/chaincode/go/map/map.go @@ -30,8 +30,6 @@ import ( // Invoke operations // put - requires two arguments, a key and value // remove - requires a key - -// Query operations // get - requires one argument, a key, and returns a value // keys - requires no arguments, returns all keys @@ -76,18 +74,6 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, erro } return nil, nil - default: - return nil, errors.New("Unsupported operation") - } -} - -// Query has two functions -// get - takes one argument, a key, and returns the value for the key -// keys - returns all keys stored in this chaincode -func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) { - function, args := stub.GetFunctionAndParameters() - switch function { - case "get": if len(args) < 1 { return nil, errors.New("get operation must include one argument, a key") @@ -100,7 +86,6 @@ func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error return value, nil case "keys": - keysIter, err := stub.RangeQueryState("", "") if err != nil { return nil, fmt.Errorf("keys operation failed. Error accessing state: %s", err) diff --git a/examples/chaincode/go/rbac_tcerts_no_attrs/rbac.go b/examples/chaincode/go/rbac_tcerts_no_attrs/rbac.go index 33d82524c27..22d84e0c14c 100644 --- a/examples/chaincode/go/rbac_tcerts_no_attrs/rbac.go +++ b/examples/chaincode/go/rbac_tcerts_no_attrs/rbac.go @@ -108,16 +108,6 @@ func (t *RBACChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, error) return t.addRole(stub, args) case "write": return t.write(stub, args) - } - - return nil, fmt.Errorf("Received unknown function invocation [%s]", function) -} - -// Query callback representing the query of a chaincode -func (t *RBACChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) { - function, args := stub.GetFunctionAndParameters() - // Handle different functions - switch function { case "read": return t.read(stub, args) } diff --git a/examples/chaincode/go/utxo/chaincode.go b/examples/chaincode/go/utxo/chaincode.go index 393d7d5eda0..deb8a0d47d4 100644 --- a/examples/chaincode/go/utxo/chaincode.go +++ b/examples/chaincode/go/utxo/chaincode.go @@ -73,17 +73,6 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) ([]byte, erro return nil, nil - default: - return nil, errors.New("Unsupported operation") - } - -} - -// Query callback representing the query of a chaincode -func (t *SimpleChaincode) Query(stub shim.ChaincodeStubInterface) ([]byte, error) { - function, args := stub.GetFunctionAndParameters() - switch function { - case "getTran": if len(args) < 1 {