diff --git a/pom.xml b/pom.xml index a3de5ec..8390e8f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ blockchains.iaas.uni.stuttgart.de blockchain-access-layer-api - 1.0.7 + 2.0.7 8 @@ -61,5 +61,10 @@ 5.4.0 test + + org.apache.commons + commons-lang3 + 3.12.0 + \ No newline at end of file diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/CancelRejectedError.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/CancelRejectedError.java new file mode 100644 index 0000000..2d45696 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/CancelRejectedError.java @@ -0,0 +1,31 @@ +/******************************************************************************** + * Copyright (c) 2023 Institute for the Architecture of Application System - + * University of Stuttgart + * Author: Akshay Patel + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package blockchains.iaas.uni.stuttgart.de.api.exceptions; + +import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; + +@JsonRpcError(code = ExceptionCode.CancelRejectedError, message = "The specified invocation cannot be cancelled") +public class CancelRejectedError extends BalException { + + public CancelRejectedError() { + super(); + } + + public CancelRejectedError(String message) { + super(message); + } + + @Override + public int getCode() { + return ExceptionCode.CancelRejectedError; + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/ExceptionCode.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/ExceptionCode.java index 27381a7..60a2b88 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/ExceptionCode.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/ExceptionCode.java @@ -15,7 +15,7 @@ public class ExceptionCode { public static final int UnknownError = 0; /** - * The blockchain instance, smart contract, event or function are not found + * The blockchain instance, smart contract, or invocation, event or function are not found */ public static final int NotFound = -32000; /** @@ -73,4 +73,11 @@ public class ExceptionCode { * This is an asynchronous error. */ public static final int Timeout = -32201; + + public static final int CancelRejectedError = -32209; + + public static final int ReplaceRejectedError = -32210; + + public static final int InvalidMessageSignedError = -32211; + } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/InsufficientFundsException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/InsufficientFundsException.java new file mode 100644 index 0000000..daaaacf --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/InsufficientFundsException.java @@ -0,0 +1,32 @@ +/******************************************************************************** + * Copyright (c) 2023 Institute for the Architecture of Application System - + * University of Stuttgart + * Author: Akshay Patel + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package blockchains.iaas.uni.stuttgart.de.api.exceptions; + +import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; + +@JsonRpcError(code = ExceptionCode.InsufficientFunds, message = "Not enough funds to invoke the state-changing\n" + + "smart contract function.") +public class InsufficientFundsException extends BalException { + + public InsufficientFundsException() { + super(); + } + + public InsufficientFundsException(String message) { + super(message); + } + + @Override + public int getCode() { + return ExceptionCode.InsufficientFunds; + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/InvocationNotFoundException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/InvocationNotFoundException.java new file mode 100644 index 0000000..cc95bf9 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/InvocationNotFoundException.java @@ -0,0 +1,31 @@ +/******************************************************************************** + * Copyright (c) 2023 Institute for the Architecture of Application System - + * University of Stuttgart + * Author: Akshay Patel + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package blockchains.iaas.uni.stuttgart.de.api.exceptions; + +import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; + +@JsonRpcError(code = ExceptionCode.NotFound, message = "The specified invocation with given correlation id cannot be found") +public class InvocationNotFoundException extends BalException { + + public InvocationNotFoundException() { + super(); + } + + public InvocationNotFoundException(String message) { + super(message); + } + + @Override + public int getCode() { + return ExceptionCode.NotFound; + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/ReplaceRejectedError.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/ReplaceRejectedError.java new file mode 100644 index 0000000..f8cd8c6 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/api/exceptions/ReplaceRejectedError.java @@ -0,0 +1,31 @@ +/******************************************************************************** + * Copyright (c) 2023 Institute for the Architecture of Application System - + * University of Stuttgart + * Author: Akshay Patel + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package blockchains.iaas.uni.stuttgart.de.api.exceptions; + +import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; + +@JsonRpcError(code = ExceptionCode.ReplaceRejectedError, message = "The specified invocation cannot be replaced") +public class ReplaceRejectedError extends BalException { + + public ReplaceRejectedError() { + super(); + } + + public ReplaceRejectedError(String message) { + super(message); + } + + @Override + public int getCode() { + return ExceptionCode.ReplaceRejectedError; + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/api/interfaces/BlockchainAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/api/interfaces/BlockchainAdapter.java index c119842..8533033 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/api/interfaces/BlockchainAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/api/interfaces/BlockchainAdapter.java @@ -1,7 +1,8 @@ /******************************************************************************** - * Copyright (c) 2018-2022 Institute for the Architecture of Application System - + * Copyright (c) 2018-2023 Institute for the Architecture of Application System - * University of Stuttgart * Author: Ghareeb Falazi + * Co-author: Akshay Patel * * This program and the accompanying materials are made available under the * terms the Apache Software License 2.0 @@ -17,6 +18,7 @@ import blockchains.iaas.uni.stuttgart.de.api.exceptions.NotSupportedException; import blockchains.iaas.uni.stuttgart.de.api.model.*; import io.reactivex.Observable; +import org.apache.commons.lang3.tuple.ImmutablePair; import java.math.BigDecimal; import java.util.List; @@ -84,10 +86,17 @@ public interface BlockchainAdapter { CompletableFuture invokeSmartContract( String smartContractPath, String functionIdentifier, + List typeArguments, List inputs, List outputs, double requiredConfidence, - long timeoutMillis + long timeoutMillis, + String signature, + String signer, + List signers, + List> signatures, + long minimumNumberOfSignatures + ) throws BalException; /** @@ -115,12 +124,60 @@ Observable subscribeToEvent(String smartContractAddress, String even * @param timeFrame The timeFrame in which to consider event occurrences. * @return A completable future containing a list of matching occurrences. */ - CompletableFuture queryEvents(String smartContractAddress, String eventIdentifier, List outputParameters, - String filter, TimeFrame timeFrame) throws BalException; + CompletableFuture queryEvents(String smartContractAddress, String eventIdentifier, + List typeArguments, List outputParameters, String filter, + TimeFrame timeFrame) + throws BalException; + /** * Tests the connection settings with the underlying blockchain * * @return true if the connection is successful, an error message otherwise. */ String testConnection(); + + + CompletableFuture tryReplaceInvocation(String correlationId, String smartContractPath, + String functionIdentifier, + List typeArguments, + List inputs, + List outputs, + double requiredConfidence, + String signature, + String signer, + List signers, + long minimumNumberOfSignatures); + + boolean tryCancelInvocation(String correlationId); + + /* + * This method should be implemented by the plugin to indicate whether the plugin is capable of handling subscription + * and the callbacks both. + * */ + boolean canHandleDelegatedSubscription(); + + /* + * This method is an alternative to initial gateway implementation where the gateway acts as a centralized entity + * and handles subscriptions and callbacks. Using this method, a plugin can must invoke callbacks on its own rather + * than gateway managing the callbacks. + * */ + boolean delegatedSubscribe(String functionIdentifier, + String eventIdentifier, + List outputParameters, + double degreeOfConfidence, + String filter, + String callbackUrl, + String correlationId); + + /* + * This method is an alternative to initial gateway implementation where the gateway acts as a centralized entity + * and handles subscriptions, callbacks and cancelling subscriptions. + * */ + boolean delegatedUnsubscribe(String smartContractPath, + String functionIdentifier, + String eventIdentifier, + List typeArguments, + List parameters, + String correlationId); + }