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.
This commit is contained in:
rishflab 2021-02-26 14:44:48 +11:00
parent 9a32f7d405
commit 60de6a9219
2 changed files with 33 additions and 46 deletions

View File

@ -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,

View File

@ -26,37 +26,13 @@ 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 {
#[structopt(long = "swap-id")]
swap_id: Uuid,
#[structopt(long = "counterpart-peer-id", default_value = DEFAULT_ALICE_PEER_ID)]
alice_peer_id: PeerId,
#[structopt(
long = "counterpart-addr",
default_value = DEFAULT_ALICE_MULTIADDR
)]
alice_addr: Multiaddr,
},
}
#[derive(structopt::StructOpt, Debug)]
pub enum Cancel {
BuyXmr {
Resume {
#[structopt(long = "swap-id")]
swap_id: Uuid,
@ -66,19 +42,12 @@ 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 {
Cancel {
#[structopt(long = "swap-id")]
swap_id: Uuid,
@ -88,8 +57,26 @@ 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,
#[structopt(short, long)]
force: bool,
},
Refund {
#[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
)]
alice_addr: Multiaddr,