Skip to content

Commit

Permalink
refactor: Extract db file path
Browse files Browse the repository at this point in the history
  • Loading branch information
binarybaron committed Dec 4, 2024
1 parent 0bc3415 commit 85f6810
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions swap/src/bin/asb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ pub async fn main() -> Result<()> {
let seed =
Seed::from_file_or_generate(&config.data.dir).expect("Could not retrieve/initialize seed");

let db_file = config.data.dir.join("sqlite");

match cmd {
Command::Start { resume_only } => {
let db = open_db(config.data.dir.join("sqlite"), AccessMode::ReadWrite, None).await?;
let db = open_db(db_file, AccessMode::ReadWrite, None).await?;

// check and warn for duplicate rendezvous points
let mut rendezvous_addrs = config.network.rendezvous_point.clone();
Expand Down Expand Up @@ -234,7 +236,7 @@ pub async fn main() -> Result<()> {
event_loop.run().await;
}
Command::History => {
let db = open_db(config.data.dir.join("sqlite"), AccessMode::ReadOnly, None).await?;
let db = open_db(db_file, AccessMode::ReadOnly, None).await?;
let mut table = Table::new();

table.set_header(vec![
Expand Down Expand Up @@ -316,7 +318,7 @@ pub async fn main() -> Result<()> {
tracing::info!(%bitcoin_balance, %monero_balance, "Current balance");
}
Command::Cancel { swap_id } => {
let db = open_db(config.data.dir.join("sqlite"), AccessMode::ReadWrite, None).await?;
let db = open_db(db_file, AccessMode::ReadWrite, None).await?;

let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;

Expand All @@ -325,7 +327,7 @@ pub async fn main() -> Result<()> {
tracing::info!("Cancel transaction successfully published with id {}", txid);
}
Command::Refund { swap_id } => {
let db = open_db(config.data.dir.join("sqlite"), AccessMode::ReadWrite, None).await?;
let db = open_db(db_file, AccessMode::ReadWrite, None).await?;

let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;
let monero_wallet = init_monero_wallet(&config, env_config).await?;
Expand All @@ -341,7 +343,7 @@ pub async fn main() -> Result<()> {
tracing::info!("Monero successfully refunded");
}
Command::Punish { swap_id } => {
let db = open_db(config.data.dir.join("sqlite"), AccessMode::ReadWrite, None).await?;
let db = open_db(db_file, AccessMode::ReadWrite, None).await?;

let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;

Expand All @@ -350,7 +352,7 @@ pub async fn main() -> Result<()> {
tracing::info!("Punish transaction successfully published with id {}", txid);
}
Command::SafelyAbort { swap_id } => {
let db = open_db(config.data.dir.join("sqlite"), AccessMode::ReadWrite, None).await?;
let db = open_db(db_file, AccessMode::ReadWrite, None).await?;

safely_abort(swap_id, db).await?;

Expand All @@ -360,7 +362,7 @@ pub async fn main() -> Result<()> {
swap_id,
do_not_await_finality,
} => {
let db = open_db(config.data.dir.join("sqlite"), AccessMode::ReadWrite, None).await?;
let db = open_db(db_file, AccessMode::ReadWrite, None).await?;

let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;

Expand Down

0 comments on commit 85f6810

Please sign in to comment.