2021-03-03 23:46:54 +00:00
|
|
|
use anyhow::{Context, Result};
|
2021-03-04 00:28:58 +00:00
|
|
|
use libp2p::core::Multiaddr;
|
|
|
|
use libp2p::PeerId;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::str::FromStr;
|
2020-11-06 00:10:22 +00:00
|
|
|
use uuid::Uuid;
|
2020-10-29 03:45:45 +00:00
|
|
|
|
2021-02-26 04:24:13 +00:00
|
|
|
pub const DEFAULT_ALICE_MULTIADDR: &str = "/dns4/xmr-btc-asb.coblox.tech/tcp/9876";
|
|
|
|
pub const DEFAULT_ALICE_PEER_ID: &str = "12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi";
|
2021-02-25 01:05:07 +00:00
|
|
|
|
2021-03-05 05:10:45 +00:00
|
|
|
// Port is assumed to be stagenet standard port 38081
|
|
|
|
pub const DEFAULT_STAGENET_MONERO_DAEMON_HOST: &str = "monero-stagenet.exan.tech";
|
|
|
|
|
2020-12-15 10:26:02 +00:00
|
|
|
#[derive(structopt::StructOpt, Debug)]
|
2021-02-10 22:47:42 +00:00
|
|
|
pub struct Arguments {
|
2021-01-27 02:33:32 +00:00
|
|
|
#[structopt(
|
2021-02-11 04:21:34 +00:00
|
|
|
long = "config",
|
|
|
|
help = "Provide a custom path to the configuration file. The configuration file must be a toml file.",
|
2021-01-27 02:33:32 +00:00
|
|
|
parse(from_os_str)
|
|
|
|
)]
|
2021-02-11 04:21:34 +00:00
|
|
|
pub config: Option<PathBuf>,
|
2020-12-15 10:26:02 +00:00
|
|
|
|
2021-03-01 01:19:05 +00:00
|
|
|
#[structopt(long, help = "Activate debug logging.")]
|
|
|
|
pub debug: bool,
|
|
|
|
|
2020-12-15 10:26:02 +00:00
|
|
|
#[structopt(subcommand)]
|
2021-03-02 11:07:48 +00:00
|
|
|
pub cmd: Command,
|
2020-12-15 10:26:02 +00:00
|
|
|
}
|
|
|
|
|
2020-10-15 22:14:39 +00:00
|
|
|
#[derive(structopt::StructOpt, Debug)]
|
2021-01-05 03:08:36 +00:00
|
|
|
#[structopt(name = "xmr_btc-swap", about = "XMR BTC atomic swap")]
|
2020-12-15 10:26:02 +00:00
|
|
|
pub enum Command {
|
2020-12-04 05:27:17 +00:00
|
|
|
BuyXmr {
|
2021-03-05 05:00:52 +00:00
|
|
|
#[structopt(flatten)]
|
|
|
|
connect_params: ConnectParams,
|
2021-03-02 11:07:48 +00:00
|
|
|
|
2021-03-05 05:00:52 +00:00
|
|
|
#[structopt(flatten)]
|
|
|
|
monero_params: MoneroParams,
|
2020-10-29 03:45:45 +00:00
|
|
|
},
|
2020-11-05 05:55:30 +00:00
|
|
|
History,
|
2021-02-26 03:44:48 +00:00
|
|
|
Resume {
|
2020-12-21 03:43:44 +00:00
|
|
|
#[structopt(long = "swap-id")]
|
|
|
|
swap_id: Uuid,
|
|
|
|
|
2021-03-05 05:00:52 +00:00
|
|
|
#[structopt(flatten)]
|
|
|
|
connect_params: ConnectParams,
|
2020-12-18 06:39:04 +00:00
|
|
|
|
2021-03-05 05:00:52 +00:00
|
|
|
#[structopt(flatten)]
|
|
|
|
monero_params: MoneroParams,
|
2020-11-06 00:10:22 +00:00
|
|
|
},
|
2021-02-26 03:44:48 +00:00
|
|
|
Cancel {
|
2021-02-01 05:10:43 +00:00
|
|
|
#[structopt(long = "swap-id")]
|
2021-02-01 05:25:33 +00:00
|
|
|
swap_id: Uuid,
|
|
|
|
|
2021-02-01 11:32:54 +00:00
|
|
|
#[structopt(short, long)]
|
|
|
|
force: bool,
|
2021-02-01 05:25:33 +00:00
|
|
|
},
|
2021-02-26 03:44:48 +00:00
|
|
|
Refund {
|
2021-02-01 05:25:33 +00:00
|
|
|
#[structopt(long = "swap-id")]
|
2021-02-01 05:10:43 +00:00
|
|
|
swap_id: Uuid,
|
|
|
|
|
2021-02-01 11:32:54 +00:00
|
|
|
#[structopt(short, long)]
|
|
|
|
force: bool,
|
2021-02-01 05:10:43 +00:00
|
|
|
},
|
|
|
|
}
|
2021-02-28 23:53:43 +00:00
|
|
|
|
2021-03-05 05:00:52 +00:00
|
|
|
#[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,
|
2021-03-05 05:10:45 +00:00
|
|
|
|
|
|
|
#[structopt(
|
|
|
|
long = "monero-daemon-host",
|
|
|
|
default_value = DEFAULT_STAGENET_MONERO_DAEMON_HOST
|
|
|
|
)]
|
|
|
|
pub monero_daemon_host: String,
|
2021-03-05 05:00:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 23:46:54 +00:00
|
|
|
fn parse_monero_address(s: &str) -> Result<monero::Address> {
|
|
|
|
monero::Address::from_str(s).with_context(|| {
|
|
|
|
format!(
|
|
|
|
"Failed to parse {} as a monero address, please make sure it is a valid address",
|
|
|
|
s
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-03-01 00:00:30 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2021-03-02 11:07:48 +00:00
|
|
|
use crate::cli::command::{DEFAULT_ALICE_MULTIADDR, DEFAULT_ALICE_PEER_ID};
|
2021-03-04 00:28:58 +00:00
|
|
|
use libp2p::core::Multiaddr;
|
|
|
|
use libp2p::PeerId;
|
2021-03-01 00:00:30 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_default_alice_peer_id_success() {
|
|
|
|
DEFAULT_ALICE_PEER_ID
|
|
|
|
.parse::<PeerId>()
|
|
|
|
.expect("default alice peer id str is a valid PeerId");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_default_alice_multiaddr_success() {
|
|
|
|
DEFAULT_ALICE_MULTIADDR
|
|
|
|
.parse::<Multiaddr>()
|
|
|
|
.expect("default alice multiaddr str is a valid Multiaddr>");
|
|
|
|
}
|
|
|
|
}
|