From 04b49d7117da1418646d5bd21af47b13a120c6a5 Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Wed, 31 Mar 2021 17:03:51 +1100 Subject: [PATCH] Add command to print Bitcoin and Monero balance --- swap/src/asb/command.rs | 1 + swap/src/bin/asb.rs | 40 +++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/swap/src/asb/command.rs b/swap/src/asb/command.rs index c4b87fa0..eb0ea13b 100644 --- a/swap/src/asb/command.rs +++ b/swap/src/asb/command.rs @@ -38,6 +38,7 @@ pub enum Command { #[structopt(long = "address", help = "The address to receive the Bitcoin.")] address: Address, }, + Balance, } fn parse_btc(s: &str) -> Result { diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index 30c82a5b..637e659f 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -78,6 +78,20 @@ async fn main() -> Result<()> { let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; let monero_wallet = init_monero_wallet(&config, env_config).await?; + let bitcoin_balance = bitcoin_wallet.balance().await?; + info!("Bitcoin balance: {}", bitcoin_balance); + + let monero_balance = monero_wallet.get_balance().await?; + if monero_balance == Amount::ZERO { + let deposit_address = monero_wallet.get_main_address(); + warn!( + "The Monero balance is 0, make sure to deposit funds at: {}", + deposit_address + ) + } else { + info!("Monero balance: {}", monero_balance); + } + let kraken_rate_updates = kraken::connect()?; let mut swarm = swarm::new::(&seed)?; @@ -144,6 +158,15 @@ async fn main() -> Result<()> { bitcoin_wallet.broadcast(signed_tx, "withdraw").await?; } + Command::Balance => { + let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; + let monero_wallet = init_monero_wallet(&config, env_config).await?; + + let bitcoin_balance = bitcoin_wallet.balance().await?; + let monero_balance = monero_wallet.get_balance().await?; + + tracing::info!("Current balance: {}, {}", bitcoin_balance, monero_balance); + } }; Ok(()) @@ -167,12 +190,6 @@ async fn init_bitcoin_wallet( wallet.sync().await?; - let balance = wallet.balance().await?; - info!( - "Connection to Bitcoin wallet succeeded, balance: {}", - balance - ); - Ok(wallet) } @@ -187,16 +204,5 @@ async fn init_monero_wallet( ) .await?; - let balance = wallet.get_balance().await?; - if balance == Amount::ZERO { - let deposit_address = wallet.get_main_address(); - warn!( - "The Monero balance is 0, make sure to deposit funds at: {}", - deposit_address - ) - } else { - info!("Monero balance: {}", balance); - } - Ok(wallet) }