2020-12-14 10:15:52 +00:00
|
|
|
use anyhow::{bail, Result};
|
2020-11-12 00:06:34 +00:00
|
|
|
use async_recursion::async_recursion;
|
2020-11-30 02:25:11 +00:00
|
|
|
use rand::{CryptoRng, RngCore};
|
2021-01-07 23:52:07 +00:00
|
|
|
use std::sync::Arc;
|
2020-12-18 00:37:02 +00:00
|
|
|
use tokio::select;
|
2020-12-07 02:31:14 +00:00
|
|
|
use tracing::info;
|
2020-11-12 00:06:34 +00:00
|
|
|
use uuid::Uuid;
|
2021-01-05 03:08:36 +00:00
|
|
|
|
|
|
|
use crate::{
|
|
|
|
database::{Database, Swap},
|
|
|
|
protocol::bob::{self, event_loop::EventLoopHandle, state::*},
|
|
|
|
ExpiredTimelocks, SwapAmounts,
|
2020-12-11 05:49:19 +00:00
|
|
|
};
|
2020-11-12 00:06:34 +00:00
|
|
|
|
2020-12-18 06:39:04 +00:00
|
|
|
// TODO(Franck): Make this a method on a struct
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-12-02 01:09:43 +00:00
|
|
|
pub async fn swap<R>(
|
|
|
|
state: BobState,
|
2020-12-22 02:47:05 +00:00
|
|
|
event_loop_handle: EventLoopHandle,
|
2020-12-02 01:09:43 +00:00
|
|
|
db: Database,
|
|
|
|
bitcoin_wallet: Arc<crate::bitcoin::Wallet>,
|
|
|
|
monero_wallet: Arc<crate::monero::Wallet>,
|
|
|
|
rng: R,
|
|
|
|
swap_id: Uuid,
|
|
|
|
) -> Result<BobState>
|
2020-12-02 01:36:47 +00:00
|
|
|
where
|
|
|
|
R: RngCore + CryptoRng + Send,
|
2020-12-02 01:09:43 +00:00
|
|
|
{
|
2020-12-02 01:36:47 +00:00
|
|
|
run_until(
|
|
|
|
state,
|
|
|
|
is_complete,
|
2020-12-10 02:55:29 +00:00
|
|
|
event_loop_handle,
|
2020-12-02 01:36:47 +00:00
|
|
|
db,
|
|
|
|
bitcoin_wallet,
|
|
|
|
monero_wallet,
|
|
|
|
rng,
|
|
|
|
swap_id,
|
|
|
|
)
|
|
|
|
.await
|
2020-12-02 01:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_complete(state: &BobState) -> bool {
|
2020-12-02 01:36:47 +00:00
|
|
|
matches!(
|
|
|
|
state,
|
2020-12-11 05:49:19 +00:00
|
|
|
BobState::BtcRefunded(..)
|
2020-12-02 01:36:47 +00:00
|
|
|
| BobState::XmrRedeemed
|
2020-12-22 04:49:30 +00:00
|
|
|
| BobState::BtcPunished
|
2020-12-02 01:36:47 +00:00
|
|
|
| BobState::SafelyAborted
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_btc_locked(state: &BobState) -> bool {
|
|
|
|
matches!(state, BobState::BtcLocked(..))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_xmr_locked(state: &BobState) -> bool {
|
|
|
|
matches!(state, BobState::XmrLocked(..))
|
2020-12-02 01:09:43 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 11:16:39 +00:00
|
|
|
pub fn is_encsig_sent(state: &BobState) -> bool {
|
|
|
|
matches!(state, BobState::EncSigSent(..))
|
|
|
|
}
|
|
|
|
|
2020-11-12 00:06:34 +00:00
|
|
|
// State machine driver for swap execution
|
2020-12-02 01:36:47 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-11-12 00:06:34 +00:00
|
|
|
#[async_recursion]
|
2020-12-02 01:09:43 +00:00
|
|
|
pub async fn run_until<R>(
|
2020-11-12 00:06:34 +00:00
|
|
|
state: BobState,
|
2020-12-02 01:36:47 +00:00
|
|
|
is_target_state: fn(&BobState) -> bool,
|
2020-12-10 02:55:29 +00:00
|
|
|
mut event_loop_handle: EventLoopHandle,
|
2020-11-12 00:06:34 +00:00
|
|
|
db: Database,
|
|
|
|
bitcoin_wallet: Arc<crate::bitcoin::Wallet>,
|
|
|
|
monero_wallet: Arc<crate::monero::Wallet>,
|
2020-11-30 02:25:11 +00:00
|
|
|
mut rng: R,
|
2020-11-26 02:55:56 +00:00
|
|
|
swap_id: Uuid,
|
2020-11-30 02:25:11 +00:00
|
|
|
) -> Result<BobState>
|
|
|
|
where
|
|
|
|
R: RngCore + CryptoRng + Send,
|
|
|
|
{
|
2020-12-07 02:55:13 +00:00
|
|
|
info!("Current state: {}", state);
|
2020-12-02 01:36:47 +00:00
|
|
|
if is_target_state(&state) {
|
2020-12-02 01:09:43 +00:00
|
|
|
Ok(state)
|
|
|
|
} else {
|
|
|
|
match state {
|
2020-12-22 02:47:05 +00:00
|
|
|
BobState::Started { state0, amounts } => {
|
|
|
|
event_loop_handle.dial().await?;
|
2020-12-18 06:39:04 +00:00
|
|
|
|
2020-12-22 02:47:05 +00:00
|
|
|
let state2 = negotiate(
|
2020-12-02 01:09:43 +00:00
|
|
|
state0,
|
|
|
|
amounts,
|
2020-12-10 02:55:29 +00:00
|
|
|
&mut event_loop_handle,
|
2020-12-02 01:09:43 +00:00
|
|
|
&mut rng,
|
|
|
|
bitcoin_wallet.clone(),
|
|
|
|
)
|
2020-12-02 01:36:47 +00:00
|
|
|
.await?;
|
2020-12-08 03:54:08 +00:00
|
|
|
|
2020-12-22 02:47:05 +00:00
|
|
|
let state = BobState::Negotiated(state2);
|
2020-12-08 03:54:08 +00:00
|
|
|
let db_state = state.clone().into();
|
2021-01-05 03:08:36 +00:00
|
|
|
db.insert_latest_state(swap_id, Swap::Bob(db_state)).await?;
|
2020-12-02 01:09:43 +00:00
|
|
|
run_until(
|
2020-12-08 03:54:08 +00:00
|
|
|
state,
|
2020-12-02 01:36:47 +00:00
|
|
|
is_target_state,
|
2020-12-10 02:55:29 +00:00
|
|
|
event_loop_handle,
|
2020-12-02 01:09:43 +00:00
|
|
|
db,
|
|
|
|
bitcoin_wallet,
|
|
|
|
monero_wallet,
|
|
|
|
rng,
|
|
|
|
swap_id,
|
|
|
|
)
|
2020-12-02 01:36:47 +00:00
|
|
|
.await
|
2020-12-02 01:09:43 +00:00
|
|
|
}
|
2020-12-22 02:47:05 +00:00
|
|
|
BobState::Negotiated(state2) => {
|
2020-12-18 06:39:04 +00:00
|
|
|
// Do not lock Bitcoin if not connected to Alice.
|
2020-12-22 02:47:05 +00:00
|
|
|
event_loop_handle.dial().await?;
|
2020-12-02 01:09:43 +00:00
|
|
|
// Alice and Bob have exchanged info
|
|
|
|
let state3 = state2.lock_btc(bitcoin_wallet.as_ref()).await?;
|
2020-12-08 03:54:08 +00:00
|
|
|
|
2020-12-22 02:47:05 +00:00
|
|
|
let state = BobState::BtcLocked(state3);
|
2020-12-08 03:54:08 +00:00
|
|
|
let db_state = state.clone().into();
|
2021-01-05 03:08:36 +00:00
|
|
|
db.insert_latest_state(swap_id, Swap::Bob(db_state)).await?;
|
2020-12-02 01:09:43 +00:00
|
|
|
run_until(
|
2020-12-08 03:54:08 +00:00
|
|
|
state,
|
2020-12-02 01:36:47 +00:00
|
|
|
is_target_state,
|
2020-12-10 02:55:29 +00:00
|
|
|
event_loop_handle,
|
2020-12-02 01:09:43 +00:00
|
|
|
db,
|
|
|
|
bitcoin_wallet,
|
|
|
|
monero_wallet,
|
|
|
|
rng,
|
|
|
|
swap_id,
|
|
|
|
)
|
2020-12-02 01:36:47 +00:00
|
|
|
.await
|
2020-12-02 01:09:43 +00:00
|
|
|
}
|
|
|
|
// Bob has locked Btc
|
2020-12-22 04:47:09 +00:00
|
|
|
// Watch for Alice to Lock Xmr or for cancel timelock to elapse
|
2020-12-22 02:47:05 +00:00
|
|
|
BobState::BtcLocked(state3) => {
|
2020-12-22 04:47:09 +00:00
|
|
|
let state = if let ExpiredTimelocks::None =
|
|
|
|
state3.current_epoch(bitcoin_wallet.as_ref()).await?
|
2020-12-21 06:33:18 +00:00
|
|
|
{
|
|
|
|
event_loop_handle.dial().await?;
|
2020-12-18 06:39:04 +00:00
|
|
|
|
2020-12-22 06:08:17 +00:00
|
|
|
let msg2_watcher = event_loop_handle.recv_message2();
|
2020-12-22 04:47:09 +00:00
|
|
|
let cancel_timelock_expires =
|
|
|
|
state3.wait_for_cancel_timelock_to_expire(bitcoin_wallet.as_ref());
|
2020-12-07 02:31:14 +00:00
|
|
|
|
2021-01-06 05:31:47 +00:00
|
|
|
// Record the current monero wallet block height so we don't have to scan from
|
|
|
|
// block 0 once we create the redeem wallet.
|
|
|
|
// TODO: This can be optimized further by extracting the block height when
|
|
|
|
// tx-lock was included. However, scanning a few more blocks won't do any harm
|
|
|
|
// and is simpler.
|
|
|
|
let monero_wallet_restore_blockheight =
|
|
|
|
monero_wallet.inner.block_height().await?;
|
|
|
|
|
2020-12-22 06:08:17 +00:00
|
|
|
select! {
|
|
|
|
msg2 = msg2_watcher => {
|
|
|
|
|
|
|
|
let xmr_lock_watcher = state3.clone()
|
2021-01-06 05:31:47 +00:00
|
|
|
.watch_for_lock_xmr(monero_wallet.as_ref(), msg2?, monero_wallet_restore_blockheight.height);
|
2020-12-22 04:47:09 +00:00
|
|
|
let cancel_timelock_expires = state3.wait_for_cancel_timelock_to_expire(bitcoin_wallet.as_ref());
|
2020-12-22 06:08:17 +00:00
|
|
|
|
|
|
|
select! {
|
|
|
|
state4 = xmr_lock_watcher => {
|
|
|
|
BobState::XmrLocked(state4?)
|
|
|
|
},
|
2020-12-22 04:47:09 +00:00
|
|
|
_ = cancel_timelock_expires => {
|
|
|
|
let state4 = state3.state4();
|
|
|
|
BobState::CancelTimelockExpired(state4)
|
2020-12-22 06:08:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
2020-12-22 04:47:09 +00:00
|
|
|
_ = cancel_timelock_expires => {
|
|
|
|
let state4 = state3.state4();
|
|
|
|
BobState::CancelTimelockExpired(state4)
|
2020-12-22 06:08:17 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-21 06:33:18 +00:00
|
|
|
} else {
|
2020-12-22 04:47:09 +00:00
|
|
|
let state4 = state3.state4();
|
|
|
|
BobState::CancelTimelockExpired(state4)
|
2020-12-21 06:33:18 +00:00
|
|
|
};
|
2020-12-08 03:54:08 +00:00
|
|
|
let db_state = state.clone().into();
|
2021-01-05 03:08:36 +00:00
|
|
|
db.insert_latest_state(swap_id, Swap::Bob(db_state)).await?;
|
2020-12-02 01:09:43 +00:00
|
|
|
run_until(
|
2020-12-08 03:54:08 +00:00
|
|
|
state,
|
2020-12-02 01:36:47 +00:00
|
|
|
is_target_state,
|
2020-12-10 02:55:29 +00:00
|
|
|
event_loop_handle,
|
2020-12-02 01:09:43 +00:00
|
|
|
db,
|
|
|
|
bitcoin_wallet,
|
|
|
|
monero_wallet,
|
|
|
|
rng,
|
|
|
|
swap_id,
|
|
|
|
)
|
2020-12-02 01:36:47 +00:00
|
|
|
.await
|
2020-12-02 01:09:43 +00:00
|
|
|
}
|
2020-12-22 02:47:05 +00:00
|
|
|
BobState::XmrLocked(state) => {
|
2020-12-22 04:47:09 +00:00
|
|
|
let state = if let ExpiredTimelocks::None =
|
|
|
|
state.expired_timelock(bitcoin_wallet.as_ref()).await?
|
|
|
|
{
|
2020-12-21 06:33:18 +00:00
|
|
|
event_loop_handle.dial().await?;
|
2020-12-17 04:17:15 +00:00
|
|
|
// Alice has locked Xmr
|
|
|
|
// Bob sends Alice his key
|
|
|
|
let tx_redeem_encsig = state.tx_redeem_encsig();
|
|
|
|
|
|
|
|
let state4_clone = state.clone();
|
2020-12-18 06:39:04 +00:00
|
|
|
// TODO(Franck): Refund if message cannot be sent.
|
2020-12-22 02:47:05 +00:00
|
|
|
let enc_sig_sent_watcher = event_loop_handle.send_message3(tx_redeem_encsig);
|
2020-12-17 04:17:15 +00:00
|
|
|
let bitcoin_wallet = bitcoin_wallet.clone();
|
2020-12-22 04:47:09 +00:00
|
|
|
let cancel_timelock_expires =
|
|
|
|
state4_clone.wait_for_cancel_timelock_to_expire(bitcoin_wallet.as_ref());
|
2020-12-17 04:17:15 +00:00
|
|
|
|
2020-12-18 00:37:02 +00:00
|
|
|
select! {
|
|
|
|
_ = enc_sig_sent_watcher => {
|
2020-12-18 06:39:04 +00:00
|
|
|
BobState::EncSigSent(state)
|
2020-12-18 00:37:02 +00:00
|
|
|
},
|
2020-12-22 04:47:09 +00:00
|
|
|
_ = cancel_timelock_expires => {
|
|
|
|
BobState::CancelTimelockExpired(state)
|
2020-12-18 00:37:02 +00:00
|
|
|
}
|
2020-12-17 04:17:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-12-22 04:47:09 +00:00
|
|
|
BobState::CancelTimelockExpired(state)
|
2020-12-17 04:17:15 +00:00
|
|
|
};
|
2020-12-08 03:54:08 +00:00
|
|
|
let db_state = state.clone().into();
|
2021-01-05 03:08:36 +00:00
|
|
|
db.insert_latest_state(swap_id, Swap::Bob(db_state)).await?;
|
2020-12-02 01:09:43 +00:00
|
|
|
run_until(
|
2020-12-08 03:54:08 +00:00
|
|
|
state,
|
2020-12-02 01:36:47 +00:00
|
|
|
is_target_state,
|
2020-12-10 02:55:29 +00:00
|
|
|
event_loop_handle,
|
2020-12-02 01:09:43 +00:00
|
|
|
db,
|
|
|
|
bitcoin_wallet,
|
|
|
|
monero_wallet,
|
|
|
|
rng,
|
|
|
|
swap_id,
|
|
|
|
)
|
2020-12-02 01:36:47 +00:00
|
|
|
.await
|
2020-12-02 01:09:43 +00:00
|
|
|
}
|
2020-12-18 06:39:04 +00:00
|
|
|
BobState::EncSigSent(state) => {
|
2020-12-22 04:47:09 +00:00
|
|
|
let state = if let ExpiredTimelocks::None =
|
|
|
|
state.expired_timelock(bitcoin_wallet.as_ref()).await?
|
|
|
|
{
|
2020-12-17 04:17:15 +00:00
|
|
|
let state_clone = state.clone();
|
|
|
|
let redeem_watcher = state_clone.watch_for_redeem_btc(bitcoin_wallet.as_ref());
|
2020-12-22 04:47:09 +00:00
|
|
|
let cancel_timelock_expires =
|
|
|
|
state_clone.wait_for_cancel_timelock_to_expire(bitcoin_wallet.as_ref());
|
2020-12-15 05:44:13 +00:00
|
|
|
|
2020-12-18 00:37:02 +00:00
|
|
|
select! {
|
|
|
|
state5 = redeem_watcher => {
|
|
|
|
BobState::BtcRedeemed(state5?)
|
|
|
|
},
|
2020-12-22 04:47:09 +00:00
|
|
|
_ = cancel_timelock_expires => {
|
|
|
|
BobState::CancelTimelockExpired(state)
|
2020-12-18 00:37:02 +00:00
|
|
|
}
|
2020-12-02 01:36:47 +00:00
|
|
|
}
|
2020-12-17 04:17:15 +00:00
|
|
|
} else {
|
2020-12-22 04:47:09 +00:00
|
|
|
BobState::CancelTimelockExpired(state)
|
2020-12-15 05:44:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let db_state = state.clone().into();
|
2021-01-05 03:08:36 +00:00
|
|
|
db.insert_latest_state(swap_id, Swap::Bob(db_state)).await?;
|
2020-12-15 05:44:13 +00:00
|
|
|
run_until(
|
|
|
|
state,
|
|
|
|
is_target_state,
|
|
|
|
event_loop_handle,
|
|
|
|
db,
|
|
|
|
bitcoin_wallet.clone(),
|
|
|
|
monero_wallet,
|
|
|
|
rng,
|
|
|
|
swap_id,
|
|
|
|
)
|
|
|
|
.await
|
2020-11-12 00:06:34 +00:00
|
|
|
}
|
2020-12-02 01:09:43 +00:00
|
|
|
BobState::BtcRedeemed(state) => {
|
|
|
|
// Bob redeems XMR using revealed s_a
|
|
|
|
state.claim_xmr(monero_wallet.as_ref()).await?;
|
2020-12-08 03:54:08 +00:00
|
|
|
|
|
|
|
let state = BobState::XmrRedeemed;
|
|
|
|
let db_state = state.clone().into();
|
2021-01-05 03:08:36 +00:00
|
|
|
db.insert_latest_state(swap_id, Swap::Bob(db_state)).await?;
|
2020-12-02 01:09:43 +00:00
|
|
|
run_until(
|
2020-12-08 03:54:08 +00:00
|
|
|
state,
|
2020-12-02 01:36:47 +00:00
|
|
|
is_target_state,
|
2020-12-10 02:55:29 +00:00
|
|
|
event_loop_handle,
|
2020-12-02 01:09:43 +00:00
|
|
|
db,
|
|
|
|
bitcoin_wallet,
|
|
|
|
monero_wallet,
|
|
|
|
rng,
|
|
|
|
swap_id,
|
|
|
|
)
|
2020-12-02 01:36:47 +00:00
|
|
|
.await
|
|
|
|
}
|
2020-12-22 04:47:09 +00:00
|
|
|
BobState::CancelTimelockExpired(state4) => {
|
2020-12-17 04:17:15 +00:00
|
|
|
if state4
|
|
|
|
.check_for_tx_cancel(bitcoin_wallet.as_ref())
|
|
|
|
.await
|
|
|
|
.is_err()
|
|
|
|
{
|
|
|
|
state4.submit_tx_cancel(bitcoin_wallet.as_ref()).await?;
|
|
|
|
}
|
|
|
|
|
2020-12-22 04:49:30 +00:00
|
|
|
let state = BobState::BtcCancelled(state4);
|
2021-01-05 03:08:36 +00:00
|
|
|
db.insert_latest_state(swap_id, Swap::Bob(state.clone().into()))
|
2020-12-17 04:17:15 +00:00
|
|
|
.await?;
|
|
|
|
|
|
|
|
run_until(
|
|
|
|
state,
|
|
|
|
is_target_state,
|
|
|
|
event_loop_handle,
|
|
|
|
db,
|
|
|
|
bitcoin_wallet,
|
|
|
|
monero_wallet,
|
|
|
|
rng,
|
|
|
|
swap_id,
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
}
|
2020-12-22 04:49:30 +00:00
|
|
|
BobState::BtcCancelled(state) => {
|
2020-12-02 01:36:47 +00:00
|
|
|
// Bob has cancelled the swap
|
2020-12-22 04:47:09 +00:00
|
|
|
let state = match state.expired_timelock(bitcoin_wallet.as_ref()).await? {
|
|
|
|
ExpiredTimelocks::None => {
|
|
|
|
bail!("Internal error: canceled state reached before cancel timelock was expired");
|
|
|
|
}
|
|
|
|
ExpiredTimelocks::Cancel => {
|
2020-12-11 01:34:20 +00:00
|
|
|
state.refund_btc(bitcoin_wallet.as_ref()).await?;
|
2020-12-08 03:54:08 +00:00
|
|
|
BobState::BtcRefunded(state)
|
2020-12-11 01:34:20 +00:00
|
|
|
}
|
2020-12-22 04:49:30 +00:00
|
|
|
ExpiredTimelocks::Punish => BobState::BtcPunished,
|
2020-12-08 03:54:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let db_state = state.clone().into();
|
2021-01-05 03:08:36 +00:00
|
|
|
db.insert_latest_state(swap_id, Swap::Bob(db_state)).await?;
|
2020-12-08 03:54:08 +00:00
|
|
|
run_until(
|
|
|
|
state,
|
|
|
|
is_target_state,
|
|
|
|
event_loop_handle,
|
|
|
|
db,
|
|
|
|
bitcoin_wallet,
|
|
|
|
monero_wallet,
|
|
|
|
rng,
|
|
|
|
swap_id,
|
|
|
|
)
|
|
|
|
.await
|
2020-12-02 01:36:47 +00:00
|
|
|
}
|
2020-12-11 05:49:19 +00:00
|
|
|
BobState::BtcRefunded(state4) => Ok(BobState::BtcRefunded(state4)),
|
2020-12-22 04:49:30 +00:00
|
|
|
BobState::BtcPunished => Ok(BobState::BtcPunished),
|
2020-12-10 00:51:58 +00:00
|
|
|
BobState::SafelyAborted => Ok(BobState::SafelyAborted),
|
|
|
|
BobState::XmrRedeemed => Ok(BobState::XmrRedeemed),
|
2020-11-12 00:06:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-15 05:53:50 +00:00
|
|
|
|
|
|
|
pub async fn negotiate<R>(
|
2021-01-05 03:08:36 +00:00
|
|
|
state0: crate::protocol::bob::state::State0,
|
2020-12-15 05:53:50 +00:00
|
|
|
amounts: SwapAmounts,
|
|
|
|
swarm: &mut EventLoopHandle,
|
|
|
|
mut rng: R,
|
|
|
|
bitcoin_wallet: Arc<crate::bitcoin::Wallet>,
|
2021-01-05 03:08:36 +00:00
|
|
|
) -> Result<bob::state::State2>
|
2020-12-15 05:53:50 +00:00
|
|
|
where
|
|
|
|
R: RngCore + CryptoRng + Send,
|
|
|
|
{
|
|
|
|
tracing::trace!("Starting negotiate");
|
2020-12-22 02:47:05 +00:00
|
|
|
swarm.request_amounts(amounts.btc).await?;
|
2020-12-15 05:53:50 +00:00
|
|
|
|
2020-12-22 02:47:05 +00:00
|
|
|
swarm.send_message0(state0.next_message(&mut rng)).await?;
|
2020-12-15 05:53:50 +00:00
|
|
|
let msg0 = swarm.recv_message0().await?;
|
|
|
|
let state1 = state0.receive(bitcoin_wallet.as_ref(), msg0).await?;
|
|
|
|
|
2020-12-22 02:47:05 +00:00
|
|
|
swarm.send_message1(state1.next_message()).await?;
|
2020-12-15 05:53:50 +00:00
|
|
|
let msg1 = swarm.recv_message1().await?;
|
|
|
|
let state2 = state1.receive(msg1)?;
|
|
|
|
|
2020-12-22 02:47:05 +00:00
|
|
|
swarm.send_message2(state2.next_message()).await?;
|
2020-12-15 05:53:50 +00:00
|
|
|
|
2020-12-22 02:47:05 +00:00
|
|
|
Ok(state2)
|
2020-12-15 05:53:50 +00:00
|
|
|
}
|