From aa812d410168d557446f512e13d30404fd12f9c7 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 25 Jul 2024 20:11:08 +0100 Subject: [PATCH] Renamed EsploraWallet to BitcoinClient --- side-node/src/bitcoin/clients/esplora.rs | 14 +++++++++----- side-node/src/bitcoin/driver.rs | 11 ++++++----- side-node/src/bitcoin/htlc.rs | 6 ++++-- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/side-node/src/bitcoin/clients/esplora.rs b/side-node/src/bitcoin/clients/esplora.rs index b25dd28..ee870a2 100644 --- a/side-node/src/bitcoin/clients/esplora.rs +++ b/side-node/src/bitcoin/clients/esplora.rs @@ -12,20 +12,24 @@ use bdk::{ use crate::utils; -/// A wallet that uses the Esplora client to interact with the Bitcoin network. -pub struct EsploraWallet { +/// A client that uses Esplora to interact with the Bitcoin network. +pub struct BitcoinClient { pub(crate) blockchain: bdk::blockchain::EsploraBlockchain, name: String, pub(crate) wallet: Wallet, } -impl EsploraWallet { +impl BitcoinClient { pub(crate) fn sync(&self) -> anyhow::Result<()> { self.wallet.sync(&self.blockchain, SyncOptions::default())?; Ok(()) } pub(crate) fn broadcast(&self, tx: &Transaction) -> anyhow::Result<()> { + tracing::info!( + "broadcasting transaction, output will be at https://mutinynet.com/tx/{}", + tx.txid() + ); let _ = self.blockchain.broadcast(&tx); Ok(()) } @@ -71,7 +75,7 @@ impl EsploraWallet { } /// Creates a Bitcoin descriptor wallet with the mnemonic in the given user directory. - pub(crate) fn create_wallet(name: &str, network: Network) -> anyhow::Result { + pub(crate) fn create_wallet(name: &str, network: Network) -> anyhow::Result { let keys_dir = utils::home(name); let mnemonic_path = crate::utils::side_paths(keys_dir).1; // TODO: this tuple stinks @@ -99,7 +103,7 @@ impl EsploraWallet { let blockchain = EsploraBlockchain::new("https://mutinynet.com/api", 20); - let esplora = EsploraWallet { + let esplora = BitcoinClient { name: name.to_string(), wallet, blockchain, diff --git a/side-node/src/bitcoin/driver.rs b/side-node/src/bitcoin/driver.rs index 2635179..4f1b183 100644 --- a/side-node/src/bitcoin/driver.rs +++ b/side-node/src/bitcoin/driver.rs @@ -5,7 +5,7 @@ use tracing_subscriber::filter::EnvFilter; use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::{fmt, layer::SubscriberExt}; -use super::clients::esplora::EsploraWallet; +use super::clients::esplora::BitcoinClient; pub(crate) async fn simple_transfer() -> Result<(), anyhow::Error> { let (mut dave, sammy) = setup().await?; @@ -20,10 +20,10 @@ pub(crate) async fn simple_transfer() -> Result<(), anyhow::Error> { Ok(()) } -async fn setup() -> Result<(EsploraWallet, EsploraWallet), anyhow::Error> { +async fn setup() -> Result<(BitcoinClient, BitcoinClient), anyhow::Error> { tracing_setup(); - let dave = EsploraWallet::create_wallet("dave", Network::Signet)?; - let sammy = EsploraWallet::create_wallet("sammy", Network::Signet)?; + let dave = BitcoinClient::create_wallet("dave", Network::Signet)?; + let sammy = BitcoinClient::create_wallet("sammy", Network::Signet)?; let _ = dave.wallet.get_balance(); dave.sync()?; let _ = dave.wallet.get_balance(); @@ -34,7 +34,7 @@ async fn setup() -> Result<(EsploraWallet, EsploraWallet), anyhow::Error> { } /// Exit if the wallet does not have enough sats to send. -fn ensure_enough_sats(wallet: &EsploraWallet, send_amount: u64) -> anyhow::Result<()> { +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.", @@ -46,6 +46,7 @@ fn ensure_enough_sats(wallet: &EsploraWallet, send_amount: u64) -> anyhow::Resul } pub(crate) async fn htlc() -> anyhow::Result<()> { + tracing::info!("starting htlc flow"); let (dave, sammy) = setup().await?; // format a new commitment transaction like in Lightning diff --git a/side-node/src/bitcoin/htlc.rs b/side-node/src/bitcoin/htlc.rs index 8f18f0b..39eba46 100644 --- a/side-node/src/bitcoin/htlc.rs +++ b/side-node/src/bitcoin/htlc.rs @@ -1,7 +1,9 @@ use std::str::FromStr; -use bdk::miniscript::{descriptor::Wsh, policy::Concrete}; -use bitcoin::Address; +use bdk::{ + bitcoin::Address, + miniscript::{descriptor::Wsh, policy::Concrete}, +}; /// A hash time locked contract between two parties. ///