Skip to content

Commit

Permalink
Merge pull request #1 from ghareeb-falazi/sc-support-ethereum
Browse files Browse the repository at this point in the history
support ethereum smart contracts
  • Loading branch information
ghareeb-falazi authored Sep 6, 2019
2 parents f63f22a + 7fd857c commit 05ef324
Show file tree
Hide file tree
Showing 51 changed files with 2,627 additions and 670 deletions.
84 changes: 0 additions & 84 deletions BlockchainAccessLayer.iml

This file was deleted.

11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ paths to create the corresponding subscription:
{application-URL}/webapi/receive-transactions
{application-URL}/webapi/detect-orphaned-transaction
{application-URL}/webapi/ensure-transaction-state
{application-URL}/webapi/invoke-smart-contract-function
```

* A GET method is also provided for the aforementioned URLs that lists the currently active subscriptions.
Expand All @@ -53,6 +54,7 @@ paths to manually delete the corresponding subscription:
{application-URL}/webapi/receive-transactions/{subscription-id}
{application-URL}/webapi/detect-orphaned-transaction/{subscription-id}
{application-URL}/webapi/ensure-transaction-state/{subscription-id}
{application-URL}/webapi/invoke-smart-contract-function
```

## Running a Local geth Node
Expand Down Expand Up @@ -100,8 +102,10 @@ connection, and the availability of peers).
```
bitcoin-cli -getinfo -rpcconnect=<ip address of the node> -rpcport=<port of the node> -rpcuser=<rpc username> -rpcpassword=<rpc password>
```
## Setting-up a Hyperledger Fabric Network
Please follow these steps [Fabric Setup](https://hyperledger-fabric.readthedocs.io/en/latest/getting_started.html)

## Case Study
## Case Study (For BlockME)
The case study invloves a cryptocurrency exchange service utilitzing the blockchain access layer.
The exchange uses the following simplified BlockME-model:

Expand Down Expand Up @@ -146,4 +150,7 @@ You can find the details about the resulting testnet3 Bitcoin transaction [here]
* a _geth_ node is running on a virtual machine in a VSphere accessible from the local network.
* a _bitcoind_ (Bitcoin Core) node is running on a virtual machine in a VSphere accessible from the local network.
* The blockchain access layer is running in a local Tomcat server listening to port 8081
* The camunda engine is running in a local Tomcat server litening to port 8080
* The camunda engine is running in a local Tomcat server litening to port 8080

## Case Study (For BlockME2)
Detailed case study for BlockME2 coming soon!
54 changes: 46 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.hyperledger.fabric-sdk-java</groupId>
<artifactId>fabric-sdk-java</artifactId>
<version>1.4.1</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
Expand All @@ -54,27 +60,36 @@
<!-- 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>2.9.4</version>
<version>${jackson.version}</version>
</dependency>

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

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

<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>3.3.1</version>
<version>4.2.0</version>
</dependency>

<dependency>
<groupId>com.neemre.btcd-cli4j</groupId>
<artifactId>btcd-cli4j-core</artifactId>
Expand Down Expand Up @@ -127,9 +142,23 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.3.0-alpha4</version>

<version>${ch.qos.logback.logback-classic.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j}</version>
<scope>compile</scope>
</dependency>
<dependency>
<!-- jersey 1.x uses java.util.logging - we want to take care about these outputs, too -->
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${org.slf4j}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand All @@ -141,9 +170,18 @@
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<jersey.version>2.9.1</jersey.version>
<jackson.version>2.8.5</jackson.version>
<org.slf4j>1.7.25</org.slf4j>
<ch.qos.logback.logback-classic.version>1.2.3</ch.qos.logback.logback-classic.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
package blockchains.iaas.uni.stuttgart.de.adaptation;

import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainIdNotFoundException;
import blockchains.iaas.uni.stuttgart.de.adaptation.interfaces.BlockchainAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.web3j.crypto.CipherException;


import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/********************************************************************************
* Copyright (c) 2018 Institute for the Architecture of Application System -
* Copyright (c) 2019 Institute for the Architecture of Application System -
* University of Stuttgart
* Author: Ghareeb Falazi
*
Expand All @@ -23,20 +9,32 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package blockchains.iaas.uni.stuttgart.de.adaptation;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import blockchains.iaas.uni.stuttgart.de.adaptation.interfaces.BlockchainAdapter;
import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainIdNotFoundException;
import blockchains.iaas.uni.stuttgart.de.gateways.GatewayManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AdapterManager {
private static final Logger log = LoggerFactory.getLogger(AdapterManager.class);
private static final String DEFAULT_ETHEREUM_ID = "eth-0";
private static final String DEFUALT_BICOIN_ID = "btc-0";
//private static final String DEFAULT_ETHEREUM_ID = "eth-0";
//private static final String DEFUALT_BICOIN_ID = "btc-0";
private BlockchainAdapterFactory factory = new BlockchainAdapterFactory();
private static AdapterManager instance = null;
private final Map<String, BlockchainAdapter> map = Collections.synchronizedMap(new HashMap<>());

private AdapterManager(){
private AdapterManager() {

}

public static AdapterManager getInstance(){
if(instance == null){
public static AdapterManager getInstance() {
if (instance == null) {
instance = new AdapterManager();
instance.initialize();
}
Expand All @@ -45,35 +43,26 @@ public static AdapterManager getInstance(){
}

public BlockchainAdapter getAdapter(String blockchainId) throws BlockchainIdNotFoundException {
if(map.containsKey(blockchainId)){
if (map.containsKey(blockchainId)) {
return map.get(blockchainId);
}else{
} else {
final String msg = String.format("blockchain-id <%s> does not exist!", blockchainId);
log.error(msg);
throw new BlockchainIdNotFoundException(msg);
}
}

private void initialize(){
private void initialize() {
try {
addDefaultEthereumNode(DEFAULT_ETHEREUM_ID);
addDefaultBitcoinNode(DEFUALT_BICOIN_ID);
createAdapters();
} catch (Exception e) {
//TODO better handling of errors
//error logs are produced at a lower level
e.printStackTrace();
}
}

private void addDefaultEthereumNode(String blockchainId) throws Exception {
map.put(blockchainId, factory.createBlockchainAdapter(NodeType.ETHEREUM));
}

private void addDefaultBitcoinNode(String blockchainId) throws Exception {
map.put(blockchainId, factory.createBlockchainAdapter(NodeType.BITCOIN));
private void createAdapters() throws Exception {
for(String id : GatewayManager.getInstance().getGateways().keySet()) {
map.put(id, factory.createBlockchainAdapter(id));
}
}

// TODO provide ability to add/remove/configure nodes externally
// TODO separate keystore management from node management
// TODO expose nodes as a REST resource
}
Loading

0 comments on commit 05ef324

Please sign in to comment.