#bitcoin #harness #container #lib

bitcoin-harness

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

2 unstable releases

0.2.0 Dec 4, 2020
0.1.0 Nov 13, 2020

MIT license

42KB
1K SLoC

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};

# #[tokio::main]
# async fn main() {
let tc_client = testcontainers::clients::Cli::default();
let bitcoind = Bitcoind::new(&tc_client, "0.20.0").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};

# #[tokio::main]
# async fn main() {
let tc_client = testcontainers::clients::Cli::default();
let bitcoind = Bitcoind::new(&tc_client, "0.19.1").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, 3.0);
# }

Dependencies

~10–14MB
~274K SLoC

}_