diff --git a/README.md b/README.md index 54c74dd..d5474dc 100644 --- a/README.md +++ b/README.md @@ -1 +1,32 @@ -# blockchain-access-layer-bitcoin-plugin \ No newline at end of file +# 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= -rpcport= -rpcuser= -rpcpassword= +``` \ No newline at end of file diff --git a/plugin.properties b/plugin.properties deleted file mode 100644 index fda6225..0000000 --- a/plugin.properties +++ /dev/null @@ -1,5 +0,0 @@ -plugin.id=bitcoin-plugin -plugin.class=blockchains.iaas.uni.stuttgart.plugin.bitcoin.BitcoinPlugin -plugin.version=1.0.0 -plugin.provider= -plugin.dependencies= \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2dcc823..258596f 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,33 @@ + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + true + + + blockchains.iaas.uni.stuttgart.de.plugin.bitcoin.BitcoinPlugin + bitcoin-plugin + 1.0.0 + 1.0.0 + + Bitcoin plugin + Akshay Patel + Apache License 2.0 + + + + + + + org.pf4j @@ -33,7 +60,7 @@ com.github.TIHBS blockchain-access-layer-api - 1.0.2 + 1.0.7 com.neemre.btcd-cli4j diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/plugin/bitcoin/BitcoinPlugin.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/plugin/bitcoin/BitcoinPlugin.java index d926981..fc6a2c8 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/plugin/bitcoin/BitcoinPlugin.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/plugin/bitcoin/BitcoinPlugin.java @@ -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; @@ -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 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(); @@ -69,14 +69,23 @@ public BlockchainAdapter getAdapter(Map 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 getConnectionProfileClass() { + return BitcoinConnectionProfile.class; + } + + @Override + public String getConnectionProfileNamedType() { + return "bitcoin"; + } + @Override public String getBlockChainId() { return "bitcoin";