A library for working with Bitcoin
Go to file
Andreas Schildbach 47660f6418 build.gradle: migrate from protobuf-java to protobuf-javalite
This commit contains rather hard to review diffs to the protobuf test datasets in .txt format.
To aid the review, this Python script can be used to convert the data from the old to the new
format:

```
import sys

file = open(sys.argv[1])
outfile = open(sys.argv[1] + ".lite", "w")
line = file.readline()
lines = []

def sortAndPrint(group, removeLastLB=False, removeFirstLB=False):
    group.sort()
    if removeFirstLB and group[0] == "\n":
        group.remove("\n")
    for i in range(len(group)):
        if i == len(group) - 1 and removeLastLB:
            group[i] = group[i].rstrip()
        print(group[i], end="", file=outfile)

def sign32neg(value):
    if 0x80000000 <= value <= 0xFFFFFFFF:
        value &= 0x7FFFFFFF
        value = int(value)
        value = ~value
        value ^= 0x7FFFFFFF
    return value

def processPath(path):
    parts = path.rstrip().split(":")
    number = int(parts[1].lstrip())
    if number >= 0x80000000:
        number = sign32neg(number)
    return parts[0] + ": " + str(number) + "\n"

groupcount = 0
while len(line) > 0:
    if line.startswith("type:"):
        if len(lines):
            sortAndPrint(lines, removeFirstLB=groupcount==0)
            groupcount += 1
        lines.clear()
        lines.append(line)
    elif line.find("deterministic_key {") != -1:
        structure = line
        innerlines = []
        line = file.readline()
        while not line.startswith('}'):
            if line.find("path") != -1:  # preserve order of paths
                pathlines = processPath(line)
                line = file.readline()
                if line.startswith('}'):
                    innerlines.append(pathlines)
                    continue
                while line.find("path") != -1:
                    pathlines += processPath(line)
                    line = file.readline()
                innerlines.append(pathlines)
                if line.startswith('}'):
                    continue
            if line.startswith("  sigsRequiredToSpend"):
                line = line.replace("sigsRequiredToSpend", "sigs_required_to_spend")
            innerlines.append(line)
            line = file.readline()
        innerlines.sort()
        for l in innerlines:
            structure += l
        structure += line.rstrip() + "\n"
        lines.append(structure)
    elif line.find("path") != -1:  # preserve order of paths
        accountpathlines = processPath(line)
        line = file.readline()
        while line.find("path") != -1:
            accountpathlines += processPath(line)
            line = file.readline()
        lines.append(accountpathlines)
        lines.append(line)
    else:
        lines.append(line)
    line = file.readline()
print(file=outfile)
sortAndPrint(lines, removeLastLB=True)
file.close()
outfile.close()
```
2021-09-25 11:00:42 +02:00
.github GitHub Actions: add special case for Gradle 4.10/JDK11/Ubuntu 2021-09-23 21:37:30 +02:00
core build.gradle: migrate from protobuf-java to protobuf-javalite 2021-09-25 11:00:42 +02:00
designdocs Design doc for contexts 2015-03-21 17:23:21 +01:00
examples build.gradle: Update SLF4J to 1.7.32. 2021-09-17 11:51:11 +02:00
tools BasicKeyChain, DeterministicKeyChain, WalletTool: use only protobuf API that is available also on protobuf-lite 2021-09-24 11:33:06 +02:00
wallettemplate walletfx: Initialize scene earlier in MainController 2021-09-23 09:25:36 -07:00
.gitattributes Add a logo. 2013-03-01 13:59:48 +01:00
.gitignore Git-ignore Gradle wrapper files. 2018-07-31 10:37:39 +02:00
.gitlab-ci.yml .gitlab-ci.yml: Use Debian Bullseye 2021-08-31 18:19:46 +02:00
AUTHORS Update AUTHORS from git. 2019-02-15 04:15:48 +01:00
build.gradle build.gradle: Choose Gradle Protobuf Plugin by Gradle version 2021-09-01 01:36:46 +02:00
COPYING Initial checkin of BitCoinJ 2011-03-07 10:17:10 +00:00
README.md README.md: Update again now that we support Gradle 7 2021-09-01 08:33:16 +02:00
settings.gradle Require Gradle 4.4 for building. 2019-04-18 16:28:04 +02:00

Github Build Status GitLab Build Status Coverage Status

Visit our IRC channel

Welcome to bitcoinj

The bitcoinj library is a Java implementation of the Bitcoin protocol, which allows it to maintain a wallet and send/receive transactions without needing a local copy of Bitcoin Core. It comes with full documentation and some example apps showing how to use it.

Technologies

  • Java 7+ and Gradle 4.4+ for the core module
  • Java 8+ and Gradle 4.4+ for tools and examples
  • Java 11+ and Gradle 4.10+ for the JavaFX-based wallettemplate
  • Gradle - for building the project
  • Google Protocol Buffers - for use with serialization and hardware communications

Getting started

To get started, it is best to have the latest JDK and Gradle installed. The HEAD of the master branch contains the latest development code and various production releases are provided on feature branches.

Building from the command line

Official builds are currently using with JDK 8, even though the core module is compatible with JDK 7 and later.

To perform a full build (including JavaDocs and unit/integration tests) use JDK 8+

gradle clean build

If you are running JDK 11 or later and Gradle 4.10 or later, the build will automatically include the JavaFX-based wallettemplate module. The outputs are under the build directory.

To perform a full build without unit/integration tests use:

gradle clean assemble

Building from an IDE

Alternatively, just import the project using your IDE. IntelliJ has Gradle integration built-in and has a free Community Edition. Simply use File | New | Project from Existing Sources and locate the build.gradle in the root of the cloned project source tree.

Building and Using the Wallet Tool

The bitcoinj tools subproject includes a command-line Wallet Tool (wallet-tool) that can be used to create and manage bitcoinj-based wallets (both the HD keychain and SPV blockchain state.) Using wallet-tool on Bitcoin's test net is a great way to learn about Bitcoin and bitcoinj.

To build an executable shell script that runs the command-line Wallet Tool, use:

gradle bitcoinj-tools:installDist

You can now run the wallet-tool without parameters to get help on its operation:

./tools/build/install/wallet-tool/bin/wallet-tool

To create a test net wallet file in ~/bitcoinj/bitcoinj-test.wallet, you would use:

mkdir ~/bitcoinj
./tools/build/install/wallet-tool/bin/wallet-tool --net=TEST --wallet=$HOME/bitcoinj/bitcoinj-test.wallet create

To sync the newly created wallet in ~/bitcoinj/bitcoinj-test.wallet with the test net, you would use:

./tools/build/install/wallet-tool/bin/wallet-tool --net=TEST --wallet=$HOME/bitcoinj/bitcoinj-test.wallet sync

To dump the state of the wallet in ~/bitcoinj/bitcoinj-test.wallet with the test net, you would use:

./tools/build/install/wallet-tool/bin/wallet-tool --net=TEST --wallet=$HOME/bitcoinj/bitcoinj-test.wallet dump

Note: These instructions are for macOS/Linux, for Windows use the tools/build/install/wallet-tool/bin/wallet-tool.bat batch file with the equivalent Windows command-line commands and options.

Example applications

These are found in the examples module.

Where next?

Now you are ready to follow the tutorial.

Testing a SNAPSHOT build

Building apps with official releases of bitcoinj is covered in the tutorial.

If you want to develop or test your app with a Jitpack-powered build of the latest master or release-0.15 branch of bitcoinj follow the dynamically-generated instructions for that branch by following the correct link.