|
32 | 32 | import static org.hyperledger.java.shim.HandlerHelper.newCompletedEventMessage;
|
33 | 33 | import static org.hyperledger.java.shim.HandlerHelper.newErrorEventMessage;
|
34 | 34 |
|
35 |
| -import java.util.ArrayList; |
36 | 35 | import java.util.HashMap;
|
37 | 36 | import java.util.List;
|
38 | 37 | import java.util.Map;
|
@@ -208,15 +207,15 @@ public void handleInit(ChaincodeMessage message) {
|
208 | 207 |
|
209 | 208 | // Get the function and args from Payload
|
210 | 209 | final ChaincodeInput input = ChaincodeInput.parseFrom(message.getPayload());
|
211 |
| - |
| 210 | + |
212 | 211 | // Mark as a transaction (allow put/del state)
|
213 | 212 | markIsTransaction(message.getTxid(), true);
|
214 | 213 |
|
215 | 214 | // Create the ChaincodeStub which the chaincode can use to callback
|
216 |
| - final ChaincodeStub stub = new ChaincodeStub(message.getTxid(), this); |
| 215 | + final ChaincodeStub stub = new ChaincodeStub(message.getTxid(), this, input.getArgsList()); |
217 | 216 |
|
218 | 217 | // Call chaincode's Run
|
219 |
| - final Response result = chaincode.run(stub, getFunction(input.getArgsList()), getParameters(input.getArgsList())); |
| 218 | + final Response result = chaincode.init(stub); |
220 | 219 | logger.debug(String.format(String.format("[%s]Init succeeded. Sending %s", shortID(message), COMPLETED)));
|
221 | 220 |
|
222 | 221 | if(result.getStatus() == Status.SUCCESS_VALUE) {
|
@@ -252,19 +251,6 @@ public void handleInit(ChaincodeMessage message) {
|
252 | 251 | }).start();
|
253 | 252 | }
|
254 | 253 |
|
255 |
| - private String getFunction(List<ByteString> args) { |
256 |
| - return (args.size() > 0) ? args.get(0).toStringUtf8() : ""; |
257 |
| - } |
258 |
| - |
259 |
| - private String[] getParameters(List<ByteString> args) { |
260 |
| - final ArrayList<String> results = new ArrayList<>(); |
261 |
| - // skip arg[0], that is the function name |
262 |
| - for(int i = 1; i < args.size(); i++) { |
263 |
| - results.add(args.get(i).toStringUtf8()); |
264 |
| - } |
265 |
| - return results.toArray(new String[results.size()]); |
266 |
| - } |
267 |
| - |
268 | 254 | // enterInitState will initialize the chaincode if entering init from established.
|
269 | 255 | public void beforeInit(Event event) {
|
270 | 256 | logger.debug(String.format("Before %s event.", event.name));
|
@@ -305,12 +291,12 @@ public void handleTransaction(ChaincodeMessage message) {
|
305 | 291 | markIsTransaction(message.getTxid(), true);
|
306 | 292 |
|
307 | 293 | // Create the ChaincodeStub which the chaincode can use to callback
|
308 |
| - final ChaincodeStub stub = new ChaincodeStub(message.getTxid(), this); |
| 294 | + final ChaincodeStub stub = new ChaincodeStub(message.getTxid(), this, input.getArgsList()); |
309 | 295 |
|
310 | 296 | // Call chaincode's Run
|
311 | 297 | Response response;
|
312 | 298 | try {
|
313 |
| - response = chaincode.run(stub, getFunction(input.getArgsList()), getParameters(input.getArgsList())); |
| 299 | + response = chaincode.invoke(stub); |
314 | 300 | } catch (Throwable throwable) {
|
315 | 301 | // Send ERROR message to chaincode support and change state
|
316 | 302 | logger.error(String.format("[%s]Error running chaincode. Transaction execution failed. Sending %s", shortID(message), ERROR));
|
|
0 commit comments