mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Merge #269
269: Monero address validity check r=da-kami a=da-kami Co-authored-by: Daniel Karzel <daniel@comit.network>
This commit is contained in:
commit
18980f4b8a
@ -12,7 +12,7 @@
|
|||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use prettytable::{row, Table};
|
use prettytable::{row, Table};
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use std::{path::Path, sync::Arc, time::Duration};
|
use std::{path::Path, sync::Arc, time::Duration};
|
||||||
@ -107,6 +107,14 @@ async fn main() -> Result<()> {
|
|||||||
alice_peer_id,
|
alice_peer_id,
|
||||||
alice_addr,
|
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 =
|
let bitcoin_wallet =
|
||||||
init_bitcoin_wallet(config, bitcoin_network, &wallet_data_dir, seed).await?;
|
init_bitcoin_wallet(config, bitcoin_network, &wallet_data_dir, seed).await?;
|
||||||
let monero_wallet =
|
let monero_wallet =
|
||||||
@ -186,6 +194,10 @@ async fn main() -> Result<()> {
|
|||||||
alice_peer_id,
|
alice_peer_id,
|
||||||
alice_addr,
|
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 =
|
let bitcoin_wallet =
|
||||||
init_bitcoin_wallet(config, bitcoin_network, &wallet_data_dir, seed).await?;
|
init_bitcoin_wallet(config, bitcoin_network, &wallet_data_dir, seed).await?;
|
||||||
let monero_wallet =
|
let monero_wallet =
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
use anyhow::{Context, Result};
|
||||||
use libp2p::{core::Multiaddr, PeerId};
|
use libp2p::{core::Multiaddr, PeerId};
|
||||||
use std::path::PathBuf;
|
use std::{path::PathBuf, str::FromStr};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub const DEFAULT_ALICE_MULTIADDR: &str = "/dns4/xmr-btc-asb.coblox.tech/tcp/9876";
|
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")]
|
#[structopt(name = "xmr_btc-swap", about = "XMR BTC atomic swap")]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
BuyXmr {
|
BuyXmr {
|
||||||
#[structopt(long = "receive-address")]
|
#[structopt(long = "receive-address", parse(try_from_str = parse_monero_address))]
|
||||||
receive_monero_address: monero::Address,
|
receive_monero_address: monero::Address,
|
||||||
|
|
||||||
#[structopt(long = "connect-peer-id", default_value = DEFAULT_ALICE_PEER_ID)]
|
#[structopt(long = "connect-peer-id", default_value = DEFAULT_ALICE_PEER_ID)]
|
||||||
@ -39,7 +40,7 @@ pub enum Command {
|
|||||||
},
|
},
|
||||||
History,
|
History,
|
||||||
Resume {
|
Resume {
|
||||||
#[structopt(long = "receive-address")]
|
#[structopt(long = "receive-address", parse(try_from_str = parse_monero_address))]
|
||||||
receive_monero_address: monero::Address,
|
receive_monero_address: monero::Address,
|
||||||
|
|
||||||
#[structopt(long = "swap-id")]
|
#[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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::cli::command::{DEFAULT_ALICE_MULTIADDR, DEFAULT_ALICE_PEER_ID};
|
use crate::cli::command::{DEFAULT_ALICE_MULTIADDR, DEFAULT_ALICE_PEER_ID};
|
||||||
|
Loading…
Reference in New Issue
Block a user