@ -2,8 +2,8 @@ use libp2p::{core::Multiaddr, PeerId};
use std ::path ::PathBuf ;
use uuid ::Uuid ;
const DEFAULT_ALICE_MULTIADDR : & str = "/dns4/xmr-btc-asb.coblox.tech/tcp/9876" ;
const DEFAULT_ALICE_PEER_ID : & str = "12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi" ;
pub const DEFAULT_ALICE_MULTIADDR : & str = "/dns4/xmr-btc-asb.coblox.tech/tcp/9876" ;
pub const DEFAULT_ALICE_PEER_ID : & str = "12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi" ;
#[ derive(structopt::StructOpt, Debug) ]
pub struct Arguments {
@ -15,7 +15,7 @@ pub struct Arguments {
pub config : Option < PathBuf > ,
#[ structopt(subcommand) ]
pub cmd : Command ,
pub cmd : Option < Command > ,
}
#[ derive(structopt::StructOpt, Debug) ]
@ -26,37 +26,28 @@ pub enum Command {
alice_peer_id : PeerId ,
#[ structopt(
long = "connect-addr" ,
default_value = DEFAULT_ALICE_MULTIADDR
long = "connect-addr" ,
default_value = DEFAULT_ALICE_MULTIADDR
) ]
alice_addr : Multiaddr ,
} ,
History ,
Resume ( Resume ) ,
Cancel ( Cancel ) ,
Refund ( Refund ) ,
}
#[ derive(structopt::StructOpt, Debug) ]
pub enum Resume {
BuyXmr {
Resume {
#[ structopt(long = " swap-id " ) ]
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 " , default_value = DEFAULT_ALICE_PEER_ID) ]
alice_peer_id : PeerId ,
#[ structopt(
long = "counterpart-addr" ,
default_value = DEFAULT_ALICE_MULTIADDR
long = "counterpart-addr" ,
default_value = DEFAULT_ALICE_MULTIADDR
) ]
alice_addr : Multiaddr ,
} ,
}
#[ derive(structopt::StructOpt, Debug) ]
pub enum Cancel {
BuyXmr {
Cancel {
#[ structopt(long = " swap-id " ) ]
swap_id : Uuid ,
@ -66,19 +57,15 @@ pub enum Cancel {
alice_peer_id : PeerId ,
#[ structopt(
long = "counterpart-addr" ,
default_value = DEFAULT_ALICE_MULTIADDR
) ]
long = "counterpart-addr" ,
default_value = DEFAULT_ALICE_MULTIADDR
) ]
alice_addr : Multiaddr ,
#[ structopt(short, long) ]
force : bool ,
} ,
}
#[ derive(structopt::StructOpt, Debug) ]
pub enum Refund {
BuyXmr {
Refund {
#[ structopt(long = " swap-id " ) ]
swap_id : Uuid ,
@ -88,8 +75,8 @@ pub enum Refund {
alice_peer_id : PeerId ,
#[ structopt(
long = "counterpart-addr" ,
default_value = DEFAULT_ALICE_MULTIADDR
long = "counterpart-addr" ,
default_value = DEFAULT_ALICE_MULTIADDR
) ]
alice_addr : Multiaddr ,
@ -97,3 +84,41 @@ pub enum Refund {
force : bool ,
} ,
}
impl Default for Command {
fn default ( ) -> Self {
Self ::BuyXmr {
alice_peer_id : DEFAULT_ALICE_PEER_ID
. parse ( )
. expect ( "default alice peer id str is a valid Multiaddr>" ) ,
alice_addr : DEFAULT_ALICE_MULTIADDR
. parse ( )
. expect ( "default alice multiaddr str is a valid PeerId" ) ,
}
}
}
#[ cfg(test) ]
mod tests {
use crate ::cli ::command ::{ Command , DEFAULT_ALICE_MULTIADDR , DEFAULT_ALICE_PEER_ID } ;
use libp2p ::{ core ::Multiaddr , PeerId } ;
#[ 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>" ) ;
}
#[ test ]
fn default_command_success ( ) {
Command ::default ( ) ;
}
}