2021-01-21 00:20:57 +00:00
|
|
|
use crate::{bitcoin, monero};
|
2020-12-18 06:39:04 +00:00
|
|
|
use libp2p::{core::Multiaddr, PeerId};
|
2021-01-27 02:33:32 +00:00
|
|
|
use std::path::PathBuf;
|
2020-11-06 00:10:22 +00:00
|
|
|
use uuid::Uuid;
|
2020-10-29 03:45:45 +00:00
|
|
|
|
2020-12-15 10:26:02 +00:00
|
|
|
#[derive(structopt::StructOpt, Debug)]
|
|
|
|
pub struct Options {
|
2021-01-27 02:33:32 +00:00
|
|
|
#[structopt(
|
|
|
|
long = "data-dir",
|
|
|
|
help = "Provide a custom path to the data directory.",
|
|
|
|
parse(from_os_str)
|
|
|
|
)]
|
|
|
|
pub data_dir: Option<PathBuf>,
|
2020-12-15 10:26:02 +00:00
|
|
|
|
|
|
|
#[structopt(subcommand)]
|
|
|
|
pub cmd: Command,
|
|
|
|
}
|
|
|
|
|
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
|
|
|
SellXmr {
|
2021-01-07 00:45:55 +00:00
|
|
|
#[structopt(long = "p2p-address", default_value = "/ip4/0.0.0.0/tcp/9876")]
|
2020-10-29 11:18:59 +00:00
|
|
|
listen_addr: Multiaddr,
|
2020-10-15 22:14:39 +00:00
|
|
|
|
2020-12-21 06:52:52 +00:00
|
|
|
#[structopt(long = "send-xmr", help = "Monero amount as floating point nr without denomination (e.g. 125.1)", parse(try_from_str = parse_xmr))]
|
2021-01-05 03:08:36 +00:00
|
|
|
send_monero: monero::Amount,
|
2020-10-26 05:55:53 +00:00
|
|
|
|
2020-12-21 06:52:52 +00:00
|
|
|
#[structopt(long = "receive-btc", help = "Bitcoin amount as floating point nr without denomination (e.g. 1.25)", parse(try_from_str = parse_btc))]
|
2021-01-07 23:41:25 +00:00
|
|
|
receive_bitcoin: bitcoin::Amount,
|
2021-01-27 02:33:32 +00:00
|
|
|
|
|
|
|
#[structopt(flatten)]
|
|
|
|
config: Config,
|
2020-12-04 05:27:17 +00:00
|
|
|
},
|
|
|
|
BuyXmr {
|
2020-12-21 06:52:52 +00:00
|
|
|
#[structopt(long = "connect-peer-id")]
|
2020-12-18 06:39:04 +00:00
|
|
|
alice_peer_id: PeerId,
|
|
|
|
|
2020-12-21 06:52:52 +00:00
|
|
|
#[structopt(long = "connect-addr")]
|
2020-10-29 11:18:59 +00:00
|
|
|
alice_addr: Multiaddr,
|
|
|
|
|
2020-12-21 06:52:52 +00:00
|
|
|
#[structopt(long = "send-btc", help = "Bitcoin amount as floating point nr without denomination (e.g. 1.25)", parse(try_from_str = parse_btc))]
|
2021-01-07 23:41:25 +00:00
|
|
|
send_bitcoin: bitcoin::Amount,
|
2020-12-04 05:27:17 +00:00
|
|
|
|
2020-12-21 06:52:52 +00:00
|
|
|
#[structopt(long = "receive-xmr", help = "Monero amount as floating point nr without denomination (e.g. 125.1)", parse(try_from_str = parse_xmr))]
|
2021-01-05 03:08:36 +00:00
|
|
|
receive_monero: monero::Amount,
|
2021-01-27 02:33:32 +00:00
|
|
|
|
|
|
|
#[structopt(flatten)]
|
|
|
|
config: Config,
|
2020-10-29 03:45:45 +00:00
|
|
|
},
|
2020-11-05 05:55:30 +00:00
|
|
|
History,
|
2020-12-21 03:43:44 +00:00
|
|
|
Resume(Resume),
|
2021-02-01 05:10:43 +00:00
|
|
|
Cancel(Cancel),
|
2021-02-01 05:25:33 +00:00
|
|
|
Refund(Refund),
|
2020-12-21 03:43:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(structopt::StructOpt, Debug)]
|
|
|
|
pub enum Resume {
|
|
|
|
SellXmr {
|
2020-12-21 06:52:52 +00:00
|
|
|
#[structopt(long = "swap-id")]
|
2020-11-06 00:10:22 +00:00
|
|
|
swap_id: Uuid,
|
|
|
|
|
2020-12-21 03:43:44 +00:00
|
|
|
#[structopt(long = "listen-address", default_value = "/ip4/127.0.0.1/tcp/9876")]
|
|
|
|
listen_addr: Multiaddr,
|
2021-01-27 02:33:32 +00:00
|
|
|
|
|
|
|
#[structopt(flatten)]
|
|
|
|
config: Config,
|
2020-12-21 03:43:44 +00:00
|
|
|
},
|
|
|
|
BuyXmr {
|
|
|
|
#[structopt(long = "swap-id")]
|
|
|
|
swap_id: Uuid,
|
|
|
|
|
|
|
|
#[structopt(long = "counterpart-peer-id")]
|
2020-12-18 06:39:04 +00:00
|
|
|
alice_peer_id: PeerId,
|
|
|
|
|
2020-12-21 03:43:44 +00:00
|
|
|
#[structopt(long = "counterpart-addr")]
|
2020-12-18 06:39:04 +00:00
|
|
|
alice_addr: Multiaddr,
|
|
|
|
|
2021-01-27 02:33:32 +00:00
|
|
|
#[structopt(flatten)]
|
|
|
|
config: Config,
|
2020-11-06 00:10:22 +00:00
|
|
|
},
|
2020-10-15 22:14:39 +00:00
|
|
|
}
|
2020-12-04 05:27:17 +00:00
|
|
|
|
2021-02-01 05:10:43 +00:00
|
|
|
#[derive(structopt::StructOpt, Debug)]
|
|
|
|
pub enum Cancel {
|
|
|
|
BuyXmr {
|
|
|
|
#[structopt(long = "swap-id")]
|
2021-02-01 05:25:33 +00:00
|
|
|
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")]
|
|
|
|
alice_peer_id: PeerId,
|
|
|
|
#[structopt(long = "counterpart-addr")]
|
|
|
|
alice_addr: Multiaddr,
|
|
|
|
|
|
|
|
#[structopt(flatten)]
|
|
|
|
config: Config,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(structopt::StructOpt, Debug)]
|
|
|
|
pub enum Refund {
|
|
|
|
BuyXmr {
|
|
|
|
#[structopt(long = "swap-id")]
|
2021-02-01 05:10:43 +00:00
|
|
|
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")]
|
|
|
|
alice_peer_id: PeerId,
|
|
|
|
#[structopt(long = "counterpart-addr")]
|
|
|
|
alice_addr: Multiaddr,
|
|
|
|
|
|
|
|
#[structopt(flatten)]
|
|
|
|
config: Config,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-01-27 02:33:32 +00:00
|
|
|
#[derive(structopt::StructOpt, Debug)]
|
|
|
|
pub struct Config {
|
|
|
|
#[structopt(
|
|
|
|
long = "config",
|
|
|
|
help = "Provide a custom path to the configuration file. The configuration file must be a toml file.",
|
|
|
|
parse(from_os_str)
|
|
|
|
)]
|
|
|
|
pub path: Option<PathBuf>,
|
|
|
|
}
|
|
|
|
|
2020-12-04 05:27:17 +00:00
|
|
|
fn parse_btc(str: &str) -> anyhow::Result<bitcoin::Amount> {
|
|
|
|
let amount = bitcoin::Amount::from_str_in(str, ::bitcoin::Denomination::Bitcoin)?;
|
|
|
|
Ok(amount)
|
|
|
|
}
|
|
|
|
|
2021-01-05 03:08:36 +00:00
|
|
|
fn parse_xmr(str: &str) -> anyhow::Result<monero::Amount> {
|
|
|
|
let amount = monero::Amount::parse_monero(str)?;
|
2020-12-04 05:27:17 +00:00
|
|
|
Ok(amount)
|
|
|
|
}
|