Refactored bitcoin driver programs

This commit is contained in:
Dave Hrycyszyn
2024-07-26 15:27:32 +01:00
parent 0edfbfaab1
commit dcf4761940
8 changed files with 119 additions and 119 deletions

View File

@@ -0,0 +1,28 @@
use crate::bitcoin::client::BitcoinClient;
use crate::bitcoin::driver;
use bdk::wallet::AddressIndex;
pub async fn run() -> Result<(), anyhow::Error> {
let (mut dave, sammy) = driver::setup().await?;
let send_amount = 500;
let _ = ensure_enough_sats(&dave, send_amount);
let sammy_address = sammy.wallet.get_address(AddressIndex::New)?;
let tx = dave.build_and_sign_send_tx(sammy_address, send_amount)?;
dave.broadcast(&tx)?;
Ok(())
}
/// Exit if the wallet does not have enough sats to send.
fn ensure_enough_sats(wallet: &BitcoinClient, send_amount: u64) -> anyhow::Result<()> {
if wallet.wallet.get_balance()?.get_total() < send_amount {
tracing::error!(
"Please send at least {} sats to the receiving address. Exiting.",
send_amount
);
std::process::exit(0);
}
Ok(())
}