Do some more cleanups

This commit is contained in:
Tobin C. Harding 2020-10-22 13:48:30 +11:00
parent 2059158dad
commit 30298bdf1f
5 changed files with 15 additions and 7 deletions

View File

@ -88,7 +88,6 @@ pub async fn swap(
let (state2, channel) = match swarm.next().await { let (state2, channel) = match swarm.next().await {
OutEvent::Message1 { msg, channel } => { OutEvent::Message1 { msg, channel } => {
debug!("Got message1 from Bob");
let state2 = state1.receive(msg); let state2 = state1.receive(msg);
(state2, channel) (state2, channel)
} }

View File

@ -104,7 +104,7 @@ async fn swap_as_alice(
async fn swap_as_bob<W>( async fn swap_as_bob<W>(
sats: u64, sats: u64,
addr: Multiaddr, alice: Multiaddr,
refund: bitcoin::Address, refund: bitcoin::Address,
wallet: W, wallet: W,
) -> Result<()> ) -> Result<()>
@ -113,7 +113,8 @@ where
{ {
let (cmd_tx, mut cmd_rx) = mpsc::channel(1); let (cmd_tx, mut cmd_rx) = mpsc::channel(1);
let (mut rsp_tx, rsp_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 { loop {
let read = cmd_rx.next().await; let read = cmd_rx.next().await;
match read { match read {
@ -139,16 +140,19 @@ fn verify(amounts: SwapAmounts) -> Rsp {
println!("Got rate from Alice for XMR/BTC swap\n"); println!("Got rate from Alice for XMR/BTC swap\n");
println!("{}", amounts); println!("{}", amounts);
print!("Would you like to continue with this swap [y/N]: "); print!("Would you like to continue with this swap [y/N]: ");
let _ = io::stdout().flush(); let _ = io::stdout().flush();
io::stdin() io::stdin()
.read_line(&mut s) .read_line(&mut s)
.expect("Did not enter a correct string"); .expect("Did not enter a correct string");
if let Some('\n') = s.chars().next_back() { if let Some('\n') = s.chars().next_back() {
s.pop(); s.pop();
} }
if let Some('\r') = s.chars().next_back() { if let Some('\r') = s.chars().next_back() {
s.pop(); s.pop();
} }
if !is_yes(&s) { if !is_yes(&s) {
println!("No worries, try again later - Alice updates her rate regularly"); println!("No worries, try again later - Alice updates her rate regularly");
return Rsp::Abort; return Rsp::Abort;

View File

@ -1,10 +1,10 @@
use serde::{de::Error, Deserialize, Deserializer, Serializer}; //! Monero stuff, for now just serde.
use xmr_btc::monero::Amount;
// This has to be in a sub-module to use with serde derive.
pub mod amount_serde { pub mod amount_serde {
use super::*; use serde::{de::Error, Deserialize, Deserializer, Serializer};
use std::str::FromStr; use std::str::FromStr;
use xmr_btc::monero::Amount;
pub fn serialize<S>(value: &Amount, serializer: S) -> Result<S::Ok, S::Error> pub fn serialize<S>(value: &Amount, serializer: S) -> Result<S::Ok, S::Error>
where where

View File

@ -13,6 +13,9 @@ use xmr_btc::{alice, bob, monero};
/// Time to wait for a response back once we send a request. /// Time to wait for a response back once we send a request.
pub const TIMEOUT: u64 = 3600; // One hour. 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. /// Messages Bob sends to Alice.
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]

View File

@ -14,6 +14,8 @@ use libp2p::{
yamux, PeerId, yamux, PeerId,
}; };
// TOOD: Add the tor transport builder.
/// Builds a libp2p transport with the following features: /// Builds a libp2p transport with the following features:
/// - TcpConnection /// - TcpConnection
/// - DNS name resolution /// - DNS name resolution