#container #addresses #lib #blocks #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 96/week @ 2024-01-05 76/week @ 2024-01-12 1/week @ 2024-01-19 112/week @ 2024-01-26 102/week @ 2024-02-02 275/week @ 2024-02-09 206/week @ 2024-02-16 182/week @ 2024-02-23 113/week @ 2024-03-01 114/week @ 2024-03-08 93/week @ 2024-03-15 81/week @ 2024-03-22 25/week @ 2024-03-29 120/week @ 2024-04-05 88/week @ 2024-04-12 46/week @ 2024-04-19

281 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–31MB
~426K SLoC