Files
bft-crdt-experiment/side-node/src/bitcoin/driver.rs

45 lines
1.3 KiB
Rust
Raw Normal View History

use std::str::FromStr;
use bdk_wallet::bitcoin::{Address, Amount, Network};
use crate::bitcoin::clients;
/// Demonstrates the use of bdk with the Esplora client.
///
/// This is more complex than the bare `bdk` crate, but the esplora client works.
///
/// Also, it very handily works with the mutinynet.com esplora server, which is configured
/// with 30 second block times.
pub(crate) async fn run() -> Result<(), anyhow::Error> {
let mut wallet = clients::esplora::create_wallet("dave")?;
let _next_address = wallet.next_unused_address()?;
let balance = wallet.balance();
println!("Wallet balance before syncing: {} sats", balance.total());
wallet.sync().await?;
let balance = wallet.balance();
println!("Wallet balance after syncing: {} sats", balance.total());
let faucet_address = Address::from_str("mkHS9ne12qx9pS9VojpwU5xtRd4T7X7ZUt")?
.require_network(Network::Signet)?;
let send_amount = Amount::from_sat(5000);
if balance.total() < send_amount {
println!(
"Please send at least {} sats to the receiving address",
send_amount
);
std::process::exit(0);
}
let tx = wallet.build_send_tx(faucet_address, send_amount)?;
wallet.broadcast(&tx).await?;
println!("Tx broadcasted! Txid: {}", tx.compute_txid());
Ok(())
}