Remove multiple occurrences of db initialisation

This commit is contained in:
rishflab 2021-09-22 18:02:27 +10:00
parent 13075c1064
commit 80a30109e8

View file

@ -54,6 +54,9 @@ async fn main() -> Result<()> {
}
};
let db = SledDatabase::open(data_dir.join("database").as_path())
.context("Failed to open database")?;
match cmd {
Command::BuyXmr {
seller,
@ -67,8 +70,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")?;
@ -140,9 +141,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"]);
@ -217,8 +215,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")?;
@ -279,8 +275,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")?;
@ -302,8 +296,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")?;