2020-12-18 01:39:04 -05:00
|
|
|
use libp2p::{core::Multiaddr, PeerId};
|
2020-10-28 23:45:45 -04:00
|
|
|
use url::Url;
|
2020-11-05 19:10:22 -05:00
|
|
|
use uuid::Uuid;
|
2020-10-28 23:45:45 -04:00
|
|
|
|
2020-12-15 05:26:02 -05:00
|
|
|
#[derive(structopt::StructOpt, Debug)]
|
|
|
|
pub struct Options {
|
2020-12-17 03:10:24 -05:00
|
|
|
// TODO: Default value should points to proper configuration folder in home folder
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "database", default_value = "./.swap-db/")]
|
2020-12-15 05:26:02 -05:00
|
|
|
pub db_path: String,
|
|
|
|
|
|
|
|
#[structopt(subcommand)]
|
|
|
|
pub cmd: Command,
|
|
|
|
}
|
|
|
|
|
2020-10-15 18:14:39 -04:00
|
|
|
#[derive(structopt::StructOpt, Debug)]
|
2020-12-17 03:10:24 -05:00
|
|
|
#[structopt(name = "xmr-btc-swap", about = "XMR BTC atomic swap")]
|
2020-12-15 05:26:02 -05:00
|
|
|
pub enum Command {
|
2020-12-04 00:27:17 -05:00
|
|
|
SellXmr {
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "bitcoind-rpc", default_value = "http://127.0.0.1:8332")]
|
2020-10-28 23:45:45 -04:00
|
|
|
bitcoind_url: Url,
|
|
|
|
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "bitcoin-wallet-name")]
|
2020-12-04 00:27:17 -05:00
|
|
|
bitcoin_wallet_name: String,
|
2020-11-03 00:08:46 -05:00
|
|
|
|
2020-12-04 00:27:17 -05:00
|
|
|
#[structopt(
|
|
|
|
long = "monero-wallet-rpc",
|
|
|
|
default_value = "http://127.0.0.1:18083/json_rpc"
|
|
|
|
)]
|
|
|
|
monero_wallet_rpc_url: Url,
|
|
|
|
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "p2p-address", default_value = "/ip4/127.0.0.1/tcp/9876")]
|
2020-10-29 07:18:59 -04:00
|
|
|
listen_addr: Multiaddr,
|
2020-10-15 18:14:39 -04:00
|
|
|
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "send-xmr", help = "Monero amount as floating point nr without denomination (e.g. 125.1)", parse(try_from_str = parse_xmr))]
|
2020-12-04 00:27:17 -05:00
|
|
|
send_monero: xmr_btc::monero::Amount,
|
2020-10-26 01:55:53 -04:00
|
|
|
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "receive-btc", help = "Bitcoin amount as floating point nr without denomination (e.g. 1.25)", parse(try_from_str = parse_btc))]
|
2020-12-04 00:27:17 -05:00
|
|
|
receive_bitcoin: bitcoin::Amount,
|
|
|
|
},
|
|
|
|
BuyXmr {
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "connect-peer-id")]
|
2020-12-18 01:39:04 -05:00
|
|
|
alice_peer_id: PeerId,
|
|
|
|
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "connect-addr")]
|
2020-10-29 07:18:59 -04:00
|
|
|
alice_addr: Multiaddr,
|
|
|
|
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "bitcoind-rpc", default_value = "http://127.0.0.1:8332")]
|
2020-10-28 23:45:45 -04:00
|
|
|
bitcoind_url: Url,
|
2020-11-02 22:54:36 -05:00
|
|
|
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "bitcoin-wallet-name")]
|
2020-12-04 00:27:17 -05:00
|
|
|
bitcoin_wallet_name: String,
|
|
|
|
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "monerod", default_value = "http://127.0.0.1:18083/json_rpc")]
|
2020-12-04 00:27:17 -05:00
|
|
|
monero_wallet_rpc_url: Url,
|
2020-11-03 00:08:46 -05:00
|
|
|
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "send-btc", help = "Bitcoin amount as floating point nr without denomination (e.g. 1.25)", parse(try_from_str = parse_btc))]
|
2020-12-04 00:27:17 -05:00
|
|
|
send_bitcoin: bitcoin::Amount,
|
|
|
|
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "receive-xmr", help = "Monero amount as floating point nr without denomination (e.g. 125.1)", parse(try_from_str = parse_xmr))]
|
2020-12-04 00:27:17 -05:00
|
|
|
receive_monero: xmr_btc::monero::Amount,
|
2020-10-28 23:45:45 -04:00
|
|
|
},
|
2020-11-05 00:55:30 -05:00
|
|
|
History,
|
2020-12-14 19:52:00 -05:00
|
|
|
Resume {
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "swap-id")]
|
2020-11-05 19:10:22 -05:00
|
|
|
swap_id: Uuid,
|
|
|
|
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "connect-peer-id")]
|
2020-12-18 01:39:04 -05:00
|
|
|
alice_peer_id: PeerId,
|
|
|
|
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "connect-addr")]
|
2020-12-18 01:39:04 -05:00
|
|
|
alice_addr: Multiaddr,
|
|
|
|
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "bitcoind-rpc", default_value = "http://127.0.0.1:8332")]
|
2020-11-05 19:10:22 -05:00
|
|
|
bitcoind_url: Url,
|
|
|
|
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "bitcoin-wallet-name")]
|
2020-12-04 00:27:17 -05:00
|
|
|
bitcoin_wallet_name: String,
|
2020-12-15 05:26:02 -05:00
|
|
|
|
|
|
|
#[structopt(
|
|
|
|
long = "monero-wallet-rpc",
|
|
|
|
default_value = "http://127.0.0.1:18083/json_rpc"
|
|
|
|
)]
|
|
|
|
monero_wallet_rpc_url: Url,
|
|
|
|
|
|
|
|
// TODO: The listen address is only relevant for Alice, but should be role independent
|
|
|
|
// see: https://github.com/comit-network/xmr-btc-swap/issues/77
|
2020-12-21 01:52:52 -05:00
|
|
|
#[structopt(long = "p2p-address", default_value = "/ip4/127.0.0.1/tcp/9876")]
|
2020-12-15 05:26:02 -05:00
|
|
|
listen_addr: Multiaddr,
|
2020-11-05 19:10:22 -05:00
|
|
|
},
|
2020-10-15 18:14:39 -04:00
|
|
|
}
|
2020-12-04 00:27:17 -05:00
|
|
|
|
|
|
|
fn parse_btc(str: &str) -> anyhow::Result<bitcoin::Amount> {
|
|
|
|
let amount = bitcoin::Amount::from_str_in(str, ::bitcoin::Denomination::Bitcoin)?;
|
|
|
|
Ok(amount)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parse_xmr(str: &str) -> anyhow::Result<xmr_btc::monero::Amount> {
|
|
|
|
let amount = xmr_btc::monero::Amount::parse_monero(str)?;
|
|
|
|
Ok(amount)
|
|
|
|
}
|