diff --git a/side-node/src/bitcoin/clients/esplora.rs b/side-node/src/bitcoin/client.rs similarity index 100% rename from side-node/src/bitcoin/clients/esplora.rs rename to side-node/src/bitcoin/client.rs diff --git a/side-node/src/bitcoin/clients/mod.rs b/side-node/src/bitcoin/clients/mod.rs deleted file mode 100644 index 9dba5bd..0000000 --- a/side-node/src/bitcoin/clients/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod esplora; diff --git a/side-node/src/bitcoin/driver.rs b/side-node/src/bitcoin/driver.rs index 4f1b183..02edfe3 100644 --- a/side-node/src/bitcoin/driver.rs +++ b/side-node/src/bitcoin/driver.rs @@ -5,7 +5,21 @@ use tracing_subscriber::filter::EnvFilter; use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::{fmt, layer::SubscriberExt}; -use super::clients::esplora::BitcoinClient; +use super::client::BitcoinClient; + +async fn setup() -> Result<(BitcoinClient, BitcoinClient), anyhow::Error> { + tracing_setup(); + let dave = BitcoinClient::create_wallet("dave", Network::Signet)?; + let sammy = BitcoinClient::create_wallet("sammy", Network::Signet)?; + + dave.sync()?; + let _ = dave.wallet.get_balance(); + + sammy.sync()?; + let _ = sammy.wallet.get_balance(); + + Ok((dave, sammy)) +} pub(crate) async fn simple_transfer() -> Result<(), anyhow::Error> { let (mut dave, sammy) = setup().await?; @@ -20,31 +34,6 @@ pub(crate) async fn simple_transfer() -> Result<(), anyhow::Error> { Ok(()) } -async fn setup() -> Result<(BitcoinClient, BitcoinClient), anyhow::Error> { - tracing_setup(); - 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(); - let _sammy = sammy.wallet.get_balance(); - sammy.sync()?; - let _ = sammy.wallet.get_balance(); - Ok((dave, sammy)) -} - -/// 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(()) -} - pub(crate) async fn htlc() -> anyhow::Result<()> { tracing::info!("starting htlc flow"); let (dave, sammy) = setup().await?; @@ -90,3 +79,15 @@ fn tracing_setup() { tracing::info!("Tracing initialized."); } + +/// 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(()) +} diff --git a/side-node/src/bitcoin/mod.rs b/side-node/src/bitcoin/mod.rs index 50092fa..df2e307 100644 --- a/side-node/src/bitcoin/mod.rs +++ b/side-node/src/bitcoin/mod.rs @@ -1,4 +1,4 @@ -pub mod clients; +pub mod client; pub mod driver; pub mod htlc; pub mod keys;