Parity Bitcoin

Parity Bitcoin (pbtc) is a historical Bitcoin client developed by Parity Technologies. Although it is no longer maintained, it serves as an example of implementing the Bitcoin protocol in Rust. This client offers various functionalities for interacting with the Bitcoin network and includes features such as a JSON-RPC interface and the ability to import existing bitcoind databases.

Key Features

Parity Bitcoin offers several key features:

  • Proof of Work: Implements the Bitcoin protocol using the Proof of Work consensus mechanism.
  • JSON-RPC Interface: Provides a comprehensive JSON-RPC API for interacting with the blockchain.
  • Multi-Fork Support: Allows users to follow different forks, including Bitcoin Core and Bitcoin Cash.
  • CLI Options: A variety of command-line options for configuring and running the client.

Development and Usage

Despite being unmaintained, the source code is still available for those interested in studying or building upon it. The client can be installed from source and includes detailed instructions for setting up the development environment.

Installing from Source

To install pbtc from source, you will need rustc and cargo. Follow these steps:

  1. Install Rust Toolchain:

    curl -sSf https://static.rust-lang.org/rustup.sh | sh
  2. Install C and C++ Compilers:

    sudo apt-get update
    sudo apt-get install build-essential
  3. Clone and Build pbtc:

    git clone https://github.com/paritytech/parity-bitcoin
    cd parity-bitcoin
    cargo build -p pbtc

The binary will be available at ./target/debug/pbtc or ./target/release/pbtc depending on the build mode.

Running Tests

Parity Bitcoin includes internal unit tests and external integration tests:

  • Unit Tests:

    cargo test --all
  • Integration Tests:

    git submodule update --init
    ./tools/regtests.sh

JSON-RPC Interface

The JSON-RPC interface is available on port :8332 for mainnet and :18332 for testnet. It provides various methods for interacting with the blockchain, such as adding nodes, querying block information, and managing transactions. Example requests can be made using curl:

  • Get Best Block Hash:
    curl -H 'content-type: application/json' --data-binary '{"jsonrpc": "2.0", "method": "getbestblockhash", "params": [], "id":1 }' localhost:8332

Logging

Detailed logging can be enabled by setting the RUST_LOG environment variable. For example, to enable info-level logs for the verification module:

RUST_LOG=verification=info ./target/release/pbtc --btc

Multiple modules can be logged simultaneously:

RUST_LOG=sync=trace,p2p=trace,verification=trace,db=trace ./target/release/pbtc --btc

Documentation

The internal documentation for pbtc can be built locally:

cd parity-bitcoin
./tools/doc.sh
open target/doc/pbtc/index.html

Although Parity Bitcoin is no longer actively maintained, it remains a valuable resource for understanding and implementing the Bitcoin protocol in Rust. Its comprehensive feature set and detailed documentation provide a solid foundation for developers interested in cryptocurrency and blockchain technologies.

Similar Projects