Cryptocurrency components for JVM & Android (JSON client & server support, services, DSL, CLI)
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bitcoinj-daemon Make daemons use WalletAppKit instead of PeerGroup (#47) Nov 5, 2018
bitcoinj-dsl Start work on 0.3.2-SNAPSHOT Oct 24, 2018
bitcoinj-dsljs Use java-library plugin for Java libraries Oct 8, 2018
bitcoinj-json Use java-library plugin for Java libraries Oct 8, 2018
bitcoinj-money Use java-library plugin for Java libraries Oct 8, 2018
bitcoinj-peerserver Use java-library plugin for Java libraries Oct 8, 2018
bitcoinj-proxy Use java-library plugin for Java libraries Oct 8, 2018
bitcoinj-rpcclient Fix integration test classpath in bitcoinj-rpcclient Oct 9, 2018
bitcoinj-server Make daemons use WalletAppKit instead of PeerGroup (#47) Nov 5, 2018
bitcoinj-spock Only depend on bitcoinj in submodules that directly use it Jul 6, 2018
cj-btc-cli-kt Use java-library plugin for Java libraries Oct 8, 2018
cj-btc-cli Go back to `compile` dependencies in cj-btc-cli for now Oct 9, 2018
cj-btc-jsonrpc-gvy Use java-library plugin for Java libraries Oct 8, 2018
cj-btc-jsonrpc Fewer requests, logs when waiting for Bitcoin to spin up Nov 6, 2018
cj-eth-jsonrpc-gvy Use java-library plugin for Java libraries Oct 8, 2018
cj-eth-jsonrpc Use java-library plugin for Java libraries Oct 8, 2018
cj-nmc-daemon Make daemons use WalletAppKit instead of PeerGroup (#47) Nov 5, 2018
cj-nmc-jsonrpc-gvy Use java-library plugin for Java libraries Oct 8, 2018
cj-nmc-jsonrpc Use java-library plugin for Java libraries Oct 8, 2018
consensusj-jsonrpc-gvy Use java-library plugin for Java libraries Oct 8, 2018
consensusj-jsonrpc Fewer requests, logs when waiting for Bitcoin to spin up Nov 6, 2018
doc Begin work on 0.3.1-SNAPSHOT Jul 31, 2018
gradle Update to Gradle 10.4.2 Oct 5, 2018
.gitignore Refactor to separate ETH & NMC jsonrpc and jsonrpc-gvy Jul 21, 2018
.gitlab-ci.yml Set Ubuntu locale to en_US and UTF-8 in GitLab CI Sep 24, 2018
.travis.yml Enable Gradle Build Scans on Travis CI Jun 5, 2018
CHANGELOG.adoc Start work on 0.3.2-SNAPSHOT Oct 24, 2018
LICENSE Add license, update README, fix jar name Aug 4, 2015
README.adoc Prepare Release 0.3.1 Oct 24, 2018
build.gradle Fix integration test classpath in bitcoinj-rpcclient Oct 9, 2018
gradle.properties Start work on 0.3.2-SNAPSHOT Oct 24, 2018
gradlew Bump to Gradle (wrapper) 4.1 Aug 18, 2017
gradlew.bat Upgrade Gradle (wrapper) to 3.5 May 6, 2017
settings.gradle Refactor to separate ETH & NMC jsonrpc and jsonrpc-gvy Jul 21, 2018

README.adoc

ConsensusJ (formerly bitcoinj-addons)

Build Status pipeline download

Modular cryptocurrency libraries for Java, JVM languages, and Android. Including:

  • A Java JSON-RPC client that serves as a base class for any cryptocurrency platform that uses JSON-RPC for communication.

  • A Groovy JSON-RPC client that can use dynamic methods for scripting, experimentation and functional tests of any JSON-RPC server.

  • A JSON-RPC Java client for the Bitcoin Core API with strong, static types.

  • JSON library using Jackson to convert between Bitcoin types and JSON

  • Spring and Guice-compatible Bitcoin server components for server-side JSON-RPC.

  • bitcoinj-proxy - A high-performance, non-blocking Ratpack server for proxying access to bitcoind or building Bitcoin-based microservices.

  • bitcoinj-daemon - A Spring Boot-based framework for a Java-based implementation of bitcoind.

  • bitcoinj-peerserver - A Spring Boot-based web application that connects to the Bitcoin P2P network and streams events to a browser using the STOMP protocol over WebSocket.

  • Bitcoin currency and exchange implementations for JavaMoney.

  • bitcoinj-cli - a command line tool and supporting libraries for accessing the JSON-RPC API.

  • A Groovy-language Domain Specific Language for scripting and testing with bitcoinj

  • Functional tests of bitcoind (and bitcoinj-daemon) JSON-RPC services, that run in regression test mode.

⚠️
Do not use this software with your private keys without doing a rigorous audit of the code first. (Feedback welcome.)
⚠️
The API is not final and prior to a 1.0 release may change without warning. Most of the API changes are fairly manageable though, and we try to deprecate first.

This project is a mono-repo with a large number of submodules/components that are published as independent binary libraries. Since it is easy to pull in just the modules you need via Maven coordinates, this allows you to manage your transitive dependencies and build small, tight applications and servers. Most of these components are fairly new, but all are useful and ready for pull requests.

Overview

Binaries download

Although the API is changing, binary releases are available on Bintray. You can download JARs or use the provided Maven coordinates to link to them directly from your pom.xml or build.gradle.

API Documentation

We have published preliminary JavaDoc to our Github pages site.

Continuous Integration

ConsensusJ is used by OmniJ and is tested by the Omni Foundation Continuous Integration Server. There are also Travis CI and GitLab CI builds.

  • Omni Foundation Jenkins build: consensusj job (note: self-signed SSL certificate)

  • Travis CI build: Build Status

  • GitLab CI build: pipeline

Requirements

Now that Android 7 and later support Java 8, we’re trying to make Java 8 the baseline. But ConsensusJ-Namecoin is cool, so we have to convince them to upgrade to Java 8.

ConsensusJ Modules

We are in the process of refactoring all modules into the new org.consensusj namespace. As part of this process, once all the packages in a module are under org.consensusj and there are no split packages, we are assigning JPMS module names via the "Automatic Module" mechanism. This results in a consistent package structure, easier usage by Java 9+, and a smooth migration to JPMS module descriptors.

The new modules also more clearly separate Java from Groovy, so the core Java modules have zero dependencies on Groovy JARs.

Table 1. ConsensusJ Modules
Name Min JDK JPMS module Description

cj-btc-cli

8

not yet

Command-line JSON-RPC client for Bitcoin

cj-btc-cli-kt

8

not yet

Command-line JSON-RPC client for Bitcoin in Kotlin

cj-btc-jsonrpc

7

not yet

Java JSON-RPC Bitcoin client

cj-btc-jsonrpc-gvy

8

not yet

Groovy JSON-RPC Bitcoin client (dynamic RPC methods)

cj-eth-jsonrpc

8

not yet

Java JSON-RPC Ethereum client (proof-of-concept)

cj-eth-jsonrpc-gvy

8

not yet

Groovy JSON-RPC Ethereum client (dynamic RPC methods)

cj-nmc-daemon

8

not yet

Namecoin daemon work-in-progress

cj-nmc-jsonrpc

8

not yet

Java JSON-RPC Namecoin client (proof-of-concept)

cj-nmc-jsonrpc-gvy

8

not yet

Groovy JSON-RPC Namecoin client (dynamic RPC methods)

consensusj-jsonrpc

7

org.consensusj.jsonrpc

Java JSON-RPC client

consensusj-jsonrpc-gvy

8

org.consensusj.jsonrpc.groovy

Groovy JSON-RPC client (dynamic RPC methods)

Modules

See the table below for an overview of the modules in the old com.msgilligan namespace. The JDK column indicates the version of Java required. The Grooviness column describes the use of the Groovy Programming Language within that module.

Table 2. Legacy Modules
Name JDK Grooviness Description

bitcoinj-rpcclient

7

Optional + tests

Bitcoin JSON-RPC integration tests

bitcoinj-json

7

Tests only (TBD)

Jackson serializers, deserializers & POJOs for Bitcoin JSON-RPC

bitcoinj-server

7

Tests only (TBD)

Service objects used by the server apps

bitcoinj-proxy

8

Tests only (TBD)

Ratpack-based server for proxying bitcoind and/or building microservices.

bitcoinj-daemon

8

Tests only (TBD)

JSON-RPC bitcoin server daemon — to replace bitcoind someday ;)

bitcoinj-peerserver

8

Tests only (TBD)

Peer and transaction info over HTTP + WebSocket/STOMP. JSON-RPC server, too.

bitcoinj-money

8

Tests only (TBD)

JavaMoney currency and exchange support. Adapter to use XChange Exchange implementations as JavaMoney `ExchangeRateProvider`s.

bitcoinj-dsl

7

Uses Groovy

Groovy DSL support.

bitcoinj-spock

8

Spock is a Groovy DSL for unit tests

Spock tests of bitcoinj classes.

consensusj-jsonrpc

Java implementation of a JSON-RPC client. RPCClient can be subclassed or called directly using the send() method and Object parameters.

consensusj-jsonrpc-gvy

Dynamic RPC methods are implemented via the DynamicRPCFallback Groovy trait. DynamicRPCClient can be used to talk to any JSON-RPC server using standard Java types and Jackson JSON conversion.

cj-btc-jsonrpc

Java Bitcoin JSON-RPC client and supporting types, both bitcoinj types and POJOs for Bitcoin Core JSON.

If the RPC procedure takes a Bitcoin address as parameter, then the Java method will take an org.bitcoinj.core.Address. If the RPC returns a transaction, the Java method will return an org.bitcoinj.core.Transaction.

See the JavaDoc for BitcoinClient to see the methods implemented.

cj-btc-jsonrpc-gvy

Subclass of Bitcoin JSON-RPC client with fallback to dynamic methods (using DynamicRPCFallback). This is useful when new methods are added to the server/protocol and static methods and types haven’t been written for them yet.

cj-btc-cli: An Bitcoin RPC command-line client

An alternative implementation of bitcoin-cli in Java. If converted to a fat jar, it is executable with java -jar. The command:

java -jar cj-btc-cli-0.3.1.jar -rpcport=8080 getblockcount

will output:

Connecting to: http://127.0.0.1:8080/
0
ℹ️
Only a few RPCs are currently supported. Pull requests welcome.

For help type:

java -jar bitcoinj-cli-0.3.1.jar -?

or read the manual page.

bitcoinj-rpcclient: A Bitcoin JSON-RPC client using bitcoinj types

Most of the previous functionality of this module has been moved to the new org.consensusj modules. What remains is:

  • Bitcoin Core integration test framework and tests (Regression Tests using Spock)

  • A Namecoin (NMC) JSON-RPC Client

  • An Ethereum (ETH) JSON-RPC Client

The remaining classes will be refactored into 3 new org.consensusj modules.

Sample Spock Integration Tests

These sample Spock "feature tests" show the RPC client in action and are from the file BitcoinSpec.groovy.

    def "Use RegTest mode to generate a block upon request"() {
        given: "a certain starting height"
        def startHeight = blockCount

        when: "we generate 1 new block"
        generateBlock()

        then: "the block height is 1 higher"
        blockCount == startHeight + 1
    }

    def "When we send an amount to a newly created address, it arrives"() {
        given: "A new, empty Bitcoin address"
        def destinationAddress = getNewAddress()

        when: "we send it testAmount (from coins mined in RegTest mode)"
        sendToAddress(destinationAddress, testAmount, "comment", "comment-to")

        and: "we generate 1 new block"
        generateBlock()

        then: "the new address has a balance of testAmount"
        testAmount == getReceivedByAddress(destinationAddress)
    }

bitcoinj-json

Jackson serializers, deserializers & POJOs used to create and parse JSON by both client and server implementations of Bitcoin JSON-RPC.

bitcoinj-server

Service objects that power the Daemon and PeerServer. Some objects, such as PeerGroupService, rely solely on javax.annotation and javax.inject for configuration and can be wired with either Spring or (in theory) Guice. The current focus is on Spring Boot, but we’re hoping to build a Ratpack server in the future.

bitcoinj-daemon

A starting point for building a complete bitcoind equivalent using bitcoinj. Currently serves a very small subset of the Bitcoin RPC API (Bitcoin uses JSON-RPC.)

Uses a PeerGroup to power the limited RPCs. Will use a BlockStore. (Pull requests welcome.)

Built as a fat, executable jar, so it can be run with java -jar.

bitcoinj-peerserver

PeerServer is a bitcoinj-powered Spring Boot application that provides the following functions:

  1. A Bitcoin JSON-RPC service at http://[host]:[port]/bitcoinrpc

    1. This is hard to connect to using bitcoin-cli as it expects the RPCs to be accessible at the root path ('/'), but you can use the Java RPC client or CLI tool to talk to it.

    2. There may be issues with the security configuration on this URL. We’re currently investigating.

  2. A STOMP protocol WebSocket service that live-streams pending Bitcoin transactions from the P2P network.

    1. The page at /peers.html lists connected peers and streams Transactions from the P2P network.

    2. You must login using username: admin, password: admin to view this page.

    3. The `peers.html' page is currently unstyled HTML.

No bitcoind is required. The server uses a bitcoinj PeerGroup to connect directly to the Bitcoin network. I’m considering renaming it to PeerGroupServer for this reason. The JAR is entirely self-contained and can be run on any system with Java 8 with the java -jar peerserver-0.3.1.jar command.

bitcoinj-proxy

A Ratpack-based proxy server that can proxy JSON-RPC commands to a connected bitcoind (or Omni Core) server. It can also be used as a starting point for JSON-RPC interoperable microservices.

bitcoinj-money

JavaMoney (also known as JSR 354) is the new Java Standard for advanced and flexible currency handling on the Java platform.

JSR 354 provides a portable and extendible framework for handling of Money & Currency. The API models monetary amounts and currencies in a platform independent and portable way, including well defined extension points.
— JavaMoney Web Site

Support for virtual currencies is one of the key design goals in the specification. The bitcoinj-money module will allow Bitcoin to be used by standard Java APIs in the same ways as fiat currencies.

The JavaMoney Reference Implementation (aka "Moneta") contains implementations of ExchangeRateProvider for ECB (European Central Bank) and IMF (International Monetary Fund). There is also U.S. FRB (Federal Reserve Bank) and Yahoo Finance ExchangeRateProvider in the JavaMoney financial library add-on module.

bitcoinj-money contains BitcoinCurrencyProvider which will add "BTC" as a standard currency code to any applications including the bitcoinj-money JAR in its classpath. and "BTC" will be available to your applications.

The bitcoinj-money module also includes an adapter class BaseXChangeExchangeRateProvider that along with a 1-line subclass adapts implementations of the Exchange interface in the popular and complete XChange library to be used by JavaMoney-compatible applications.

bitcoinj-dsl

Groovy DSL support to write things like:

assert 1.btc == 100_000_000.satoshi
and
assert 100.satoshi == Coin.MICROCOIN

bitcoinj-spock

Spock tests of bitcoinj classes. Initial focus is learning and documentation, not test coverage.

Building and Running

Before running ./gradlew wrapper script you must have JDK 8 installed and your JAVA_HOME set correctly. For example:

export JAVA_HOME=`/usr/libexec/java_home -v1.8`
ℹ️
The first time you run the build all dependency JARS will be downloaded.

Full Build

./gradlew build

Build CLI tool

To build the CLI executable jar:

./gradlew :bitcoinj-cli:shadowJar

To run it and display a list of command line options:

java -jar bitcoinj-cli/build/libs/cj-btc-cli-0.3.1.jar -?

Build and Run PeerServer Locally Using Gradle

  1. Build and Run with Gradle Wrapper

    ./gradlew :bitcoinj-peerserver:bootRun
ℹ️
This will connect to the Bitcoin P2P network

Build an Executable JAR

./gradlew :bitcoinj-peerserver:assemble

The JAR will be built at build/libs/peerserver-0.3.1.jar and can be run with:

java -jar bitcoinj-peerserver/build/libs/peerserver-0.3.1.jar