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> {
2024-06-25 14:58:53 +01:00
let mut dave = clients::esplora::create_wallet("dave")?;
2024-06-25 14:58:53 +01:00
let _next_address = dave.next_unused_address()?;
2024-06-25 14:58:53 +01:00
let balance = dave.balance();
println!("Wallet balance before syncing: {} sats", balance.total());
2024-06-25 14:58:53 +01:00
dave.sync().await?;
2024-06-25 14:58:53 +01:00
let balance = dave.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);
}
2024-06-25 14:58:53 +01:00
let tx = dave.build_send_tx(faucet_address, send_amount)?;
dave.broadcast(&tx).await?;
println!("Tx broadcasted! Txid: {}", tx.compute_txid());
Ok(())
}