Save state0 in the swarm to process message0

pull/41/head
Franck Royer 4 years ago
parent d8218a7bea
commit 2abeba17f9
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4

@ -71,16 +71,6 @@ pub async fn negotiate(
// TODO: get an ack from libp2p2
swarm.send_amounts(channel, amounts);
let event = timeout(*BOB_TIME_TO_ACT, swarm.next())
.await
.context("Failed to receive message 0 from Bob")?;
let message0 = match event {
OutEvent::Message0(msg) => msg,
other => bail!("Unexpected event received: {:?}", other),
};
let SwapAmounts { btc, xmr } = amounts;
let redeem_address = bitcoin_wallet.as_ref().new_address().await?;
let punish_address = redeem_address.clone();
@ -88,14 +78,27 @@ pub async fn negotiate(
a,
s_a,
v_a,
btc,
xmr,
amounts.btc,
amounts.xmr,
REFUND_TIMELOCK,
PUNISH_TIMELOCK,
redeem_address,
punish_address,
);
// TODO(Franck): Understand why this is needed.
swarm.set_state0(state0.clone());
let event = timeout(*BOB_TIME_TO_ACT, swarm.next())
.await
.context("Failed to receive message 0 from Bob")?;
let message0 = match event {
OutEvent::Message0(msg) => msg,
other => bail!("Unexpected event received: {:?}", other),
};
let SwapAmounts { btc, xmr } = amounts;
let state1 = state0.receive(message0)?;
let event = timeout(*BOB_TIME_TO_ACT, swarm.next())

Loading…
Cancel
Save