Use Message4

This commit is contained in:
Franck Royer 2021-01-22 14:21:27 +11:00
parent 124d6f1ebb
commit d2a1937f51
No known key found for this signature in database
GPG key ID: A82ED75A8DFC50A4
13 changed files with 211 additions and 107 deletions

View file

@ -10,10 +10,9 @@ use crate::{
config::Config,
monero,
monero::Transfer,
network::request_response::AliceToBob,
protocol::{
alice,
alice::{event_loop::EventLoopHandle, SwapResponse},
alice::{event_loop::EventLoopHandle, Message4, SwapResponse},
SwapAmounts,
},
};
@ -23,7 +22,7 @@ use futures::{
future::{select, Either},
pin_mut,
};
use libp2p::request_response::ResponseChannel;
use libp2p::PeerId;
use rand::rngs::OsRng;
use sha2::Sha256;
use std::sync::Arc;
@ -35,11 +34,11 @@ pub async fn negotiate(
xmr_amount: monero::Amount,
event_loop_handle: &mut EventLoopHandle,
config: Config,
) -> Result<(ResponseChannel<AliceToBob>, alice::State3)> {
) -> Result<(PeerId, alice::State3)> {
trace!("Starting negotiate");
// todo: we can move this out, we dont need to timeout here
let _peer_id = timeout(
let bob_peer_id = timeout(
config.bob_time_to_act,
event_loop_handle.recv_conn_established(),
)
@ -73,12 +72,11 @@ pub async fn negotiate(
.send_message1(channel, state2.next_message())
.await?;
let (bob_message2, channel) =
timeout(config.bob_time_to_act, event_loop_handle.recv_message2()).await??;
let bob_message2 = timeout(config.bob_time_to_act, event_loop_handle.recv_message2()).await??;
let state3 = state2.receive(bob_message2)?;
Ok((channel, state3))
Ok((bob_peer_id, state3))
}
// TODO(Franck): Use helper functions from xmr-btc instead of re-writing them
@ -108,7 +106,7 @@ where
}
pub async fn lock_xmr<W>(
channel: ResponseChannel<AliceToBob>,
bob_peer_id: PeerId,
amounts: SwapAmounts,
state3: alice::State3,
event_loop_handle: &mut EventLoopHandle,
@ -134,7 +132,7 @@ where
// Otherwise Alice might publish the lock tx twice!
event_loop_handle
.send_message2(channel, alice::Message2 {
.send_message4(bob_peer_id, Message4 {
tx_lock_proof: transfer_proof,
})
.await?;