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

Development #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
# blockchain-access-layer-bitcoin-plugin
# blockchain-access-layer-bitcoin-plugin

**Notice:** the build requires a library (btcd-cli4j) to communicate with the Bitcoin Core
node. [The used library](https://github.com/pythonmax/btcd-cli4j) is forked from
an [unmaintained library](http://btcd-cli4j.neemre.com) to fix some issues resulting from changes in the recent versions
of the Bitcoin Core node. However, the used library is not available in a public Maven repository, so we had to provide
a local Maven repository which includes the required binaries. This repository is found [here](local-maven-repo).

### Running a Local Bitcoin Core Node

A Bitcoin Core node (or _bitcoind_ node) is used to access the Bitcoin network. For development purposes, it is advised
not to connect to the main Bitcoin network, but rather to one of the testnets.
(another, more difficult option would be to run a local private Bitcoin network). In order to connect a _bitcoind_ node
to [testnet3](https://en.bitcoin.it/wiki/Testnet) (one of Bitcoin's testnets), you can follow these steps:

1. [Install bitcoind](https://bitcoin.org/en/download):
this differs depending on your operating system. For the installation instructions on Ubuntu you can
follow [these steps](https://gist.github.com/rjmacarthy/b56497a81a6497bfabb1).
2. Configure _bitcoind_: This can be done by editing and using the [`bitcoin.conf`](app/src/main/resources/bitcoin.conf)
file when starting the bicoind daemon. The configuration allows external rpc-based communication with the node, and
instructs it to communicate with the testnet rather than the mainnet. Furthermore, it orders the node to build an
index on the blockchain that allows querying even historic transactions. Finally, it instructs the node to send
notifications to the BAL when it detects a new block or a transaction addressed to one of the Bitcoin wallet's
addresses. Syncing the whole testnet blockchain (which is done once only) takes about 1-4 hours (depending on the
hardware, the speed of the network connection, and the availability of peers).
3. Start the pre-configured _bitcoind_ node with the following command:```bitcoind -daemon```
4. Test connection: you can test your connection to a running _bitcoind_ node using the following command
(make sure to install bitcoin-cli (shipped with _bitcoind_) on the computer where you run this command):

```
bitcoin-cli -getinfo -rpcconnect=<ip address of the node> -rpcport=<port of the node> -rpcuser=<rpc username> -rpcpassword=<rpc password>
```
5 changes: 0 additions & 5 deletions plugin.properties

This file was deleted.

29 changes: 28 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,33 @@
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<Plugin-Class>blockchains.iaas.uni.stuttgart.de.plugin.bitcoin.BitcoinPlugin</Plugin-Class>
<Plugin-Id>bitcoin-plugin</Plugin-Id>
<Plugin-Version>1.0.0</Plugin-Version>
<Plugin-Requires>1.0.0</Plugin-Requires>
<Plugin-Dependencies></Plugin-Dependencies>
<Plugin-Description>Bitcoin plugin</Plugin-Description>
<Plugin-Provider>Akshay Patel</Plugin-Provider>
<Plugin-License>Apache License 2.0</Plugin-License>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.pf4j</groupId>
Expand All @@ -33,7 +60,7 @@
<dependency>
<groupId>com.github.TIHBS</groupId>
<artifactId>blockchain-access-layer-api</artifactId>
<version>1.0.2</version>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.neemre.btcd-cli4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

package blockchains.iaas.uni.stuttgart.de.plugin.bitcoin;

import blockchains.iaas.uni.stuttgart.de.api.IAdapterExtenstion;
import blockchains.iaas.uni.stuttgart.de.api.IAdapterExtension;
import blockchains.iaas.uni.stuttgart.de.api.connectionprofiles.AbstractConnectionProfile;
import blockchains.iaas.uni.stuttgart.de.api.interfaces.BlockchainAdapter;
import blockchains.iaas.uni.stuttgart.de.api.utils.PoWConfidenceCalculator;
import com.neemre.btcdcli4j.core.BitcoindException;
Expand Down Expand Up @@ -52,12 +53,11 @@ public void stop() {
}

@Extension
public static class BitcoinPluginImpl implements IAdapterExtenstion {
public static class BitcoinPluginImpl implements IAdapterExtension {

@Override
public BlockchainAdapter getAdapter(Map<String, String> parameters) {
// TODO: Create blockchains.iaas.uni.stuttgart.demo.BitcoinConnectionProfile object from parameters
BitcoinConnectionProfile gateway = new BitcoinConnectionProfile();
public BlockchainAdapter getAdapter(AbstractConnectionProfile abstractConnectionProfile) {
BitcoinConnectionProfile gateway = (BitcoinConnectionProfile) abstractConnectionProfile;
final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
final CloseableHttpClient httpProvider = HttpClients.custom().setConnectionManager(connManager).build();

Expand All @@ -69,14 +69,23 @@ public BlockchainAdapter getAdapter(Map<String, String> parameters) {
cCalc.setAdversaryRatio(gateway.getAdversaryVotingRatio());
result.setConfidenceCalculator(cCalc);
return result;
} catch (BitcoindException e) {
e.printStackTrace();
} catch (CommunicationException e) {
} catch (BitcoindException | CommunicationException e) {
e.printStackTrace();
}
return null;
}


@Override
public Class<? extends AbstractConnectionProfile> getConnectionProfileClass() {
return BitcoinConnectionProfile.class;
}

@Override
public String getConnectionProfileNamedType() {
return "bitcoin";
}

@Override
public String getBlockChainId() {
return "bitcoin";
Expand Down