2020-12-09 22:59:09 -05:00
use libp2p ::core ::Multiaddr ;
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-10-15 18:14:39 -04:00
#[ derive(structopt::StructOpt, Debug) ]
2020-11-02 22:54:36 -05:00
#[ structopt(name = " xmr-btc-swap " , about = " Trustless XMR BTC swaps " ) ]
2020-10-28 23:45:45 -04:00
pub enum Options {
2020-12-04 00:27:17 -05:00
SellXmr {
#[ structopt(
short = " b " ,
long = " bitcoind " ,
default_value = " http://127.0.0.1:8332 "
) ]
2020-10-28 23:45:45 -04:00
bitcoind_url : Url ,
2020-12-04 00:27:17 -05:00
#[ structopt(short = " n " , long = " bitcoin-wallet-name " ) ]
bitcoin_wallet_name : String ,
2020-11-03 00:08:46 -05:00
2020-12-04 00:27:17 -05:00
#[ structopt(
short = " m " ,
long = " monero-wallet-rpc " ,
default_value = " http://127.0.0.1:18083/json_rpc "
) ]
monero_wallet_rpc_url : Url ,
#[ structopt(
short = " a " ,
long = " listen-addr " ,
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-04 00:27:17 -05:00
#[ structopt(short = " s " , long = " send-xmr " , help = " Monero amount as floating point nr without denomination (e.g. 125.1) " , parse(try_from_str = parse_xmr)) ]
send_monero : xmr_btc ::monero ::Amount ,
2020-10-26 01:55:53 -04:00
2020-12-04 00:27:17 -05:00
#[ structopt(short = " r " , long = " receive-btc " , help = " Bitcoin amount as floating point nr without denomination (e.g. 1.25) " , parse(try_from_str = parse_btc)) ]
receive_bitcoin : bitcoin ::Amount ,
} ,
BuyXmr {
#[ structopt(short = " a " , long = " connect-addr " ) ]
2020-10-29 07:18:59 -04:00
alice_addr : Multiaddr ,
2020-12-04 00:27:17 -05:00
#[ structopt(
short = " b " ,
long = " bitcoind " ,
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-04 00:27:17 -05:00
#[ structopt(short = " n " , long = " bitcoin-wallet-name " ) ]
bitcoin_wallet_name : String ,
#[ structopt(
short = " m " ,
long = " monerod " ,
default_value = " http://127.0.0.1:18083/json_rpc "
) ]
monero_wallet_rpc_url : Url ,
2020-11-03 00:08:46 -05:00
2020-12-04 00:27:17 -05:00
#[ structopt(short = " s " , long = " send-btc " , help = " Bitcoin amount as floating point nr without denomination (e.g. 1.25) " , parse(try_from_str = parse_btc)) ]
send_bitcoin : bitcoin ::Amount ,
#[ structopt(short = " r " , long = " receive-xmr " , help = " Monero amount as floating point nr without denomination (e.g. 125.1) " , parse(try_from_str = parse_xmr)) ]
receive_monero : xmr_btc ::monero ::Amount ,
2020-10-28 23:45:45 -04:00
} ,
2020-11-05 00:55:30 -05:00
History ,
2020-11-05 19:10:22 -05:00
Recover {
#[ structopt(required = true) ]
swap_id : Uuid ,
#[ structopt(default_value = " http://127.0.0.1:8332 " , long = " bitcoind " ) ]
bitcoind_url : Url ,
2020-11-30 15:41:22 -05:00
#[ structopt(default_value = " http://127.0.0.1:18083/json_rpc " , long = " monerod " ) ]
monerod_url : Url ,
2020-12-04 00:27:17 -05:00
#[ structopt(short = " n " , long = " bitcoin-wallet-name " ) ]
bitcoin_wallet_name : String ,
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 )
}