@@ -25,6 +25,7 @@ import (
25
25
"strings"
26
26
27
27
"github.com/hyperledger/fabric/core"
28
+ "github.com/hyperledger/fabric/core/chaincode/shim"
28
29
"github.com/hyperledger/fabric/peer/common"
29
30
"github.com/hyperledger/fabric/peer/util"
30
31
pb "github.com/hyperledger/fabric/protos"
@@ -33,6 +34,10 @@ import (
33
34
"golang.org/x/net/context"
34
35
)
35
36
37
+ type container struct {
38
+ Args []string
39
+ }
40
+
36
41
// chaincodeInvokeOrQuery invokes or queries the chaincode. If successful, the
37
42
// INVOKE form prints the transaction ID on STDOUT, and the QUERY form prints
38
43
// 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
57
62
}
58
63
// Build the spec
59
64
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 {
61
67
err = fmt .Errorf ("Chaincode argument error: %s" , err )
62
68
return
63
69
}
64
-
70
+ input = & pb. ChaincodeInput { Args : shim . ToChaincodeArgs ( inputc . Args ... )}
65
71
var attributes []string
66
72
if err = json .Unmarshal ([]byte (chaincodeAttributesJSON ), & attributes ); err != nil {
67
73
err = fmt .Errorf ("Chaincode argument error: %s" , err )
@@ -172,9 +178,9 @@ func checkChaincodeCmdParams(cmd *cobra.Command) error {
172
178
}
173
179
}
174
180
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
178
184
// on here with JSON parsing see http://blog.golang.org/json-and-go -
179
185
// Generic JSON with interface{}
180
186
if chaincodeCtorJSON != "{}" {
@@ -184,19 +190,18 @@ func checkChaincodeCmdParams(cmd *cobra.Command) error {
184
190
return fmt .Errorf ("Chaincode argument error: %s" , err )
185
191
}
186
192
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'" )
189
195
}
190
196
for k := range m {
191
197
switch strings .ToLower (k ) {
192
- case "function" :
193
198
case "args" :
194
199
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 )
196
201
}
197
202
}
198
203
} 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'" )
200
205
}
201
206
202
207
if chaincodeAttributesJSON != "[]" {
0 commit comments