From 35d0e246d89810fa00ec3135b764a49472d68ccd Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Thu, 4 Mar 2021 10:46:12 +1100 Subject: [PATCH] Monero address network check Add a network check to ensure the given monero address is on the configured network. --- swap/src/bin/swap_cli.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/swap/src/bin/swap_cli.rs b/swap/src/bin/swap_cli.rs index 36f1326a..01f23f05 100644 --- a/swap/src/bin/swap_cli.rs +++ b/swap/src/bin/swap_cli.rs @@ -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 =