2020-12-18 17:39:04 +11:00
|
|
|
use libp2p::{core::Multiaddr, PeerId};
|
2020-10-29 14:45:45 +11:00
|
|
|
use url::Url;
|
2020-11-06 11:10:22 +11:00
|
|
|
use uuid::Uuid;
|
2020-10-29 14:45:45 +11:00
|
|
|
|
2021-01-08 10:41:25 +11:00
|
|
|
use crate::{bitcoin, monero};
|
2021-01-05 14:08:36 +11:00
|
|
|
|
2020-12-15 21:26:02 +11:00
|
|
|
#[derive(structopt::StructOpt, Debug)]
|
|
|
|
pub struct Options {
|
2020-12-17 19:10:24 +11:00
|
|
|
// TODO: Default value should points to proper configuration folder in home folder
|
2021-01-08 12:04:48 +11:00
|
|
|
#[structopt(long = "data-dir", default_value = "./.swap-data/")]
|
|
|
|
pub data_dir: String,
|
2020-12-15 21:26:02 +11:00
|
|
|
|
|
|
|
#[structopt(subcommand)]
|
|
|
|
pub cmd: Command,
|
|
|
|
}
|
|
|
|
|
2020-10-16 09:14:39 +11:00
|
|
|
#[derive(structopt::StructOpt, Debug)]
|
2021-01-05 14:08:36 +11:00
|
|
|
#[structopt(name = "xmr_btc-swap", about = "XMR BTC atomic swap")]
|
2020-12-15 21:26:02 +11:00
|
|
|
pub enum Command {
|
2020-12-04 16:27:17 +11:00
|
|
|
SellXmr {
|
2020-12-21 17:52:52 +11:00
|
|
|
#[structopt(long = "bitcoind-rpc", default_value = "http://127.0.0.1:8332")]
|
2020-10-29 14:45:45 +11:00
|
|
|
bitcoind_url: Url,
|
|
|
|
|
2020-12-21 17:52:52 +11:00
|
|
|
#[structopt(long = "bitcoin-wallet-name")]
|
2020-12-04 16:27:17 +11:00
|
|
|
bitcoin_wallet_name: String,
|
2020-11-03 16:08:46 +11:00
|
|
|
|
2020-12-04 16:27:17 +11:00
|
|
|
#[structopt(
|
|
|
|
long = "monero-wallet-rpc",
|
|
|
|
default_value = "http://127.0.0.1:18083/json_rpc"
|
|
|
|
)]
|
|
|
|
monero_wallet_rpc_url: Url,
|
|
|
|
|
2021-01-07 11:45:55 +11:00
|
|
|
#[structopt(long = "p2p-address", default_value = "/ip4/0.0.0.0/tcp/9876")]
|
2020-10-29 22:18:59 +11:00
|
|
|
listen_addr: Multiaddr,
|
2020-10-16 09:14:39 +11:00
|
|
|
|
2020-12-21 17:52:52 +11: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 14:08:36 +11:00
|
|
|
send_monero: monero::Amount,
|
2020-10-26 16:55:53 +11:00
|
|
|
|
2020-12-21 17:52:52 +11: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-08 10:41:25 +11:00
|
|
|
receive_bitcoin: bitcoin::Amount,
|
2020-12-04 16:27:17 +11:00
|
|
|
},
|
|
|
|
BuyXmr {
|
2020-12-21 17:52:52 +11:00
|
|
|
#[structopt(long = "connect-peer-id")]
|
2020-12-18 17:39:04 +11:00
|
|
|
alice_peer_id: PeerId,
|
|
|
|
|
2020-12-21 17:52:52 +11:00
|
|
|
#[structopt(long = "connect-addr")]
|
2020-10-29 22:18:59 +11:00
|
|
|
alice_addr: Multiaddr,
|
|
|
|
|
2020-12-21 17:52:52 +11:00
|
|
|
#[structopt(long = "bitcoind-rpc", default_value = "http://127.0.0.1:8332")]
|
2020-10-29 14:45:45 +11:00
|
|
|
bitcoind_url: Url,
|
2020-11-03 14:54:36 +11:00
|
|
|
|
2020-12-21 17:52:52 +11:00
|
|
|
#[structopt(long = "bitcoin-wallet-name")]
|
2020-12-04 16:27:17 +11:00
|
|
|
bitcoin_wallet_name: String,
|
|
|
|
|
2021-01-05 11:00:15 +11:00
|
|
|
#[structopt(
|
|
|
|
long = "monero-wallet-rpc",
|
|
|
|
default_value = "http://127.0.0.1:18083/json_rpc"
|
|
|
|
)]
|
2020-12-04 16:27:17 +11:00
|
|
|
monero_wallet_rpc_url: Url,
|
2020-11-03 16:08:46 +11:00
|
|
|
|
2020-12-21 17:52:52 +11: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-08 10:41:25 +11:00
|
|
|
send_bitcoin: bitcoin::Amount,
|
2020-12-04 16:27:17 +11:00
|
|
|
|
2020-12-21 17:52:52 +11: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 14:08:36 +11:00
|
|
|
receive_monero: monero::Amount,
|
2020-10-29 14:45:45 +11:00
|
|
|
},
|
2020-11-05 16:55:30 +11:00
|
|
|
History,
|
2020-12-21 14:43:44 +11:00
|
|
|
Resume(Resume),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(structopt::StructOpt, Debug)]
|
|
|
|
pub enum Resume {
|
|
|
|
SellXmr {
|
2020-12-21 17:52:52 +11:00
|
|
|
#[structopt(long = "swap-id")]
|
2020-11-06 11:10:22 +11:00
|
|
|
swap_id: Uuid,
|
|
|
|
|
2020-12-21 14:43:44 +11:00
|
|
|
#[structopt(long = "bitcoind-rpc", default_value = "http://127.0.0.1:8332")]
|
|
|
|
bitcoind_url: Url,
|
|
|
|
|
|
|
|
#[structopt(long = "bitcoin-wallet-name")]
|
|
|
|
bitcoin_wallet_name: String,
|
|
|
|
|
|
|
|
#[structopt(
|
|
|
|
long = "monero-wallet-rpc",
|
|
|
|
default_value = "http://127.0.0.1:18083/json_rpc"
|
|
|
|
)]
|
|
|
|
monero_wallet_rpc_url: Url,
|
|
|
|
|
|
|
|
#[structopt(long = "listen-address", default_value = "/ip4/127.0.0.1/tcp/9876")]
|
|
|
|
listen_addr: Multiaddr,
|
|
|
|
},
|
|
|
|
BuyXmr {
|
|
|
|
#[structopt(long = "swap-id")]
|
|
|
|
swap_id: Uuid,
|
|
|
|
|
|
|
|
#[structopt(long = "counterpart-peer-id")]
|
2020-12-18 17:39:04 +11:00
|
|
|
alice_peer_id: PeerId,
|
|
|
|
|
2020-12-21 14:43:44 +11:00
|
|
|
#[structopt(long = "counterpart-addr")]
|
2020-12-18 17:39:04 +11:00
|
|
|
alice_addr: Multiaddr,
|
|
|
|
|
2020-12-21 17:52:52 +11:00
|
|
|
#[structopt(long = "bitcoind-rpc", default_value = "http://127.0.0.1:8332")]
|
2020-11-06 11:10:22 +11:00
|
|
|
bitcoind_url: Url,
|
|
|
|
|
2020-12-21 17:52:52 +11:00
|
|
|
#[structopt(long = "bitcoin-wallet-name")]
|
2020-12-04 16:27:17 +11:00
|
|
|
bitcoin_wallet_name: String,
|
2020-12-15 21:26:02 +11:00
|
|
|
|
|
|
|
#[structopt(
|
|
|
|
long = "monero-wallet-rpc",
|
|
|
|
default_value = "http://127.0.0.1:18083/json_rpc"
|
|
|
|
)]
|
|
|
|
monero_wallet_rpc_url: Url,
|
2020-11-06 11:10:22 +11:00
|
|
|
},
|
2020-10-16 09:14:39 +11:00
|
|
|
}
|
2020-12-04 16:27:17 +11: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 14:08:36 +11:00
|
|
|
fn parse_xmr(str: &str) -> anyhow::Result<monero::Amount> {
|
|
|
|
let amount = monero::Amount::parse_monero(str)?;
|
2020-12-04 16:27:17 +11:00
|
|
|
Ok(amount)
|
|
|
|
}
|