@@ -25,6 +25,7 @@ import (
2525 "strings"
2626
2727 "github.com/hyperledger/fabric/core"
28+ "github.com/hyperledger/fabric/core/chaincode/shim"
2829 "github.com/hyperledger/fabric/peer/common"
2930 "github.com/hyperledger/fabric/peer/util"
3031 pb "github.com/hyperledger/fabric/protos"
@@ -33,6 +34,10 @@ import (
3334 "golang.org/x/net/context"
3435)
3536
37+ type container struct {
38+ Args []string
39+ }
40+
3641// chaincodeInvokeOrQuery invokes or queries the chaincode. If successful, the
3742// INVOKE form prints the transaction ID on STDOUT, and the QUERY form prints
3843// 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
5762 }
5863 // Build the spec
5964 input := & pb.ChaincodeInput {}
60- if err = json .Unmarshal ([]byte (chaincodeCtorJSON ), & input ); err != nil {
65+ inputc := container {}
66+ if err = json .Unmarshal ([]byte (chaincodeCtorJSON ), & inputc ); err != nil {
6167 err = fmt .Errorf ("Chaincode argument error: %s" , err )
6268 return
6369 }
64-
70+ input = & pb. ChaincodeInput { Args : shim . ToChaincodeArgs ( inputc . Args ... )}
6571 var attributes []string
6672 if err = json .Unmarshal ([]byte (chaincodeAttributesJSON ), & attributes ); err != nil {
6773 err = fmt .Errorf ("Chaincode argument error: %s" , err )
@@ -172,9 +178,9 @@ func checkChaincodeCmdParams(cmd *cobra.Command) error {
172178 }
173179 }
174180
175- // Check that non-empty chaincode parameters contain only Function and
176- // Args keys. Type checking is done later when the JSON is actually
177- // unmarshaled into a pb.ChaincodeInput. To better understand what's going
181+ // Check that non-empty chaincode parameters contain only Args as a key.
182+ // Type checking is done later when the JSON is actually unmarshaled
183+ // into a pb.ChaincodeInput. To better understand what's going
178184 // on here with JSON parsing see http://blog.golang.org/json-and-go -
179185 // Generic JSON with interface{}
180186 if chaincodeCtorJSON != "{}" {
@@ -184,19 +190,18 @@ func checkChaincodeCmdParams(cmd *cobra.Command) error {
184190 return fmt .Errorf ("Chaincode argument error: %s" , err )
185191 }
186192 m := f .(map [string ]interface {})
187- if len (m ) != 2 {
188- return fmt .Errorf ("Non-empty JSON chaincode parameters must contain exactly 2 keys - 'Function' and 'Args'" )
193+ if len (m ) != 1 {
194+ return fmt .Errorf ("Non-empty JSON chaincode parameters must contain exactly 1 key: 'Args'" )
189195 }
190196 for k := range m {
191197 switch strings .ToLower (k ) {
192- case "function" :
193198 case "args" :
194199 default :
195- return fmt .Errorf ("Illegal chaincode key '%s' - must be either 'Function' or 'Args'" , k )
200+ return fmt .Errorf ("Illegal chaincode key '%s' - must be only 'Args'" , k )
196201 }
197202 }
198203 } else {
199- return errors .New ("Empty JSON chaincode parameters must contain exactly 2 keys - 'Function' and 'Args'" )
204+ return errors .New ("Empty JSON chaincode parameters must contain exactly 1 key: 'Args'" )
200205 }
201206
202207 if chaincodeAttributesJSON != "[]" {
0 commit comments