20
20
21
21
import blockchains .iaas .uni .stuttgart .de .adaptation .AdapterManager ;
22
22
import blockchains .iaas .uni .stuttgart .de .api .exceptions .*;
23
+ import blockchains .iaas .uni .stuttgart .de .api .model .*;
23
24
import blockchains .iaas .uni .stuttgart .de .management .callback .CallbackManager ;
24
25
import blockchains .iaas .uni .stuttgart .de .management .callback .CamundaMessageTranslator ;
25
26
import blockchains .iaas .uni .stuttgart .de .management .callback .ScipMessageTranslator ;
31
32
import blockchains .iaas .uni .stuttgart .de .management .model .Subscription ;
32
33
import blockchains .iaas .uni .stuttgart .de .management .model .SubscriptionKey ;
33
34
import blockchains .iaas .uni .stuttgart .de .management .model .SubscriptionType ;
34
- import blockchains .iaas .uni .stuttgart .de .api .model .Parameter ;
35
- import blockchains .iaas .uni .stuttgart .de .api .model .QueryResult ;
36
- import blockchains .iaas .uni .stuttgart .de .api .model .TimeFrame ;
37
- import blockchains .iaas .uni .stuttgart .de .api .model .Transaction ;
38
- import blockchains .iaas .uni .stuttgart .de .api .model .TransactionState ;
39
35
import com .google .common .base .Strings ;
36
+ import io .reactivex .Observable ;
40
37
import io .reactivex .disposables .Disposable ;
41
38
import org .slf4j .Logger ;
42
39
import org .slf4j .LoggerFactory ;
@@ -366,42 +363,33 @@ public void invokeSmartContractFunction(
366
363
final String correlationId ,
367
364
final String signature ) throws BalException {
368
365
369
- // Validate scip parameters!
370
- if (Strings .isNullOrEmpty (blockchainIdentifier )
371
- || Strings .isNullOrEmpty (smartContractPath )
372
- || Strings .isNullOrEmpty (functionIdentifier )
373
- || timeoutMillis < 0
374
- || MathUtils .doubleCompare (requiredConfidence , 0.0 ) < 0
375
- || MathUtils .doubleCompare (requiredConfidence , 100.0 ) > 0 ) {
376
- throw new InvalidScipParameterException ();
377
- }
378
-
379
- final AdapterManager adapterManager = AdapterManager .getInstance ();
380
- final double minimumConfidenceAsProbability = requiredConfidence / 100.0 ;
381
- final BlockchainAdapter adapter = adapterManager .getAdapter (blockchainIdentifier );
382
- final CompletableFuture <Transaction > future = adapter .invokeSmartContract (smartContractPath ,
383
- functionIdentifier , inputs , outputs , minimumConfidenceAsProbability , timeoutMillis );
366
+ final CompletableFuture <Transaction > future = this .invokeSmartContractFunction (blockchainIdentifier , smartContractPath ,
367
+ functionIdentifier , inputs , outputs , requiredConfidence , timeoutMillis , signature );
384
368
385
369
future .
386
370
thenAccept (tx -> {
387
371
if (tx != null ) {
388
- if (tx .getState () == TransactionState .CONFIRMED || tx .getState () == TransactionState .RETURN_VALUE ) {
389
- CallbackManager .getInstance ().sendCallback (callbackUrl ,
390
- ScipMessageTranslator .getInvocationResponseMessage (
391
- correlationId ,
392
- tx .getReturnValues ()));
393
- } else {// it is NOT_FOUND (it was dropped from the system due to invalidation) or ERRORED
394
- if (tx .getState () == TransactionState .NOT_FOUND ) {
395
- CallbackManager .getInstance ().sendCallback (callbackUrl ,
396
- ScipMessageTranslator .getAsynchronousErrorResponseMessage (
397
- correlationId ,
398
- new TransactionNotFoundException ("The transaction associated with a function invocation is invalidated after it was mined." )));
399
- } else {
372
+ if (callbackUrl != null ) {
373
+ if (tx .getState () == TransactionState .CONFIRMED || tx .getState () == TransactionState .RETURN_VALUE ) {
400
374
CallbackManager .getInstance ().sendCallback (callbackUrl ,
401
- ScipMessageTranslator .getAsynchronousErrorResponseMessage (
375
+ ScipMessageTranslator .getInvocationResponseMessage (
402
376
correlationId ,
403
- new InvokeSmartContractFunctionFailure ("The smart contract function invocation reported an error." )));
377
+ tx .getReturnValues ()));
378
+ } else {// it is NOT_FOUND (it was dropped from the system due to invalidation) or ERRORED
379
+ if (tx .getState () == TransactionState .NOT_FOUND ) {
380
+ CallbackManager .getInstance ().sendCallback (callbackUrl ,
381
+ ScipMessageTranslator .getAsynchronousErrorResponseMessage (
382
+ correlationId ,
383
+ new TransactionNotFoundException ("The transaction associated with a function invocation is invalidated after it was mined." )));
384
+ } else {
385
+ CallbackManager .getInstance ().sendCallback (callbackUrl ,
386
+ ScipMessageTranslator .getAsynchronousErrorResponseMessage (
387
+ correlationId ,
388
+ new InvokeSmartContractFunctionFailure ("The smart contract function invocation reported an error." )));
389
+ }
404
390
}
391
+ } else {
392
+ log .info ("callbackUrl is null" );
405
393
}
406
394
} else {
407
395
log .info ("resulting transaction is null" );
@@ -414,6 +402,9 @@ public void invokeSmartContractFunction(
414
402
CallbackManager .getInstance ().sendCallback (callbackUrl ,
415
403
ScipMessageTranslator .getAsynchronousErrorResponseMessage (correlationId , (BalException ) e .getCause ()));
416
404
405
+ if (e instanceof ManualUnsubscriptionException || e .getCause () instanceof ManualUnsubscriptionException ) {
406
+ log .info ("Manual unsubscription of SC invocation!" );
407
+ }
417
408
// ManualUnsubscriptionException is also captured here
418
409
return null ;
419
410
}).
@@ -427,6 +418,33 @@ public void invokeSmartContractFunction(
427
418
SubscriptionManager .getInstance ().createSubscription (correlationId , blockchainIdentifier , smartContractPath , subscription );
428
419
}
429
420
421
+ public CompletableFuture <Transaction > invokeSmartContractFunction (
422
+ final String blockchainIdentifier ,
423
+ final String smartContractPath ,
424
+ final String functionIdentifier ,
425
+ final List <Parameter > inputs ,
426
+ final List <Parameter > outputs ,
427
+ final double requiredConfidence ,
428
+ final long timeoutMillis ,
429
+ final String signature ) throws BalException {
430
+
431
+ // Validate scip parameters!
432
+ if (Strings .isNullOrEmpty (blockchainIdentifier )
433
+ || Strings .isNullOrEmpty (smartContractPath )
434
+ || Strings .isNullOrEmpty (functionIdentifier )
435
+ || timeoutMillis < 0
436
+ || MathUtils .doubleCompare (requiredConfidence , 0.0 ) < 0
437
+ || MathUtils .doubleCompare (requiredConfidence , 100.0 ) > 0 ) {
438
+ throw new InvalidScipParameterException ();
439
+ }
440
+
441
+ final AdapterManager adapterManager = AdapterManager .getInstance ();
442
+ final double minimumConfidenceAsProbability = requiredConfidence / 100.0 ;
443
+ final BlockchainAdapter adapter = adapterManager .getAdapter (blockchainIdentifier );
444
+ return adapter .invokeSmartContract (smartContractPath ,
445
+ functionIdentifier , inputs , outputs , minimumConfidenceAsProbability , timeoutMillis );
446
+ }
447
+
430
448
public void subscribeToEvent (
431
449
final String blockchainIdentifier ,
432
450
final String smartContractPath ,
@@ -437,21 +455,13 @@ public void subscribeToEvent(
437
455
final String callbackUrl ,
438
456
final String correlationIdentifier ) {
439
457
440
- // Validate scip parameters!
441
- if (Strings .isNullOrEmpty (blockchainIdentifier )
442
- || Strings .isNullOrEmpty (smartContractPath )
443
- || Strings .isNullOrEmpty (eventIdentifier )
444
- || MathUtils .doubleCompare (degreeOfConfidence , 0.0 ) < 0
445
- || MathUtils .doubleCompare (degreeOfConfidence , 100.0 ) > 0 ) {
446
- throw new InvalidScipParameterException ();
447
- }
448
458
449
- final double minimumConfidenceAsProbability = degreeOfConfidence / 100.0 ;
450
459
451
460
// first, we cancel previous identical subscriptions.
452
461
this .cancelEventSubscriptions (blockchainIdentifier , smartContractPath , correlationIdentifier , eventIdentifier , outputParameters );
453
- Disposable result = AdapterManager .getInstance ().getAdapter (blockchainIdentifier )
454
- .subscribeToEvent (smartContractPath , eventIdentifier , outputParameters , minimumConfidenceAsProbability , filter )
462
+
463
+
464
+ Disposable result = this .subscribeToEvent (blockchainIdentifier , smartContractPath , eventIdentifier , outputParameters , degreeOfConfidence , filter )
455
465
.doFinally (() -> {
456
466
// remove subscription from subscription list
457
467
SubscriptionManager .getInstance ().removeSubscription (correlationIdentifier , blockchainIdentifier , smartContractPath );
@@ -471,6 +481,28 @@ public void subscribeToEvent(
471
481
SubscriptionManager .getInstance ().createSubscription (correlationIdentifier , blockchainIdentifier , smartContractPath , subscription );
472
482
}
473
483
484
+ public Observable <Occurrence > subscribeToEvent (String blockchainIdentifier ,
485
+ final String smartContractPath ,
486
+ final String eventIdentifier ,
487
+ final List <Parameter > outputParameters ,
488
+ final double degreeOfConfidence ,
489
+ final String filter ) {
490
+ // Validate scip parameters!
491
+ if (Strings .isNullOrEmpty (blockchainIdentifier )
492
+ || Strings .isNullOrEmpty (smartContractPath )
493
+ || Strings .isNullOrEmpty (eventIdentifier )
494
+ || MathUtils .doubleCompare (degreeOfConfidence , 0.0 ) < 0
495
+ || MathUtils .doubleCompare (degreeOfConfidence , 100.0 ) > 0 ) {
496
+ throw new InvalidScipParameterException ();
497
+ }
498
+
499
+ final double minimumConfidenceAsProbability = degreeOfConfidence / 100.0 ;
500
+
501
+ return AdapterManager .getInstance ().getAdapter (blockchainIdentifier )
502
+ .subscribeToEvent (smartContractPath , eventIdentifier , outputParameters , minimumConfidenceAsProbability , filter );
503
+ }
504
+
505
+
474
506
public void cancelEventSubscriptions (String blockchainId , String smartContractId , String correlationId , String eventIdentifier , List <Parameter > parameters ) {
475
507
// Validate scip parameters!
476
508
if (Strings .isNullOrEmpty (blockchainId ) || Strings .isNullOrEmpty (smartContractId )) {
0 commit comments