Remove parameter duplication by introducing structs

This commit is contained in:
Daniel Karzel 2021-03-05 16:00:52 +11:00
parent c826a28911
commit f091402c7a
2 changed files with 43 additions and 29 deletions

View file

@ -28,36 +28,22 @@ pub struct Arguments {
#[structopt(name = "xmr_btc-swap", about = "XMR BTC atomic swap")]
pub enum Command {
BuyXmr {
#[structopt(long = "receive-address", parse(try_from_str = parse_monero_address))]
receive_monero_address: monero::Address,
#[structopt(flatten)]
connect_params: ConnectParams,
#[structopt(long = "connect-peer-id", default_value = DEFAULT_ALICE_PEER_ID)]
alice_peer_id: PeerId,
#[structopt(
long = "connect-addr",
default_value = DEFAULT_ALICE_MULTIADDR
)]
alice_addr: Multiaddr,
#[structopt(flatten)]
monero_params: MoneroParams,
},
History,
Resume {
#[structopt(long = "receive-address", parse(try_from_str = parse_monero_address))]
receive_monero_address: monero::Address,
#[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(flatten)]
connect_params: ConnectParams,
#[structopt(
long = "counterpart-addr",
default_value = DEFAULT_ALICE_MULTIADDR
)]
alice_addr: Multiaddr,
#[structopt(flatten)]
monero_params: MoneroParams,
},
Cancel {
#[structopt(long = "swap-id")]
@ -75,6 +61,24 @@ pub enum Command {
},
}
#[derive(structopt::StructOpt, Debug)]
pub struct ConnectParams {
#[structopt(long = "connect-peer-id", default_value = DEFAULT_ALICE_PEER_ID)]
pub alice_peer_id: PeerId,
#[structopt(
long = "connect-addr",
default_value = DEFAULT_ALICE_MULTIADDR
)]
pub alice_addr: Multiaddr,
}
#[derive(structopt::StructOpt, Debug)]
pub struct MoneroParams {
#[structopt(long = "receive-address", parse(try_from_str = parse_monero_address))]
pub receive_monero_address: monero::Address,
}
fn parse_monero_address(s: &str) -> Result<monero::Address> {
monero::Address::from_str(s).with_context(|| {
format!(