Skip to content

Commit

Permalink
feat: --only-unfinished flaf
Browse files Browse the repository at this point in the history
  • Loading branch information
binarybaron committed Dec 4, 2024
1 parent c5f2961 commit 4ddd73d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
21 changes: 15 additions & 6 deletions swap/src/asb/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -197,7 +197,9 @@ pub enum Command {
Start {
resume_only: bool,
},
History,
History {
only_unfinished: bool,
},
Config,
Logs {
logs_dir: Option<PathBuf>,
Expand Down Expand Up @@ -295,7 +297,10 @@ pub enum RawCommand {
swap_id: Option<Uuid>,
},
#[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.")]
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 10 additions & 3 deletions swap/src/bin/asb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 {
Expand Down Expand Up @@ -440,10 +448,9 @@ struct SwapDetails {
impl SwapDetails {
async fn from_db_state(
swap_id: Uuid,
state: State,
latest_state: AliceState,
db: &Arc<dyn Database + Send + Sync>,
) -> Result<Self> {
let latest_state: AliceState = state.try_into()?;
let completed = is_complete(&latest_state);

let all_states = db.get_states(swap_id.clone()).await?;
Expand Down

0 comments on commit 4ddd73d

Please sign in to comment.