diff --git a/swap/src/asb/command.rs b/swap/src/asb/command.rs index f23c4ebad..91223cff9 100644 --- a/swap/src/asb/command.rs +++ b/swap/src/asb/command.rs @@ -31,12 +31,12 @@ where env_config: env_config(testnet), cmd: Command::Start { resume_only }, }, - RawCommand::History => Arguments { + RawCommand::History { only_unfinished } => Arguments { testnet, json, config_path: config_path(config, testnet)?, env_config: env_config(testnet), - cmd: Command::History, + cmd: Command::History { only_unfinished }, }, RawCommand::Logs { logs_dir: dir_path, @@ -197,7 +197,9 @@ pub enum Command { Start { resume_only: bool, }, - History, + History { + only_unfinished: bool, + }, Config, Logs { logs_dir: Option, @@ -295,7 +297,10 @@ pub enum RawCommand { swap_id: Option, }, #[structopt(about = "Prints swap-id and the state of each swap ever made.")] - History, + History { + #[structopt(long = "only-unfinished", help = "Only print in progress swaps")] + only_unfinished: bool, + }, #[structopt(about = "Prints the current config")] Config, #[structopt(about = "Allows withdrawing BTC from the internal Bitcoin wallet.")] @@ -411,7 +416,9 @@ mod tests { json: false, config_path: default_mainnet_conf_path, env_config: mainnet_env_config, - cmd: Command::History, + cmd: Command::History { + only_unfinished: false, + }, }; let args = parse_args(raw_ars).unwrap(); assert_eq!(expected_args, args); @@ -586,7 +593,9 @@ mod tests { json: false, config_path: default_testnet_conf_path, env_config: testnet_env_config, - cmd: Command::History, + cmd: Command::History { + only_unfinished: false, + }, }; let args = parse_args(raw_ars).unwrap(); assert_eq!(expected_args, args); diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index f69cc4d3a..5d764809f 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -235,7 +235,7 @@ pub async fn main() -> Result<()> { event_loop.run().await; } - Command::History => { + Command::History { only_unfinished } => { let db = open_db(db_file, AccessMode::ReadOnly, None).await?; let mut table = Table::new(); @@ -253,6 +253,14 @@ pub async fn main() -> Result<()> { let all_swaps = db.all().await?; for (swap_id, state) in all_swaps { + let state: AliceState = state + .try_into() + .expect("Alice database only has Alice states"); + + if only_unfinished && is_complete(&state) { + continue; + } + match SwapDetails::from_db_state(swap_id.clone(), state, &db).await { Ok(details) => { if json { @@ -440,10 +448,9 @@ struct SwapDetails { impl SwapDetails { async fn from_db_state( swap_id: Uuid, - state: State, + latest_state: AliceState, db: &Arc, ) -> Result { - let latest_state: AliceState = state.try_into()?; let completed = is_complete(&latest_state); let all_states = db.get_states(swap_id.clone()).await?;