diff --git a/swap/src/alice.rs b/swap/src/alice.rs index 6611ad43..79c1060e 100644 --- a/swap/src/alice.rs +++ b/swap/src/alice.rs @@ -88,7 +88,6 @@ pub async fn swap( let (state2, channel) = match swarm.next().await { OutEvent::Message1 { msg, channel } => { - debug!("Got message1 from Bob"); let state2 = state1.receive(msg); (state2, channel) } diff --git a/swap/src/main.rs b/swap/src/main.rs index 7f427a8d..ce6ea418 100644 --- a/swap/src/main.rs +++ b/swap/src/main.rs @@ -104,7 +104,7 @@ async fn swap_as_alice( async fn swap_as_bob( sats: u64, - addr: Multiaddr, + alice: Multiaddr, refund: bitcoin::Address, wallet: W, ) -> Result<()> @@ -113,7 +113,8 @@ where { let (cmd_tx, mut cmd_rx) = mpsc::channel(1); let (mut rsp_tx, rsp_rx) = mpsc::channel(1); - tokio::spawn(bob::swap(sats, addr, cmd_tx, rsp_rx, refund, wallet)); + tokio::spawn(bob::swap(sats, alice, cmd_tx, rsp_rx, refund, wallet)); + loop { let read = cmd_rx.next().await; match read { @@ -139,16 +140,19 @@ fn verify(amounts: SwapAmounts) -> Rsp { println!("Got rate from Alice for XMR/BTC swap\n"); println!("{}", amounts); print!("Would you like to continue with this swap [y/N]: "); + let _ = io::stdout().flush(); io::stdin() .read_line(&mut s) .expect("Did not enter a correct string"); + if let Some('\n') = s.chars().next_back() { s.pop(); } if let Some('\r') = s.chars().next_back() { s.pop(); } + if !is_yes(&s) { println!("No worries, try again later - Alice updates her rate regularly"); return Rsp::Abort; diff --git a/swap/src/monero.rs b/swap/src/monero.rs index 43b571b8..c9ca0d30 100644 --- a/swap/src/monero.rs +++ b/swap/src/monero.rs @@ -1,10 +1,10 @@ -use serde::{de::Error, Deserialize, Deserializer, Serializer}; - -use xmr_btc::monero::Amount; +//! Monero stuff, for now just serde. +// This has to be in a sub-module to use with serde derive. pub mod amount_serde { - use super::*; + use serde::{de::Error, Deserialize, Deserializer, Serializer}; use std::str::FromStr; + use xmr_btc::monero::Amount; pub fn serialize(value: &Amount, serializer: S) -> Result where diff --git a/swap/src/network/request_response.rs b/swap/src/network/request_response.rs index 8e9f44b0..b0061a9b 100644 --- a/swap/src/network/request_response.rs +++ b/swap/src/network/request_response.rs @@ -13,6 +13,9 @@ use xmr_btc::{alice, bob, monero}; /// Time to wait for a response back once we send a request. pub const TIMEOUT: u64 = 3600; // One hour. +// TODO: Think about whether there is a better way to do this, e.g., separate +// Codec for each Message and a macro that implements them. + /// Messages Bob sends to Alice. #[derive(Clone, Debug, Serialize, Deserialize)] #[allow(clippy::large_enum_variant)] diff --git a/swap/src/network/transport.rs b/swap/src/network/transport.rs index 22392fd2..19da6c8f 100644 --- a/swap/src/network/transport.rs +++ b/swap/src/network/transport.rs @@ -14,6 +14,8 @@ use libp2p::{ yamux, PeerId, }; +// TOOD: Add the tor transport builder. + /// Builds a libp2p transport with the following features: /// - TcpConnection /// - DNS name resolution