|
1 | 1 | # bdk-bitcoind-client |
2 | 2 |
|
3 | | -A minimal Bitcoin Core RPC client designed specifically for the Bitcoin Dev Kit (BDK). It retrieves blockchain data from `bitcoind` over JSON-RPC and supports multiple versions of Bitcoin Core (v28.0 through v30.0+). |
| 3 | +<p> |
| 4 | + <!-- <a href="https://crates.io/crates/bdk-bitcoind-client"><img src="https://img.shields.io/crates/v/bdk-bitcoind-client.svg"/></a> --> |
| 5 | + <!-- <a href="https://docs.rs/bdk-bitcoind-client"><img src="https://img.shields.io/badge/docs.rs-bdk-bitcoind-client-orange"/></a> --> |
| 6 | + <a href="https://blog.rust-lang.org/2025/02/20/Rust-1.85.0/"><img src="https://img.shields.io/badge/rustc-1.85.0%2B-orange.svg"/></a> |
| 7 | + <a href="https://github.com/bitcoindevkit/bdk-bitcoind-client/blob/master/LICENSE"><img src="https://img.shields.io/badge/License-MIT%2FApache--2.0-red.svg"/></a> |
| 8 | + <a href="https://github.com/bitcoindevkit/bdk-bitcoind-client/actions/workflows/cont_integration.yml"><img src="https://github.com/bitcoindevkit/bdk-bitcoind-client/actions/workflows/cont_integration.yml/badge.svg"></a> |
| 9 | +</p> |
4 | 10 |
|
5 | | -### Features |
| 11 | +A minimal `bitcoind` RPC client custom built for [BDK](https://github.com/bitcoindevkit/bdk). |
6 | 12 |
|
7 | | -- _Version Pinning_: Explicit support for different Bitcoin Core RPC schemas via feature flags (28_0, 29_0, 30_0). |
8 | | -- _Minimal Dependencies_: Uses bitreq_http for a lightweight HTTP transport by default. |
9 | | -- _Wallet-Agnostic_: Focused on blockchain data emission (blocks, headers, mempool) rather than wallet management. |
10 | | -- _Robust Error Handling_: Specific error variants for RPC failures, deserialization issues, and transport timeouts. |
| 13 | +## Features |
11 | 14 |
|
12 | | -### Installation |
| 15 | +- **Multiple Bitcoin Core Version Support**: implements support for multiple Bitcoin Core versions in the backend: |
| 16 | + - Bitcoin Core v30.0 |
| 17 | + - Bitcoin Core v29.0 |
| 18 | + - Bitcoin Core v28.0 |
| 19 | + |
| 20 | +- **Minimal Dependencies**: by default, the minimal `bitreq_http` is used as the HTTP transport. |
| 21 | + |
| 22 | +- **Separation of Concerns**: focused on emitting generic data structures, such as blocks, |
| 23 | +headers and mempool. Interpreting this data is left to wallets that use this crate as a chain-source. |
| 24 | + |
| 25 | +- **Robust Error Handling**: implements specifc error variants for RPC, deserialization and transport errors. |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +Add this to your `Cargo.toml` manifest to use this crate with |
| 30 | +the latest Bitcoin Core version (currently v30.0) as the backend: |
13 | 31 |
|
14 | | -Add this to your `Cargo.toml`: |
15 | 32 | ```toml |
16 | | -# For the latest Bitcoin Core (v30.0+) |
17 | 33 | bdk-bitcoind-client = { version = "0.1.0" } |
| 34 | +``` |
18 | 35 |
|
19 | | -# OR for older nodes (e.g., v28.x) |
| 36 | +Alternatively, add this to your `Cargo.toml` manifest to use this crate |
| 37 | +with a specific Bitcoin Core version as the backend (v28.0 or v29.0): |
| 38 | + |
| 39 | +```toml |
| 40 | +# Bitcoin Core v29.0 |
| 41 | +bdk-bitcoind-client = { version = "0.1.0", default-features = false, features = ["29_0"] } |
| 42 | + |
| 43 | +# Bitcoin Core v28.0 |
20 | 44 | bdk-bitcoind-client = { version = "0.1.0", default-features = false, features = ["28_0"] } |
21 | 45 | ``` |
22 | 46 |
|
23 | | -### Quick Start |
| 47 | +## Quick Start |
24 | 48 |
|
25 | 49 | ```rust |
26 | 50 | use bdk_bitcoind_client::{Auth, Client}; |
27 | 51 | use std::path::PathBuf; |
28 | 52 | fn main() -> anyhow::Result<()> { |
29 | | - // 1. Setup authentication (Cookie file is recommended for security) |
| 53 | + // Define how to authenticate with `bitcoind` (Cookie File or User/Pass) |
30 | 54 | let auth = Auth::CookieFile(PathBuf::from("/path/to/regtest/.cookie")); |
| 55 | + let auth = Auth::UserPass("user".to_string(), "pass".to_string()); |
31 | 56 |
|
32 | | - // 2. Initialize the client |
| 57 | + // Instantiate a JSON-RCP `Client` |
33 | 58 | let client = Client::with_auth("http://127.0.0.1:18443", auth)?; |
34 | 59 |
|
35 | | - // 3. Query the blockchain |
| 60 | + // Perform blockchain queries to `bitcoind` using the `Client` |
36 | 61 | let block_count = client.get_block_count()?; |
37 | 62 | let best_hash = client.get_block_hash(block_count)?; |
38 | | - |
39 | | - // 4. Get verbose headers (handles schema differences automatically) |
40 | 63 | let header = client.get_block_header_verbose(&best_hash)?; |
41 | | - |
| 64 | + |
| 65 | + println!("Block Count: {}", block_count); |
| 66 | + println!("Best Block Hash: {}", best_hash); |
42 | 67 | println!("Chain tip: {} at height {}", header.hash, header.height); |
43 | 68 |
|
44 | 69 | Ok(()) |
45 | 70 | } |
46 | 71 | ``` |
47 | 72 |
|
48 | | -### Version Compatibility |
| 73 | +## Bitcoin Core Version Compatibility |
49 | 74 |
|
50 | | -Bitcoin Core often changes its JSON-RPC response fields (e.g., adding the target field in `v29/v30`). This client manages these differences through compile-time features. |
| 75 | +Bitcoin Core often changes its JSON-RPC schema, such as the addition of the `target` |
| 76 | +and `difficulty` fields in the `getmininginfo` RPC on Bitcoin Core v29.0 and newer. |
51 | 77 |
|
52 | | -| Feature | Bitcoin Core Version | Notes | |
53 | | -| ----------------- | --------------------- | -------------------------------------------- | |
54 | | -| 30_0 (default) | v30.x and newer | Supports latest target and difficulty fields.| |
55 | | -| 29_0 | v29.x | Aligned with v29 schema. | |
56 | | -| 28_0 | v28.x and older | Omits newer fields | |
| 78 | +This crate manages this via compile-time feature flags: |
57 | 79 |
|
| 80 | +| Feature Flag | Bitcoin Core Version | Notes | |
| 81 | +| ---------------- | -------------------- | ------------------------------------------------------------ | |
| 82 | +| `30_0` (default) | v30.x | | |
| 83 | +| `29_0` | v29.x | Supports `target` and `difficulty` fields on `getmininginfo` | |
| 84 | +| `28_0` | v28.x and older | Omits newer fields | |
58 | 85 |
|
59 | | -### Development and Testing |
60 | | -To run tests against a specific Bitcoin Core version, use the corresponding feature flag: |
61 | 86 |
|
62 | | -``` |
63 | | -cargo test --no-default-features --features 28_0 |
64 | | -``` |
| 87 | +## Developing |
65 | 88 |
|
66 | | -### Minimum Supported Rust Version (MSRV) |
| 89 | +This project uses [`cargo-rbmt`](https://github.com/rust-bitcoin/rust-bitcoin-maintainer-tools/tree/master/cargo-rbmt) |
| 90 | +to manage everything related to `cargo`, such as formatting, linting, testing and CI. To install it, run: |
67 | 91 |
|
68 | | -The library maintain a MSRV of 1.85.0. |
| 92 | +```console |
| 93 | +~$ cargo install cargo-rbmt |
| 94 | +``` |
| 95 | + |
| 96 | +A `justfile` is provided for convenient command-running. You must have |
| 97 | +[`just`](https://github.com/casey/just?tab=readme-ov-file#installation) installed. |
| 98 | + |
| 99 | +Run `just` to see available commands: |
| 100 | + |
| 101 | +```console |
| 102 | +> bdk-bitcoind-client |
| 103 | +> An experimental `bitcoind` RPC client for BDK |
| 104 | + |
| 105 | +Available recipes: |
| 106 | + build # Build the `bdk-bitcoind-client` [alias: b] |
| 107 | + check # Check code formatting, compilation, and linting [alias: c] |
| 108 | + check-features # Check that all feature combinations compile [alias: cf] |
| 109 | + check-sigs # Checks whether all commits in this branch are PGP-signed [alias: cs] |
| 110 | + doc # Generate documentation [alias: d] |
| 111 | + doc-open # Generate and open documetation [alias: do] |
| 112 | + fmt # Format code [alias: f] |
| 113 | + lock # Regenerate `Cargo-recent.lock` and `Cargo-minimal.lock` [alias: l] |
| 114 | + msrv # Verify the library builds with the MSRV toolchain (1.85.0) [alias: m] |
| 115 | + pre-push # Run pre-push suite: lock, check-sigs, fmt, check, test, and msrv [alias: p] |
| 116 | + test # Run all tests on the workspace with all features [alias: t] |
| 117 | + test-version VERSION # Run tests against a specific Bitcoin Core version: 30_0, 29_0, 28_0 [alias: tv] |
| 118 | +``` |
69 | 119 |
|
70 | | -## Just |
| 120 | +## Minimum Supported Rust Version (MSRV) |
71 | 121 |
|
72 | | -This project has a [`justfile`](/justfile) for easy command running. You must have [`just`](https://github.com/casey/just) installed. |
| 122 | +This library should compile with any combination of features on Rust 1.85.0. |
73 | 123 |
|
74 | | -To see a list of available recipes: `just` |
| 124 | +To build with the MSRV toolchain, copy `Cargo-minimal.lock` to `Cargo.lock`. |
75 | 125 |
|
76 | 126 | ## License |
77 | 127 |
|
|
0 commit comments