From 60de6a9219c520e5af0e5496754654eb2ab4287e Mon Sep 17 00:00:00 2001 From: rishflab Date: Fri, 26 Feb 2021 14:44:48 +1100 Subject: [PATCH] Remove intermediate structs in cli arguments These intermediate structs were creating unnecessary noise. The peer id and multiaddr fields are going to be removed in the future further reducing the need to have seperate structs for cancel, resume and refund. --- swap/src/bin/swap_cli.rs | 14 +++++++------- swap/src/cli/command.rs | 41 ++++++++++++++-------------------------- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/swap/src/bin/swap_cli.rs b/swap/src/bin/swap_cli.rs index 2fc2b64e..24f6b2b6 100644 --- a/swap/src/bin/swap_cli.rs +++ b/swap/src/bin/swap_cli.rs @@ -21,7 +21,7 @@ use swap::{ bitcoin, bitcoin::Amount, cli::{ - command::{Arguments, Cancel, Command, Refund, Resume}, + command::{Arguments, Command}, config::{read_config, Config}, }, database::Database, @@ -141,11 +141,11 @@ async fn main() -> Result<()> { // Print the table to stdout table.printstd(); } - Command::Resume(Resume::BuyXmr { + Command::Resume { swap_id, alice_peer_id, alice_addr, - }) => { + } => { let (bitcoin_wallet, monero_wallet) = init_wallets( config, bitcoin_network, @@ -171,12 +171,12 @@ async fn main() -> Result<()> { tokio::spawn(async move { event_loop.run().await }); bob::run(swap).await?; } - Command::Cancel(Cancel::BuyXmr { + Command::Cancel { swap_id, alice_peer_id, alice_addr, force, - }) => { + } => { // TODO: Optimization: Only init the Bitcoin wallet, Monero wallet unnecessary let (bitcoin_wallet, monero_wallet) = init_wallets( config, @@ -223,12 +223,12 @@ async fn main() -> Result<()> { } } } - Command::Refund(Refund::BuyXmr { + Command::Refund { swap_id, alice_peer_id, alice_addr, force, - }) => { + } => { let (bitcoin_wallet, monero_wallet) = init_wallets( config, bitcoin_network, diff --git a/swap/src/cli/command.rs b/swap/src/cli/command.rs index 7089949a..171349f8 100644 --- a/swap/src/cli/command.rs +++ b/swap/src/cli/command.rs @@ -26,37 +26,28 @@ pub enum Command { alice_peer_id: PeerId, #[structopt( - long = "connect-addr", - default_value = DEFAULT_ALICE_MULTIADDR + long = "connect-addr", + default_value = DEFAULT_ALICE_MULTIADDR )] alice_addr: Multiaddr, }, History, - Resume(Resume), - Cancel(Cancel), - Refund(Refund), -} - -#[derive(structopt::StructOpt, Debug)] -pub enum Resume { - BuyXmr { + Resume { #[structopt(long = "swap-id")] swap_id: Uuid, + // TODO: Remove Alice peer-id/address, it should be saved in the database when running swap + // and loaded from the database when running resume/cancel/refund #[structopt(long = "counterpart-peer-id", default_value = DEFAULT_ALICE_PEER_ID)] alice_peer_id: PeerId, #[structopt( - long = "counterpart-addr", - default_value = DEFAULT_ALICE_MULTIADDR + long = "counterpart-addr", + default_value = DEFAULT_ALICE_MULTIADDR )] alice_addr: Multiaddr, }, -} - -#[derive(structopt::StructOpt, Debug)] -pub enum Cancel { - BuyXmr { + Cancel { #[structopt(long = "swap-id")] swap_id: Uuid, @@ -66,19 +57,15 @@ pub enum Cancel { alice_peer_id: PeerId, #[structopt( - long = "counterpart-addr", - default_value = DEFAULT_ALICE_MULTIADDR - )] + long = "counterpart-addr", + default_value = DEFAULT_ALICE_MULTIADDR + )] alice_addr: Multiaddr, #[structopt(short, long)] force: bool, }, -} - -#[derive(structopt::StructOpt, Debug)] -pub enum Refund { - BuyXmr { + Refund { #[structopt(long = "swap-id")] swap_id: Uuid, @@ -88,8 +75,8 @@ pub enum Refund { alice_peer_id: PeerId, #[structopt( - long = "counterpart-addr", - default_value = DEFAULT_ALICE_MULTIADDR + long = "counterpart-addr", + default_value = DEFAULT_ALICE_MULTIADDR )] alice_addr: Multiaddr,