@@ -72,12 +72,21 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string)
7272 var X int // Transaction value
7373 var err error
7474
75- if len (args ) != 3 {
76- return shim .Error ("Incorrect number of arguments. Expecting 3, function followed by 2 names and 1 value" )
75+ if len (args ) != 0 {
76+ return shim .Error ("Incorrect number of arguments. All attributes must be included in the transient map." )
77+ }
78+
79+ transMap , err := stub .GetTransient ()
80+ if err != nil {
81+ return shim .Error ("Error getting transient: " + err .Error ())
82+ }
83+
84+ if len (transMap ) != 3 {
85+ return shim .Error ("Incorrect number of arguments. Expecting 3, function followed by 2 names and 1 value, got " + strconv .Itoa (len (transMap )))
7786 }
7887
79- A = args [ 0 ]
80- B = args [ 1 ]
88+ A = string ( transMap [ "A" ])
89+ B = string ( transMap [ "B" ])
8190
8291 // Get the state from the ledger
8392 // TODO: will be nice to have a GetAllState call to ledger
@@ -100,7 +109,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string)
100109 Bval , _ = strconv .Atoi (string (Bvalbytes ))
101110
102111 // Perform the execution
103- X , err = strconv .Atoi (args [ 2 ] )
112+ X , err = strconv .Atoi (string ( transMap [ "moveAmount" ]) )
104113 if err != nil {
105114 return shim .Error ("Invalid transaction amount, expecting a integer value" )
106115 }
@@ -128,19 +137,27 @@ func (t *SimpleChaincode) set(stub shim.ChaincodeStubInterface, args []string) p
128137 var Aval , Bval int // Asset holdings
129138 var err error
130139
131- if len (args ) != 4 {
132- return shim .Error ("Incorrect number of arguments. Expecting 4, function followed by 2 names and 2 values" )
140+ if len (args ) != 0 {
141+ return shim .Error ("Incorrect number of arguments. All attributes must be included in the transient map." )
142+ }
143+
144+ transMap , err := stub .GetTransient ()
145+ if err != nil {
146+ return shim .Error ("Error getting transient: " + err .Error ())
147+ }
148+
149+ if len (transMap ) != 4 {
150+ return shim .Error ("Incorrect number of arguments. Expecting 4, function followed by 2 names and 2 values, got " + strconv .Itoa (len (transMap )))
133151 }
134152
135- A = args [ 0 ]
136- Aval , err = strconv .Atoi (args [ 1 ] )
153+ A = string ( transMap [ "A" ])
154+ Aval , err = strconv .Atoi (string ( transMap [ "AVal" ]) )
137155 if err != nil {
138156 return shim .Error ("Invalid A value amount, expecting a integer value" )
139157 }
140158
141- B = args [2 ]
142-
143- Bval , err = strconv .Atoi (args [3 ])
159+ B = string (transMap ["B" ])
160+ Bval , err = strconv .Atoi (string (transMap ["BVal" ]))
144161 if err != nil {
145162 return shim .Error ("Invalid B value amount, expecting a integer value" )
146163 }
@@ -168,30 +185,39 @@ func (t *SimpleChaincode) set(stub shim.ChaincodeStubInterface, args []string) p
168185// Query callback representing the query of a chaincode ===>>> ONLY Query B VALUES
169186func (t * SimpleChaincode ) query (stub shim.ChaincodeStubInterface , args []string ) pb.Response {
170187
171- var A string // Entities
188+ var QueryKey string // Entities
172189 var err error
173190
174- if len (args ) != 1 {
175- return shim .Error ("Incorrect number of arguments. Expecting name of the person to query" )
191+ if len (args ) != 0 {
192+ return shim .Error ("Incorrect number of arguments. All attributes must be included in the transient map." )
193+ }
194+
195+ transMap , err := stub .GetTransient ()
196+ if err != nil {
197+ return shim .Error ("Error getting transient: " + err .Error ())
198+ }
199+
200+ if len (transMap ) != 1 {
201+ return shim .Error ("Incorrect number of arguments. Expecting 1, function followed by query key, got " + strconv .Itoa (len (transMap )))
176202 }
177203
178- A = args [ 0 ]
204+ QueryKey = string ( transMap [ "B" ])
179205
180- logger .Infof ("query for %s\n " , A )
206+ logger .Infof ("query for %s\n " , QueryKey )
181207
182208 // Get the state from the ledger
183- Avalbytes , err := stub .GetPrivateData ("COLLECTION_FOR_B" , A )
209+ Avalbytes , err := stub .GetPrivateData ("COLLECTION_FOR_B" , QueryKey )
184210 if err != nil {
185- jsonResp := "{\" Error\" :\" Failed to get state for " + A + "\" }"
211+ jsonResp := "{\" Error\" :\" Failed to get state for " + QueryKey + "\" }"
186212 return shim .Error (jsonResp )
187213 }
188214
189215 if Avalbytes == nil {
190- jsonResp := "{\" Error\" :\" Nil amount for " + A + "\" }"
216+ jsonResp := "{\" Error\" :\" Nil amount for " + QueryKey + "\" }"
191217 return shim .Error (jsonResp )
192218 }
193219
194- jsonResp := "{\" Name\" :\" " + A + "\" ,\" Amount\" :\" " + string (Avalbytes ) + "\" }"
220+ jsonResp := "{\" Name\" :\" " + QueryKey + "\" ,\" Amount\" :\" " + string (Avalbytes ) + "\" }"
195221 logger .Infof ("Query Response:%s\n " , jsonResp )
196222 return shim .Success (Avalbytes )
197223}
0 commit comments