269: Monero address validity check r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
This commit is contained in:
bors[bot] 2021-03-04 02:36:52 +00:00 committed by GitHub
commit 18980f4b8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 4 deletions

View File

@ -12,7 +12,7 @@
#![forbid(unsafe_code)]
#![allow(non_snake_case)]
use anyhow::{Context, Result};
use anyhow::{bail, Context, Result};
use prettytable::{row, Table};
use reqwest::Url;
use std::{path::Path, sync::Arc, time::Duration};
@ -107,6 +107,14 @@ async fn main() -> Result<()> {
alice_peer_id,
alice_addr,
} => {
if receive_monero_address.network != monero_network {
bail!(
"Given monero address is on network {:?}, expected address on network {:?}",
receive_monero_address.network,
monero_network
)
}
let bitcoin_wallet =
init_bitcoin_wallet(config, bitcoin_network, &wallet_data_dir, seed).await?;
let monero_wallet =
@ -186,6 +194,10 @@ async fn main() -> Result<()> {
alice_peer_id,
alice_addr,
} => {
if receive_monero_address.network != monero_network {
bail!("The given monero address is on network {:?}, expected address of network {:?}.", receive_monero_address.network, monero_network)
}
let bitcoin_wallet =
init_bitcoin_wallet(config, bitcoin_network, &wallet_data_dir, seed).await?;
let monero_wallet =

View File

@ -1,5 +1,6 @@
use anyhow::{Context, Result};
use libp2p::{core::Multiaddr, PeerId};
use std::path::PathBuf;
use std::{path::PathBuf, str::FromStr};
use uuid::Uuid;
pub const DEFAULT_ALICE_MULTIADDR: &str = "/dns4/xmr-btc-asb.coblox.tech/tcp/9876";
@ -25,7 +26,7 @@ pub struct Arguments {
#[structopt(name = "xmr_btc-swap", about = "XMR BTC atomic swap")]
pub enum Command {
BuyXmr {
#[structopt(long = "receive-address")]
#[structopt(long = "receive-address", parse(try_from_str = parse_monero_address))]
receive_monero_address: monero::Address,
#[structopt(long = "connect-peer-id", default_value = DEFAULT_ALICE_PEER_ID)]
@ -39,7 +40,7 @@ pub enum Command {
},
History,
Resume {
#[structopt(long = "receive-address")]
#[structopt(long = "receive-address", parse(try_from_str = parse_monero_address))]
receive_monero_address: monero::Address,
#[structopt(long = "swap-id")]
@ -72,6 +73,15 @@ pub enum Command {
},
}
fn parse_monero_address(s: &str) -> Result<monero::Address> {
monero::Address::from_str(s).with_context(|| {
format!(
"Failed to parse {} as a monero address, please make sure it is a valid address",
s
)
})
}
#[cfg(test)]
mod tests {
use crate::cli::command::{DEFAULT_ALICE_MULTIADDR, DEFAULT_ALICE_PEER_ID};