A {regtest} bitcoin node runner πββοΈ
This crate makes it simple to run regtest bitcoind,
utreexod, and electrs
instances from Rust code, useful in integration test contexts.
Heavily inspired by the bitcoind
and electrsd crates.
| Implementation | Version | Feature Flag | Default Feature |
|---|---|---|---|
bitcoind |
v31.0 |
bitcoind |
Yes |
electrs |
v0.11.1 |
electrs |
No |
utreexod |
v0.6.0 |
utreexod |
Yes |
Binaries are downloaded automatically at build time: see build.rs.
use halfin::connect;
use halfin::bitcoind::BitcoinD;
// Use a downloaded binary
let bitcoind_alpha = BitcoinD::new().unwrap();
// Use a local binary
let bin_path = PathBuf::from_str("/usr/local/bin/bitcoind").unwrap();
let bitcoind_beta = BitcoinD::from_bin(&bin_path).unwrap();
// Connect peers
connect(&bitcoind_alpha, &bitcoind_beta).unwrap()
// Mine blocks
bitcoind_alpha.generate(100).unwrap();
assert_eq!(bitcoind_alpha.get_chain_tip().unwrap(), 100);
// Wait for a node to catch up with the other
wait_for_height(&bitcoind_beta, 100).unwrap();
assert_eq!(bitcoind_beta.get_chain_tip().unwrap(), 100);use halfin::bitcoind::BitcoinD;
use halfin::electrsd::ElectrsD;
let bitcoind = BitcoinD::new().unwrap();
bitcoind.generate(100).unwrap();
let electrs = ElectrsD::new(&bitcoind).unwrap();
electrs.wait_until_caught_up(&bitcoind, None).unwrap();use halfin::utreexod::UtreexoD;
// Use a downloaded binary
let utreexod = UtreexoD::new().unwrap();
// Mine blocks
utreexod.generate(100).unwrap();
assert_eq!(utreexod.get_chain_tip().unwrap(), 100);
// Perform a raw RPC call
let res = utreexod.call("uptime", &[]).unwrap();This project uses just for command running, and
cargo-rbmt
to manage everything related to cargo, such as formatting, linting, testing and CI. To install them, run:
~$ cargo install just
~$ cargo install cargo-rbmtA justfile is provided for convenience. Run just to see available commands:
~$ just
> halfin
> A regtest runner for `bitcoind` and `utreexod`
Available recipes:
audit # Run `cargo audit` on all lockfiles and prune ignored advisories [alias: a]
build # Build `halfin` [alias: b]
check # Check code formatting, compilation, and linting [alias: c]
check-sigs # Checks whether all commits in this branch are signed [alias: cs]
doc # Generate documentation [alias: d]
doc-open # Generate and open documentation [alias: do]
fmt # Format code [alias: f]
lock # Regenerate Cargo-recent.lock and Cargo-minimal.lock [alias: l]
pre-push # Run pre-push checks [alias: p]
shellcheck # Run ShellCheck [alias: sc]
test # Run tests with relevant toolchain and lockfile combinations [alias: t]
toolchains # Install and/or Update `cargo-rbmt` and Stable and Nightly toolchains
zizmor # Run Zizmor Static Analysis [alias: z]This library should compile with any combination of features on Rust 1.85.0.
To build with the MSRV toolchain, copy Cargo-minimal.lock to Cargo.lock.
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
