Separate Buy/Sell for resume command

To avoid confusing the user on whether person should enter a listen addr
or a connect peer id and address
This commit is contained in:
Franck Royer 2020-12-21 14:43:44 +11:00
parent 672377b216
commit 1fa812b727
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 81 additions and 55 deletions

View File

@ -23,7 +23,7 @@ use swap::{
alice::swap::AliceState, alice::swap::AliceState,
bitcoin, bob, bitcoin, bob,
bob::swap::BobState, bob::swap::BobState,
cli::{Command, Options}, cli::{Command, Options, Resume},
monero, monero,
network::transport::build, network::transport::build,
storage::Database, storage::Database,
@ -173,58 +173,65 @@ async fn main() -> Result<()> {
// Print the table to stdout // Print the table to stdout
table.printstd(); table.printstd();
} }
Command::Resume { Command::Resume(Resume::SellXmr {
swap_id, swap_id,
bitcoind_url, bitcoind_url,
bitcoin_wallet_name, bitcoin_wallet_name,
monero_wallet_rpc_url, monero_wallet_rpc_url,
listen_addr, listen_addr,
alice_peer_id, }) => {
alice_addr,
} => {
let db_swap = db.get_state(swap_id)?; let db_swap = db.get_state(swap_id)?;
if let Ok(alice_state) = AliceState::try_from(db_swap.clone()) { let alice_state = AliceState::try_from(db_swap.clone())?;
let (bitcoin_wallet, monero_wallet) = setup_wallets( let (bitcoin_wallet, monero_wallet) = setup_wallets(
bitcoind_url, bitcoind_url,
bitcoin_wallet_name.as_str(), bitcoin_wallet_name.as_str(),
monero_wallet_rpc_url, monero_wallet_rpc_url,
config, config,
) )
.await?; .await?;
alice_swap( alice_swap(
swap_id, swap_id,
alice_state, alice_state,
listen_addr, listen_addr,
bitcoin_wallet, bitcoin_wallet,
monero_wallet, monero_wallet,
config, config,
db, db,
) )
.await?; .await?;
} else if let Ok(bob_state) = BobState::try_from(db_swap) {
let (bitcoin_wallet, monero_wallet) = setup_wallets(
bitcoind_url,
bitcoin_wallet_name.as_str(),
monero_wallet_rpc_url,
config,
)
.await?;
bob_swap(
swap_id,
bob_state,
bitcoin_wallet,
monero_wallet,
db,
alice_peer_id,
alice_addr,
)
.await?;
} else {
anyhow::bail!("Unable to construct swap state for swap with id {}")
}
} }
} Command::Resume(Resume::BuyXmr {
swap_id,
bitcoind_url,
bitcoin_wallet_name,
monero_wallet_rpc_url,
alice_peer_id,
alice_addr,
}) => {
let db_swap = db.get_state(swap_id)?;
let bob_state = BobState::try_from(db_swap)?;
let (bitcoin_wallet, monero_wallet) = setup_wallets(
bitcoind_url,
bitcoin_wallet_name.as_str(),
monero_wallet_rpc_url,
config,
)
.await?;
bob_swap(
swap_id,
bob_state,
bitcoin_wallet,
monero_wallet,
db,
alice_peer_id,
alice_addr,
)
.await?;
}
};
Ok(()) Ok(())
} }

View File

@ -60,16 +60,15 @@ pub enum Command {
receive_monero: xmr_btc::monero::Amount, receive_monero: xmr_btc::monero::Amount,
}, },
History, History,
Resume { Resume(Resume),
}
#[derive(structopt::StructOpt, Debug)]
pub enum Resume {
SellXmr {
#[structopt(long = "swap-id")] #[structopt(long = "swap-id")]
swap_id: Uuid, swap_id: Uuid,
#[structopt(long = "connect-peer-id")]
alice_peer_id: PeerId,
#[structopt(long = "connect-addr")]
alice_addr: Multiaddr,
#[structopt(long = "bitcoind-rpc", default_value = "http://127.0.0.1:8332")] #[structopt(long = "bitcoind-rpc", default_value = "http://127.0.0.1:8332")]
bitcoind_url: Url, bitcoind_url: Url,
@ -82,11 +81,31 @@ pub enum Command {
)] )]
monero_wallet_rpc_url: Url, monero_wallet_rpc_url: Url,
// TODO: The listen address is only relevant for Alice, but should be role independent #[structopt(long = "listen-address", default_value = "/ip4/127.0.0.1/tcp/9876")]
// see: https://github.com/comit-network/xmr-btc-swap/issues/77
#[structopt(long = "p2p-address", default_value = "/ip4/127.0.0.1/tcp/9876")]
listen_addr: Multiaddr, listen_addr: Multiaddr,
}, },
BuyXmr {
#[structopt(long = "swap-id")]
swap_id: Uuid,
#[structopt(long = "counterpart-peer-id")]
alice_peer_id: PeerId,
#[structopt(long = "counterpart-addr")]
alice_addr: Multiaddr,
#[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,
},
} }
fn parse_btc(str: &str) -> anyhow::Result<bitcoin::Amount> { fn parse_btc(str: &str) -> anyhow::Result<bitcoin::Amount> {