#container #blocks #lib #addresses #start #generate #bitcoind

bitcoin-harness

A simple lib to start a bitcoind container, generate blocks and fund addresses

4 releases

0.2.2 Nov 9, 2022
0.2.1 Sep 19, 2022
0.2.0 Dec 4, 2020
0.1.0 Nov 13, 2020

#6 in #bitcoind

Download history 157/week @ 2023-12-05 909/week @ 2023-12-12 327/week @ 2023-12-19 61/week @ 2023-12-26 145/week @ 2024-01-02 155/week @ 2024-01-09 2/week @ 2024-01-16 93/week @ 2024-01-23 97/week @ 2024-01-30 174/week @ 2024-02-06 228/week @ 2024-02-13 176/week @ 2024-02-20 213/week @ 2024-02-27 99/week @ 2024-03-05 77/week @ 2024-03-12 89/week @ 2024-03-19

484 downloads per month

MIT license

30KB
649 lines

bitcoin-harness-rs

A simple lib to start a bitcoind container, generate blocks and funds addresses.


lib.rs:

bitcoin-harness

A simple lib to start a bitcoind container, generate blocks and funds addresses. Note: It uses tokio.

Examples

Just connect to bitcoind and get the network

use bitcoin_harness::{Bitcoind, bitcoind_rpc, Client};

let tc_client = testcontainers::clients::Cli::default();
let bitcoind = Bitcoind::new(&tc_client).unwrap();
let client = Client::new(bitcoind.node_url);
let network = client.network().await.unwrap();

assert_eq!(network, bitcoin::Network::Regtest)

Create a wallet, fund it and get a UTXO

use bitcoin_harness::{Bitcoind, bitcoind_rpc, Client, Wallet};

let tc_client = testcontainers::clients::Cli::default();
let bitcoind = Bitcoind::new(&tc_client).unwrap();
let client = Client::new(bitcoind.node_url.clone());

bitcoind.init(5).await.unwrap();

let wallet = Wallet::new("my_wallet", bitcoind.node_url.clone()).await.unwrap();
let address = wallet.new_address().await.unwrap();
let amount = bitcoin::Amount::from_btc(3.0).unwrap();

bitcoind.mint(address, amount).await.unwrap();

let balance = wallet.balance().await.unwrap();

assert_eq!(balance, amount);

let utxos = wallet.list_unspent().await.unwrap();

assert_eq!(utxos.get(0).unwrap().amount, amount);

Dependencies

~16–30MB
~426K SLoC