From a738c9df8a15415819b979cbbcc2d8b4e84885e7 Mon Sep 17 00:00:00 2001 From: rishflab Date: Wed, 22 Sep 2021 18:02:27 +1000 Subject: [PATCH] Remove multiple occurrences of db initialisation --- swap/src/bin/swap.rs | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/swap/src/bin/swap.rs b/swap/src/bin/swap.rs index 2c40aa7c..443bddcf 100644 --- a/swap/src/bin/swap.rs +++ b/swap/src/bin/swap.rs @@ -54,6 +54,12 @@ async fn main() -> Result<()> { } }; + let db = Arc::new( + SledDatabase::open(data_dir.join("database").as_path()) + .await + .context("Failed to open database")?, + ); + match cmd { Command::BuyXmr { seller, @@ -67,11 +73,6 @@ async fn main() -> Result<()> { let swap_id = Uuid::new_v4(); cli::tracing::init(debug, json, data_dir.join("logs"), Some(swap_id))?; - let db = Arc::new( - SledDatabase::open(data_dir.join("database").as_path()) - .await - .context("Failed to open database")?, - ); let seed = Seed::from_file_or_generate(data_dir.as_path()) .context("Failed to read in seed file")?; @@ -143,10 +144,6 @@ async fn main() -> Result<()> { } } Command::History => { - let db = SledDatabase::open(data_dir.join("database").as_path()) - .await - .context("Failed to open database")?; - let mut table = Table::new(); table.set_header(vec!["SWAP ID", "STATE"]); @@ -221,11 +218,6 @@ async fn main() -> Result<()> { tor_socks5_port, } => { cli::tracing::init(debug, json, data_dir.join("logs"), Some(swap_id))?; - let db = Arc::new( - SledDatabase::open(data_dir.join("database").as_path()) - .await - .context("Failed to open database")?, - ); let seed = Seed::from_file_or_generate(data_dir.as_path()) .context("Failed to read in seed file")?; @@ -287,11 +279,6 @@ async fn main() -> Result<()> { bitcoin_target_block, } => { cli::tracing::init(debug, json, data_dir.join("logs"), Some(swap_id))?; - let db = Arc::new( - SledDatabase::open(data_dir.join("database").as_path()) - .await - .context("Failed to open database")?, - ); let seed = Seed::from_file_or_generate(data_dir.as_path()) .context("Failed to read in seed file")?; @@ -313,11 +300,6 @@ async fn main() -> Result<()> { bitcoin_target_block, } => { cli::tracing::init(debug, json, data_dir.join("logs"), Some(swap_id))?; - let db = Arc::new( - SledDatabase::open(data_dir.join("database").as_path()) - .await - .context("Failed to open database")?, - ); let seed = Seed::from_file_or_generate(data_dir.as_path()) .context("Failed to read in seed file")?;