diff --git a/swap/src/alice/execution.rs b/swap/src/alice/execution.rs index c1c83db4..aea07512 100644 --- a/swap/src/alice/execution.rs +++ b/swap/src/alice/execution.rs @@ -142,10 +142,10 @@ where .await .context("Failed to find lock Bitcoin tx")?; - // We saw the transaction in the mempool, waiting for it to be confirmed. - bitcoin_wallet - .wait_for_transaction_finality(lock_bitcoin_txid) - .await; + // // We saw the transaction in the mempool, waiting for it to be confirmed. + // bitcoin_wallet + // .wait_for_transaction_finality(lock_bitcoin_txid) + // .await; Ok(()) } @@ -235,8 +235,8 @@ where .broadcast_signed_transaction(redeem_tx) .await?; - // TODO(Franck): Not sure if we wait for finality here or just mined - bitcoin_wallet.wait_for_transaction_finality(tx_id).await; + // // TODO(Franck): Not sure if we wait for finality here or just mined + // bitcoin_wallet.wait_for_transaction_finality(tx_id).await; Ok(()) } @@ -370,7 +370,8 @@ where .broadcast_signed_transaction(punish_tx) .await?; - bitcoin_wallet.wait_for_transaction_finality(txid).await; + // todo: enable this once trait is implemented + // bitcoin_wallet.wait_for_transaction_finality(txid).await; Ok(txid) } diff --git a/swap/src/bob/execution.rs b/swap/src/bob/execution.rs index 0b0f2aab..86f839c2 100644 --- a/swap/src/bob/execution.rs +++ b/swap/src/bob/execution.rs @@ -3,24 +3,25 @@ use crate::{ Cmd, Rsp, SwapAmounts, }; use anyhow::Result; +use libp2p::core::Multiaddr; use rand::{CryptoRng, RngCore}; use std::sync::Arc; use tokio::{stream::StreamExt, sync::mpsc}; - use xmr_btc::bob::State2; pub async fn negotiate( state0: xmr_btc::bob::State0, amounts: SwapAmounts, swarm: &mut Swarm, + addr: Multiaddr, mut rng: R, bitcoin_wallet: Arc, ) -> Result<(SwapAmounts, State2)> where R: RngCore + CryptoRng + Send, { - // todo: dial the swarm outside - // libp2p::Swarm::dial_addr(&mut swarm, addr)?; + libp2p::Swarm::dial_addr(swarm, addr)?; + let alice = match swarm.next().await { OutEvent::ConnectionEstablished(alice) => alice, other => panic!("unexpected event: {:?}", other), diff --git a/swap/src/bob/swap.rs b/swap/src/bob/swap.rs index 603b8203..2a3a3a3f 100644 --- a/swap/src/bob/swap.rs +++ b/swap/src/bob/swap.rs @@ -5,9 +5,10 @@ use crate::{ }; use anyhow::Result; use async_recursion::async_recursion; -use libp2p::PeerId; +use libp2p::{core::Multiaddr, PeerId}; use rand::{CryptoRng, RngCore}; use std::sync::Arc; +use tracing::debug; use uuid::Uuid; use xmr_btc::bob::{self}; @@ -18,6 +19,7 @@ pub enum BobState { state0: bob::State0, amounts: SwapAmounts, peer_id: PeerId, + addr: Multiaddr, }, Negotiated(bob::State2, PeerId), BtcLocked(bob::State3, PeerId), @@ -50,11 +52,13 @@ where state0, amounts, peer_id, + addr, } => { let (swap_amounts, state2) = negotiate( state0, amounts, &mut swarm, + addr, &mut rng, bitcoin_wallet.clone(), ) @@ -118,6 +122,17 @@ where // should happen in this arm? swarm.send_message3(alice_peer_id.clone(), tx_redeem_encsig); + // Sadly we have to poll the swarm to get make sure the message is sent? + // FIXME: Having to wait for Alice's response here is a big problem, because + // we're stuck if she doesn't send her response back. I believe this is + // currently necessary, so we may have to rework this and/or how we use libp2p + match swarm.next().await { + OutEvent::Message3 => { + debug!("Got Message3 empty response"); + } + other => panic!("unexpected event: {:?}", other), + }; + swap( BobState::EncSigSent(state, alice_peer_id), swarm, diff --git a/swap/tests/e2e.rs b/swap/tests/e2e.rs index 66672874..656d4408 100644 --- a/swap/tests/e2e.rs +++ b/swap/tests/e2e.rs @@ -179,8 +179,6 @@ async fn simple_swap_happy_path() { )); let bob_xmr_wallet = Arc::new(swap::monero::Wallet(monero.wallet("bob").unwrap().client())); - // let redeem_address = bitcoin_wallet.as_ref().new_address().await?; - // let punish_address = redeem_address.clone(); let amounts = SwapAmounts { btc, xmr: xmr_btc::monero::Amount::from_piconero(xmr), @@ -201,7 +199,8 @@ async fn simple_swap_happy_path() { v_a, } }; - let alice_swarm = alice::new_swarm(alice_multiaddr, alice_transport, alice_behaviour).unwrap(); + let alice_swarm = + alice::new_swarm(alice_multiaddr.clone(), alice_transport, alice_behaviour).unwrap(); let alice_swap = alice::swap::swap( alice_state, alice_swarm, @@ -227,6 +226,7 @@ async fn simple_swap_happy_path() { state0, amounts, peer_id: alice_peer_id, + addr: alice_multiaddr, }; let bob_swarm = bob::new_swarm(bob_transport, bob_behaviour).unwrap(); let bob_swap = bob::swap::swap(