Skip to content
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

.idea/

target/
74 changes: 74 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>blockchains.iaas.uni.stuttgart.de</groupId>
<artifactId>blockchain-access-layer-api</artifactId>
<version>1.0.1-SNAPSHOT</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<jsonrpc.version>0.10</jsonrpc.version>
<org.slf4j>1.7.25</org.slf4j>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>com.github.arteam</groupId>
<artifactId>simple-json-rpc-server</artifactId>
<version>${jsonrpc.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.arteam</groupId>
<artifactId>simple-json-rpc-client</artifactId>
<version>${jsonrpc.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>26.0-android</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.json/javax.json-api -->
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.2.21</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2022 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;

import blockchains.iaas.uni.stuttgart.de.api.interfaces.BlockchainAdapter;
import org.pf4j.ExtensionPoint;

import java.util.Map;

public interface IAdapterExtenstion extends ExtensionPoint {
BlockchainAdapter getAdapter(Map<String, String> parameters);

String getBlockChainId();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/********************************************************************************
* Copyright (c) 2019 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.api.connectionprofiles;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

import java.util.Properties;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME)
public abstract class AbstractConnectionProfile {
private static final String PREFIX = "common.";
private static final String ADVERSARY_VOTING_RATIO = PREFIX + "adversaryVotingRatio";
private double adversaryVotingRatio;

public double getAdversaryVotingRatio() {
return adversaryVotingRatio;
}

public void setAdversaryVotingRatio(double adversaryVotingRatio) {
if (adversaryVotingRatio < 0 || adversaryVotingRatio > 1.0) {
throw new IllegalArgumentException("Voting power of adversary should be between 0.0 and 1.0, but (" +
adversaryVotingRatio + ") is passed!");
}

this.adversaryVotingRatio = adversaryVotingRatio;
}

public Properties getAsProperties() {
Properties result = new Properties();
result.put(ADVERSARY_VOTING_RATIO, String.valueOf(adversaryVotingRatio));

return result;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AbstractConnectionProfile that = (AbstractConnectionProfile) o;
return this.getAsProperties().equals(that.getAsProperties());
}

@Override
public int hashCode() {
return this.getAsProperties().hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2019 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.api.exceptions;

public abstract class BalException extends RuntimeException {

public BalException() {
}

public BalException(String message) {
super(message);
}

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
@@ -0,0 +1,31 @@
/********************************************************************************
* Copyright (c) 2018-2019 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.api.exceptions;

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

@JsonRpcError(code = ExceptionCode.NotFound, message = "The specified blockchain-id cannot be found")
public class BlockchainIdNotFoundException extends BalException {

public BlockchainIdNotFoundException() {
super();
}

public BlockchainIdNotFoundException(String message) {
super(message);
}

@Override
public int getCode() {
return ExceptionCode.NotFound;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/********************************************************************************
* Copyright (c) 2018-2019 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.api.exceptions;

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

@JsonRpcError(code = ExceptionCode.ConnectionException, message = "The blockchain node cannot be reached.")
public class BlockchainNodeUnreachableException extends BalException {

public BlockchainNodeUnreachableException() {
}

public BlockchainNodeUnreachableException(String message) {
super(message);
}

@Override
public int getCode() {
return ExceptionCode.ConnectionException;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*******************************************************************************
* Copyright (c) 2019 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.api.exceptions;

public class ExceptionCode {
public static final int UnknownError = 0;

/**
* The blockchain instance, smart contract, event or function are not found
*/
public static final int NotFound = -32000;
/**
* Input parameter types, names, or order mismatch the designated function or event.
* This also indicates inability to map a parameter's abstract type to a native type.
*/
public static final int InvalidParameters = -32001;
/**
* Client certificate is missing
*/
public static final int MissingCertificate = -32002;
/**
* The client application is not authorized to perform the requested task.
* Gateway-side authorization.
*/
public static final int NotAuthorized = -32003;
/**
* The specified blockchain instance does not support the requested operation.
*/
public static final int NotSupported = -32004;
/**
* Connection to the underlying blockchain node is not possible.
*/
public static final int ConnectionException = -32005;
/**
* The transaction associated with an function invocation is invalidated after it was mined.
*/
public static final int TransactionInvalidatedException = -32006;

/**
* A scip method parameter has an invalid value
*/
public static final int InvalidScipParam = -32007;

/**
* A general error occurred when trying to invoke a smart contract function
* This error is used when the specific cause of the error cannot be deteremined.
*/
public static final int InvocationError = -32100;
/**
* The smart contract function threw an exception
*/
public static final int ExecutionError = -32101;
/**
* Not enough funds to invoke the state-changing smart contract funciton.
*/
public static final int InsufficientFunds = -32102;
/**
* The BAL instance is not authorized to performed the requested operation on the underlying blockchain.
*/
public static final int BalNotAuthorized = -32103;

/**
* Timeout is reached before fulfilling the desired degree of confidence.
* This is an asynchronous error.
*/
public static final int Timeout = -32201;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2019 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.api.exceptions;

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

@JsonRpcError(code = ExceptionCode.InvalidScipParam, message = "A scip method parameter has an invalid value.")
public class InvalidScipParameterException extends BalException {
@Override
public int getCode() {
return ExceptionCode.InvalidScipParam;
}

public InvalidScipParameterException() {
}

public InvalidScipParameterException(String message) {
super(message);
}
}
Loading