Save state0 in the swarm to process message0

This commit is contained in:
Franck Royer 2020-12-01 10:41:10 +11:00
parent d8218a7bea
commit 2abeba17f9
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4

View File

@ -71,6 +71,24 @@ pub async fn negotiate(
// TODO: get an ack from libp2p2
swarm.send_amounts(channel, amounts);
let redeem_address = bitcoin_wallet.as_ref().new_address().await?;
let punish_address = redeem_address.clone();
let state0 = State0::new(
a,
s_a,
v_a,
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")?;
@ -81,21 +99,6 @@ pub async fn negotiate(
let SwapAmounts { btc, xmr } = amounts;
let redeem_address = bitcoin_wallet.as_ref().new_address().await?;
let punish_address = redeem_address.clone();
let state0 = State0::new(
a,
s_a,
v_a,
btc,
xmr,
REFUND_TIMELOCK,
PUNISH_TIMELOCK,
redeem_address,
punish_address,
);
let state1 = state0.receive(message0)?;
let event = timeout(*BOB_TIME_TO_ACT, swarm.next())