diff --git a/peer/chaincode/common.go b/peer/chaincode/common.go index 8d8fafc63e1..46c88a35939 100755 --- a/peer/chaincode/common.go +++ b/peer/chaincode/common.go @@ -25,6 +25,7 @@ import ( "strings" "github.com/hyperledger/fabric/core" + "github.com/hyperledger/fabric/core/chaincode/shim" "github.com/hyperledger/fabric/peer/common" "github.com/hyperledger/fabric/peer/util" pb "github.com/hyperledger/fabric/protos" @@ -33,6 +34,10 @@ import ( "golang.org/x/net/context" ) +type container struct { + Args []string +} + // chaincodeInvokeOrQuery invokes or queries the chaincode. If successful, the // INVOKE form prints the transaction ID on STDOUT, and the QUERY form prints // the query result on STDOUT. A command-line flag (-r, --raw) determines @@ -57,11 +62,12 @@ func chaincodeInvokeOrQuery(cmd *cobra.Command, args []string, invoke bool) (err } // Build the spec input := &pb.ChaincodeInput{} - if err = json.Unmarshal([]byte(chaincodeCtorJSON), &input); err != nil { + inputc := container{} + if err = json.Unmarshal([]byte(chaincodeCtorJSON), &inputc); err != nil { err = fmt.Errorf("Chaincode argument error: %s", err) return } - + input = &pb.ChaincodeInput{Args: shim.ToChaincodeArgs(inputc.Args...)} var attributes []string if err = json.Unmarshal([]byte(chaincodeAttributesJSON), &attributes); err != nil { err = fmt.Errorf("Chaincode argument error: %s", err) @@ -173,9 +179,9 @@ func checkChaincodeCmdParams(cmd *cobra.Command) error { } } - // Check that non-empty chaincode parameters contain only Function and - // Args keys. Type checking is done later when the JSON is actually - // unmarshaled into a pb.ChaincodeInput. To better understand what's going + // Check that non-empty chaincode parameters contain only Args as a key. + // Type checking is done later when the JSON is actually unmarshaled + // into a pb.ChaincodeInput. To better understand what's going // on here with JSON parsing see http://blog.golang.org/json-and-go - // Generic JSON with interface{} if chaincodeCtorJSON != "{}" { @@ -185,19 +191,18 @@ func checkChaincodeCmdParams(cmd *cobra.Command) error { return fmt.Errorf("Chaincode argument error: %s", err) } m := f.(map[string]interface{}) - if len(m) != 2 { - return fmt.Errorf("Non-empty JSON chaincode parameters must contain exactly 2 keys - 'Function' and 'Args'") + if len(m) != 1 { + return fmt.Errorf("Non-empty JSON chaincode parameters must contain exactly 1 key: 'Args'") } for k := range m { switch strings.ToLower(k) { - case "function": case "args": default: - return fmt.Errorf("Illegal chaincode key '%s' - must be either 'Function' or 'Args'", k) + return fmt.Errorf("Illegal chaincode key '%s' - must be only 'Args'", k) } } } else { - return errors.New("Empty JSON chaincode parameters must contain exactly 2 keys - 'Function' and 'Args'") + return errors.New("Empty JSON chaincode parameters must contain exactly 1 key: 'Args'") } if chaincodeAttributesJSON != "[]" { diff --git a/peer/chaincode/deploy.go b/peer/chaincode/deploy.go index 9ff1ffd3231..76e0545f17f 100755 --- a/peer/chaincode/deploy.go +++ b/peer/chaincode/deploy.go @@ -27,6 +27,7 @@ import ( "golang.org/x/net/context" "github.com/hyperledger/fabric/core" + "github.com/hyperledger/fabric/core/chaincode/shim" "github.com/hyperledger/fabric/peer/common" "github.com/hyperledger/fabric/peer/util" pb "github.com/hyperledger/fabric/protos" @@ -62,9 +63,11 @@ func chaincodeDeploy(cmd *cobra.Command, args []string) error { } // Build the spec input := &pb.ChaincodeInput{} - if err := json.Unmarshal([]byte(chaincodeCtorJSON), &input); err != nil { + inputc := container{} + if err = json.Unmarshal([]byte(chaincodeCtorJSON), &inputc); err != nil { return fmt.Errorf("Chaincode argument error: %s", err) } + input = &pb.ChaincodeInput{Args: shim.ToChaincodeArgs(inputc.Args...)} var attributes []string if err := json.Unmarshal([]byte(chaincodeAttributesJSON), &attributes); err != nil {