Remove `--seller-peer-id` from `buy-xmr` command

The peer-id is to be provided as part of the multiaddress.
This simplifies the interface for the user.

Note that the `resume` command was not adapted yet, and we are not yet saving the complete multiaddr in the database but only the peer-id.
rendezvous-demo
Daniel Karzel 3 years ago
parent 061208a063
commit 9224134dee
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E

@ -13,6 +13,8 @@
#![allow(non_snake_case)]
use anyhow::{bail, Context, Result};
use libp2p::core::multiaddr::Protocol;
use libp2p::PeerId;
use prettytable::{row, Table};
use qrcode::render::unicode;
use qrcode::QrCode;
@ -58,7 +60,6 @@ async fn main() -> Result<()> {
match cmd {
Command::BuyXmr {
seller_peer_id,
seller_addr,
bitcoin_electrum_rpc_url,
bitcoin_target_block,
@ -68,6 +69,23 @@ async fn main() -> Result<()> {
} => {
let swap_id = Uuid::new_v4();
let seller_peer_id = match seller_addr.iter().last() {
None => {
bail!("Invalid multiaddress");
}
Some(protocol) => {
match protocol {
Protocol::P2p(hash) => {
match PeerId::from_multihash(hash) {
Ok(peer_id) => peer_id,
Err(_) => bail!("Multiaddress contains invalid peer-id")
}
}
_ => bail!("The given multiaddress does not end with the peer-id (i.e. /p2p/{peer-id}), make sure you provide the peer-id of the seller as part of the address.")
}
}
};
cli::tracing::init(debug, json, data_dir.join("logs"), Some(swap_id))?;
let db = Database::open(data_dir.join("database").as_path())
.context("Failed to open database")?;
@ -159,6 +177,10 @@ async fn main() -> Result<()> {
monero_daemon_address,
tor_socks5_port,
} => {
// TODO: Save complete seller address into database - the user might not know
// the seller that is traded with We assume that the seller address
// does not change.
cli::tracing::init(debug, json, data_dir.join("logs"), Some(swap_id))?;
let db = Database::open(data_dir.join("database").as_path())
.context("Failed to open database")?;

@ -69,7 +69,6 @@ where
let arguments = match args.cmd {
RawCommand::BuyXmr {
seller_peer_id,
seller_addr: SellerAddr { seller_addr },
bitcoin:
Bitcoin {
@ -88,7 +87,6 @@ where
json,
data_dir: data::data_dir_from(data, is_testnet)?,
cmd: Command::BuyXmr {
seller_peer_id,
seller_addr,
bitcoin_electrum_rpc_url: bitcoin_electrum_rpc_url_from(
bitcoin_electrum_rpc_url,
@ -218,7 +216,6 @@ where
#[derive(Debug, PartialEq)]
pub enum Command {
BuyXmr {
seller_peer_id: PeerId,
seller_addr: Multiaddr,
bitcoin_electrum_rpc_url: Url,
bitcoin_target_block: usize,
@ -291,9 +288,6 @@ pub struct RawArguments {
pub enum RawCommand {
/// Start a XMR for BTC swap
BuyXmr {
#[structopt(long = "seller-peer-id", help = "The seller's peer id")]
seller_peer_id: PeerId,
#[structopt(flatten)]
seller_addr: SellerAddr,
@ -415,7 +409,10 @@ pub struct SwapId {
#[derive(structopt::StructOpt, Debug)]
pub struct SellerAddr {
#[structopt(long = "seller-addr", help = "The seller's multiaddress")]
#[structopt(
long = "seller-addr",
help = "The seller's multiaddress including the peer-id"
)]
pub seller_addr: Multiaddr,
}
@ -987,7 +984,6 @@ mod tests {
json: false,
data_dir: data_dir_path_cli().join(TESTNET),
cmd: Command::BuyXmr {
seller_peer_id: PeerId::from_str(PEER_ID).unwrap(),
seller_addr: Multiaddr::from_str(MUTLI_ADDRESS).unwrap(),
bitcoin_electrum_rpc_url: Url::from_str(DEFAULT_ELECTRUM_RPC_URL_TESTNET)
.unwrap(),
@ -1007,7 +1003,6 @@ mod tests {
json: false,
data_dir: data_dir_path_cli().join(MAINNET),
cmd: Command::BuyXmr {
seller_peer_id: PeerId::from_str(PEER_ID).unwrap(),
seller_addr: Multiaddr::from_str(MUTLI_ADDRESS).unwrap(),
bitcoin_electrum_rpc_url: Url::from_str(DEFAULT_ELECTRUM_RPC_URL).unwrap(),
bitcoin_target_block: DEFAULT_BITCOIN_CONFIRMATION_TARGET,

Loading…
Cancel
Save