Extracted the Esplora wallet into a struct

This commit is contained in:
Dave Hrycyszyn
2024-06-25 14:58:13 +01:00
parent 2474f5186d
commit 35deb4a75c
2 changed files with 106 additions and 83 deletions

View File

@@ -11,14 +11,14 @@ use crate::bitcoin::clients;
/// 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, mut db) = clients::esplora::create_wallet("dave")?;
let mut wallet = clients::esplora::create_wallet("dave")?;
let _next_address = clients::esplora::next_unused_address(&mut wallet, &mut db)?;
let _next_address = wallet.next_unused_address()?;
let balance = wallet.balance();
println!("Wallet balance before syncing: {} sats", balance.total());
let client = clients::esplora::sync(&mut wallet, &mut db).await?;
wallet.sync().await?;
let balance = wallet.balance();
println!("Wallet balance after syncing: {} sats", balance.total());
@@ -35,8 +35,9 @@ pub(crate) async fn run() -> Result<(), anyhow::Error> {
std::process::exit(0);
}
let tx = clients::esplora::build_send_tx(wallet, faucet_address, send_amount)?;
client.broadcast(&tx).await?;
let tx = wallet.build_send_tx(faucet_address, send_amount)?;
wallet.broadcast(&tx).await?;
println!("Tx broadcasted! Txid: {}", tx.compute_txid());
Ok(())