#container #lib #start #addresses #blocks #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

#8 in #bitcoind

Download history 7/week @ 2024-09-20 1/week @ 2024-09-27

683 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–29MB
~393K SLoC