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 dave = clients::esplora::create_wallet("dave", Network::Signet)?; let mut sammy = clients::esplora::create_wallet("sammy", Network::Signet)?; let _next_address = dave.next_unused_address()?; let dave_balance = dave.balance(); println!( "Dave wallet balance before syncing: {} sats", dave_balance.total() ); dave.sync().await?; let dave_balance = dave.balance(); println!("Wallet balance after syncing: {} sats", dave_balance); let sammy_address = sammy.next_unused_address()?.address; println!("Sammy's address: {}", sammy_address); let sammy_balance = sammy.balance(); println!( "Sammy wallet balance before syncing: {} sats", sammy_balance ); sammy.sync().await?; let sammy_balance = sammy.balance(); println!("Sammy wallet balance after syncing: {} sats", sammy_balance); let send_amount = Amount::from_sat(500); if dave_balance.total() < send_amount { println!( "Please send at least {} sats to the receiving address", send_amount ); std::process::exit(0); } let tx = dave.build_send_tx(sammy_address, send_amount)?; dave.broadcast(&tx).await?; Ok(()) }