Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/enable choosing bindings #19

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7c967d9
Add SCIP methods response POJOs
ghareeb-falazi Feb 22, 2022
dd1f8c1
Create initial JsonRpcBinding
ghareeb-falazi Feb 22, 2022
97163b7
Add unit test for invocationresponse json-rpc binding
ghareeb-falazi Feb 22, 2022
2b79430
add unit tests for jsonrpc binding
ghareeb-falazi Feb 22, 2022
0511832
Add initial implementation for CamundaBinding
ghareeb-falazi Feb 22, 2022
8b0e446
Add initial test for camunda binding
ghareeb-falazi Feb 22, 2022
7172e1d
Fix Jackson/Jersey compatibility
ghareeb-falazi Feb 23, 2022
7a0279c
Fix web3j dependencies
ghareeb-falazi Feb 23, 2022
f229f15
Finalize Camunda Binding
ghareeb-falazi Feb 23, 2022
d149761
Use new mechanism
ghareeb-falazi Feb 23, 2022
5f027d9
Reorganize Exceptions
ghareeb-falazi Feb 24, 2022
ab9bb81
Fix EndpointBinding tests
ghareeb-falazi Feb 24, 2022
15e9b35
Fix project setup
ghareeb-falazi Feb 24, 2022
99644ef
Add support for detecting more Ethereum errors
ghareeb-falazi Feb 24, 2022
91628de
Update pom.xml
ghareeb-falazi Feb 24, 2022
32bccb9
Correctly handle a timeout value of 0
ghareeb-falazi Feb 24, 2022
6cdaa5d
Implement Endpoint Binding Rules Controller
ghareeb-falazi Feb 24, 2022
aa267bd
Fix Error Camunda Binding
ghareeb-falazi Feb 25, 2022
49de71b
fix bug in submitting transactions
ghareeb-falazi Feb 25, 2022
f8dbe30
Catch all exceptions inside observable
ghareeb-falazi Mar 16, 2022
bc5737a
catch communication errors
ghareeb-falazi Mar 18, 2022
920b2e2
Fix Camunda Binding
ghareeb-falazi Mar 23, 2022
459fe77
Update EthereumAdapter.java
ghareeb-falazi Mar 23, 2022
79c8a28
Remove ProcessInstanceID from Camunda Message
dabberpk Mar 31, 2022
d5cd039
Merge pull request #16 from dabberpk/feature/enable-choosing-bindings
ghareeb-falazi Mar 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
330 changes: 236 additions & 94 deletions README.md

Large diffs are not rendered by default.

54 changes: 29 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<version>3.8.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
Expand Down Expand Up @@ -55,45 +55,31 @@
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>${jersey.version}</version>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>

<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>

<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>4.5.6</version>
<version>${org.web3j.version}</version>
</dependency>


<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -180,10 +166,25 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
<version>${org.junit.jupiter}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${org.junit.jupiter}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>4.9.0</version>
<scope>test</scope>
</dependency>



<dependency>
<groupId>com.github.arteam</groupId>
<artifactId>simple-json-rpc-server</artifactId>
Expand Down Expand Up @@ -211,10 +212,13 @@
</exclusions>
</dependency>


</dependencies>
<properties>
<jersey.version>2.9.1</jersey.version>
<jackson.version>[2.9.9.2,)</jackson.version>
<org.web3j.version>4.9.0</org.web3j.version>
<org.junit.jupiter>5.8.2</org.junit.jupiter>
<jersey.version>2.35</jersey.version>
<jackson.version>2.12.1</jackson.version>
<jsonrpc.version>0.10</jsonrpc.version>
<org.slf4j>1.7.25</org.slf4j>
<ch.qos.logback.logback-classic.version>1.2.3</ch.qos.logback.logback-classic.version>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static AdapterManager getInstance() {

public BlockchainAdapter getAdapter(String blockchainId) throws BlockchainIdNotFoundException, BlockchainNodeUnreachableException {
AbstractConnectionProfile connectionProfile = ConnectionProfilesManager.getInstance().getConnectionProfiles().get(blockchainId);
// no connection profile!
// no connection profiles!
if (connectionProfile == null) {
final String msg = String.format("blockchain-id <%s> does not exist!", blockchainId);
log.error(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public class EthereumAdapter extends AbstractAdapter {
private final int averageBlockTimeSeconds;

public EthereumAdapter(final String nodeUrl, final int averageBlockTimeSeconds) {
if (averageBlockTimeSeconds <= 0)
throw new IllegalArgumentException("The average block time must be a value larger than 0");
this.nodeUrl = nodeUrl;
this.averageBlockTimeSeconds = averageBlockTimeSeconds;
// We use a specific implementation so we can change the polling period (useful for prototypes).
Expand Down Expand Up @@ -211,6 +213,7 @@ private static CompletionException wrapEthereumExceptions(Throwable e) {
return new CompletionException(mapEthereumException(e));
}

// todo this code seems fishy.
private static BalException mapEthereumException(Throwable e) {
BalException result;

Expand Down Expand Up @@ -245,7 +248,17 @@ public CompletableFuture<Transaction> submitTransaction(String receiverAddress,
return Transfer.sendFunds(web3j, credentials, receiverAddress, value, Convert.Unit.WEI) // 1 wei = 10^-18 Ether
.sendAsync()
// when an exception (e.g., ConnectException happens), the following is skipped
.thenCompose(tx -> subscribeForTxEvent(tx.getTransactionHash(), waitFor, TransactionState.CONFIRMED, TransactionState.NOT_FOUND))
.thenCompose(tx -> {
if (!tx.isStatusOK()) {
// we go here, for example, for block gas limit exceptions.
InvalidTransactionException exception = new InvalidTransactionException(
"Failed to submit transaction. Ethereum JSON-RPC code: " + tx.getStatus());
log.error("Failed to submit transaction. Ethereum JSON-RPC code: " + tx.getStatus());
throw new CompletionException(exception);
}

return subscribeForTxEvent(tx.getTransactionHash(), waitFor, TransactionState.CONFIRMED, TransactionState.NOT_FOUND);
})
.exceptionally((e) -> {
throw wrapEthereumExceptions(e);
}
Expand Down Expand Up @@ -621,6 +634,15 @@ private CompletableFuture<Transaction> invokeFunctionByTransaction(long waitFor,
.thenCompose(transaction -> web3j.ethSendTransaction(transaction).sendAsync())
.thenCompose(tx -> {
final String txHash = tx.getTransactionHash();

if (tx.hasError()) {
InvokeSmartContractFunctionFailure exception = new InvokeSmartContractFunctionFailure(
"Failed to invoke smart contract function via tx. Reason: " + tx.getError().getMessage());
log.error("Transaction submission failed. Code: {}, Reason: {}", tx.getError().getCode(), tx.getError().getMessage());

throw new CompletionException(exception);
}

log.info("transaction hash is {}", txHash);
return CompletableFuture.completedFuture(txHash);
})
Expand Down Expand Up @@ -652,7 +674,8 @@ private CompletableFuture<TransactionReceipt> waitUntilTransactionIsMined(final
result.complete(receipt.getResult());
}
}
} catch (IOException e) {

} catch (Exception e) {// most likely IOException
result.completeExceptionally(e);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidScipParameterException;
import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidTransactionException;
import blockchains.iaas.uni.stuttgart.de.exceptions.InvokeSmartContractFunctionFailure;
import blockchains.iaas.uni.stuttgart.de.exceptions.InvokeSmartContractFunctionRevoke;
import blockchains.iaas.uni.stuttgart.de.exceptions.NotSupportedException;
import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException;
import blockchains.iaas.uni.stuttgart.de.model.Occurrence;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package blockchains.iaas.uni.stuttgart.de.adaptation.interfaces;

import java.math.BigDecimal;
import java.time.Period;
import java.util.List;
import java.util.concurrent.CompletableFuture;

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart
* Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart
* Author: Ghareeb Falazi
*
* This program and the accompanying materials are made available under the
Expand All @@ -23,9 +23,5 @@ public BalException(String message, Throwable cause) {
super(message, cause);
}

public BalException(Throwable cause) {
super(cause);
}

public abstract int getCode();
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/********************************************************************************
* Copyright (c) 2018-2019 Institute for the Architecture of Application System -
* University of Stuttgart
/*******************************************************************************
* Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart
* Author: Ghareeb Falazi
*
* 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.exceptions;

import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/********************************************************************************
* Copyright (c) 2018-2019 Institute for the Architecture of Application System -
* University of Stuttgart
/*******************************************************************************
* Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart
* Author: Ghareeb Falazi
*
* 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.exceptions;

import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart
* Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart
* Author: Ghareeb Falazi
*
* This program and the accompanying materials are made available under the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart
* Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart
* Author: Ghareeb Falazi
*
* This program and the accompanying materials are made available under the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/********************************************************************************
* Copyright (c) 2018-2019 Institute for the Architecture of Application System -
* University of Stuttgart
/*******************************************************************************
* Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart
* Author: Ghareeb Falazi
*
* 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.exceptions;

import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError;

@JsonRpcError(code = ExceptionCode.InvocationError, message = "An error occurred while trying to invoke the smart contract function.")
@JsonRpcError(code = ExceptionCode.InvocationError, message = "An error occurred while trying to submit a transaction.")
public class InvalidTransactionException extends BalException {

public InvalidTransactionException() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019-2022 Institute for the Architecture of Application System - University of Stuttgart
* Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart
* Author: Ghareeb Falazi
*
* This program and the accompanying materials are made available under the
Expand All @@ -12,7 +12,8 @@

import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError;

@JsonRpcError(code = ExceptionCode.InvocationError, message = "The smart contract function invocation failed.")
@JsonRpcError(code = ExceptionCode.InvocationError,
message = "The smart contract function invocation failed.")
public class InvokeSmartContractFunctionFailure extends BalException {
public InvokeSmartContractFunctionFailure() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart
* Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart
* Author: Ghareeb Falazi
*
* This program and the accompanying materials are made available under the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart
* Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart
* Author: Ghareeb Falazi
*
* This program and the accompanying materials are made available under the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart
* Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart
* Author: Ghareeb Falazi
*
* This program and the accompanying materials are made available under the
Expand Down
Loading