Refactored bitcoin driver programs
This commit is contained in:
28
side-node/src/bitcoin/driver/simple_transfer.rs
Normal file
28
side-node/src/bitcoin/driver/simple_transfer.rs
Normal 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(())
|
||||
}
|
||||
Reference in New Issue
Block a user