26
26
import org .fisco .bcos .sdk .jni .utilities .tx .TransactionBuilderJniObj ;
27
27
import org .fisco .bcos .sdk .jni .utilities .tx .TxPair ;
28
28
import org .fisco .bcos .sdk .v3 .client .Client ;
29
+ import org .fisco .bcos .sdk .v3 .client .RespCallback ;
29
30
import org .fisco .bcos .sdk .v3 .client .protocol .response .Call ;
30
31
import org .fisco .bcos .sdk .v3 .codec .ContractCodec ;
31
32
import org .fisco .bcos .sdk .v3 .codec .ContractCodecException ;
32
33
import org .fisco .bcos .sdk .v3 .codec .datatypes .Type ;
33
34
import org .fisco .bcos .sdk .v3 .codec .wrapper .ABIObject ;
34
35
import org .fisco .bcos .sdk .v3 .crypto .keypair .CryptoKeyPair ;
35
36
import org .fisco .bcos .sdk .v3 .model .PrecompiledRetCode ;
37
+ import org .fisco .bcos .sdk .v3 .model .Response ;
36
38
import org .fisco .bcos .sdk .v3 .model .RetCode ;
37
39
import org .fisco .bcos .sdk .v3 .model .TransactionReceipt ;
38
40
import org .fisco .bcos .sdk .v3 .model .callback .TransactionCallback ;
@@ -434,6 +436,52 @@ public CallResponse sendCall(CallRequest callRequest)
434
436
return callResponse ;
435
437
}
436
438
439
+ @ Override
440
+ public void sendCallAsync (
441
+ String from ,
442
+ String to ,
443
+ String abi ,
444
+ String functionName ,
445
+ List <Object > params ,
446
+ RespCallback <CallResponse > callback )
447
+ throws ContractCodecException {
448
+ byte [] data = this .contractCodec .encodeMethod (abi , functionName , params );
449
+ callAndGetResponseAsync (from , to , abi , functionName , data , callback );
450
+ }
451
+
452
+ @ Override
453
+ public void sendCallAsync (CallRequest callRequest , RespCallback <CallResponse > callback ) {
454
+ this .asyncExecuteCall (
455
+ callRequest ,
456
+ new RespCallback <Call >() {
457
+ @ Override
458
+ public void onResponse (Call call ) {
459
+ try {
460
+ CallResponse callResponse =
461
+ parseCallResponseStatus (call .getCallResult ());
462
+ String callOutput = call .getCallResult ().getOutput ();
463
+ Pair <List <Object >, List <ABIObject >> results =
464
+ contractCodec .decodeMethodAndGetOutputObject (
465
+ callRequest .getAbi (), callOutput );
466
+ callResponse .setValues (JsonUtils .toJson (results .getLeft ()));
467
+ callResponse .setReturnObject (results .getLeft ());
468
+ callResponse .setReturnABIObject (results .getRight ());
469
+ callback .onResponse (callResponse );
470
+ } catch (TransactionBaseException | ContractCodecException e ) {
471
+ Response response = new Response ();
472
+ response .setErrorMessage (e .getMessage ());
473
+ response .setErrorCode (-5000 );
474
+ callback .onError (response );
475
+ }
476
+ }
477
+
478
+ @ Override
479
+ public void onError (Response errorResponse ) {
480
+ callback .onError (errorResponse );
481
+ }
482
+ });
483
+ }
484
+
437
485
@ Override
438
486
public CallResponse sendCallWithStringParams (
439
487
String from , String to , String abi , String functionName , List <String > paramsList )
@@ -442,6 +490,56 @@ public CallResponse sendCallWithStringParams(
442
490
return this .callAndGetResponse (from , to , abi , functionName , data );
443
491
}
444
492
493
+ @ Override
494
+ public void sendCallWithStringParamsAsync (
495
+ String from ,
496
+ String to ,
497
+ String abi ,
498
+ String functionName ,
499
+ List <String > params ,
500
+ RespCallback <CallResponse > callback )
501
+ throws TransactionBaseException , ContractCodecException {
502
+ byte [] data = this .contractCodec .encodeMethodFromString (abi , functionName , params );
503
+ callAndGetResponseAsync (from , to , abi , functionName , data , callback );
504
+ }
505
+
506
+ private void callAndGetResponseAsync (
507
+ String from ,
508
+ String to ,
509
+ String abi ,
510
+ String functionName ,
511
+ byte [] data ,
512
+ RespCallback <CallResponse > callback ) {
513
+ this .asyncExecuteCall (
514
+ from ,
515
+ to ,
516
+ data ,
517
+ new RespCallback <Call >() {
518
+ @ Override
519
+ public void onResponse (Call call ) {
520
+ try {
521
+ CallResponse callResponse =
522
+ parseCallResponseStatus (call .getCallResult ());
523
+ List <Type > decodedResult =
524
+ contractCodec .decodeMethodAndGetOutputObject (
525
+ abi , functionName , call .getCallResult ().getOutput ());
526
+ callResponse .setResults (decodedResult );
527
+ callback .onResponse (callResponse );
528
+ } catch (TransactionBaseException | ContractCodecException e ) {
529
+ Response response = new Response ();
530
+ response .setErrorMessage (e .getMessage ());
531
+ response .setErrorCode (-5000 );
532
+ callback .onError (response );
533
+ }
534
+ }
535
+
536
+ @ Override
537
+ public void onError (Response errorResponse ) {
538
+ callback .onError (errorResponse );
539
+ }
540
+ });
541
+ }
542
+
445
543
public CallResponse callAndGetResponse (
446
544
String from , String to , String abi , String functionName , byte [] data )
447
545
throws ContractCodecException , TransactionBaseException {
0 commit comments