Simplified driver code a bit

This commit is contained in:
Dave Hrycyszyn
2024-07-24 18:14:08 +01:00
parent 479abcbba2
commit 09c10b8d45
2 changed files with 16 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
use std::{collections::BTreeSet, fs, io::Write};
use std::fs;
use bdk::keys::bip39::Mnemonic;
use bdk_esplora::{
@@ -6,7 +6,7 @@ use bdk_esplora::{
EsploraAsyncExt,
};
use bdk_wallet::{
bitcoin::{Address, Amount, Network, Script},
bitcoin::{Address, Amount, Network},
chain::ConfirmationTimeHeightAnchor,
keys::{DerivableKey, ExtendedKey},
wallet::AddressInfo,

View File

@@ -13,29 +13,33 @@ pub(crate) async fn simple_transfer() -> Result<(), anyhow::Error> {
let _next_address = dave.next_unused_address()?;
let _ = dave.balance();
dave.sync().await?;
let dave_balance = dave.balance();
let sammy_address = sammy.next_unused_address()?.address;
let _ = dave.balance();
let _sammy = sammy.balance();
sammy.sync().await?;
let _sammy = sammy.balance();
let _ = sammy.balance();
let send_amount = Amount::from_sat(500);
ensure_enough_sats(dave, send_amount);
if dave_balance.total() < send_amount {
let sammy_address = sammy.next_unused_address()?.address;
let tx = dave.build_and_sign_send_tx(sammy_address, send_amount)?;
dave.broadcast(&tx).await?;
Ok(())
}
/// Exit if the wallet does not have enough sats to send.
fn ensure_enough_sats(wallet: EsploraWallet, send_amount: bitcoin::Amount) -> _ {
if wallet.balance().total() < send_amount {
tracing::error!(
"Please send at least {} sats to the receiving address. Exiting.",
send_amount
);
std::process::exit(0);
}
let tx = dave.build_and_sign_send_tx(sammy_address, send_amount)?;
dave.broadcast(&tx).await?;
Ok(())
}
pub(crate) async fn htlc() -> anyhow::Result<()> {