Use tokio::select macro instead of function

This is slightly less verbose and therefore hopefully easier to read.
This commit is contained in:
Thomas Eizinger 2021-03-18 13:21:31 +11:00
parent b1affe3ecf
commit 776a50137d
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96

View File

@ -10,8 +10,6 @@ use crate::protocol::alice::AliceState;
use crate::{bitcoin, database, monero};
use anyhow::{bail, Context, Result};
use async_recursion::async_recursion;
use futures::future::{select, Either};
use futures::pin_mut;
use rand::{CryptoRng, RngCore};
use std::sync::Arc;
use tokio::select;
@ -297,11 +295,10 @@ async fn run_until_internal(
let refund_tx_seen =
bitcoin_wallet.watch_until_status(&tx_refund, |status| status.has_been_seen());
pin_mut!(punish_tx_finalised);
pin_mut!(refund_tx_seen);
select! {
result = refund_tx_seen => {
result.context("Failed to monitor refund transaction")?;
match select(refund_tx_seen, punish_tx_finalised).await {
Either::Left((Ok(()), _)) => {
let published_refund_tx =
bitcoin_wallet.get_raw_transaction(tx_refund.txid()).await?;
@ -317,10 +314,9 @@ async fn run_until_internal(
monero_wallet_restore_blockheight,
}
}
Either::Left((Err(e), _)) => {
bail!(e.context("Failed to monitor refund transaction"))
_ = punish_tx_finalised => {
AliceState::BtcPunished
}
Either::Right(_) => AliceState::BtcPunished,
}
}
AliceState::XmrRefunded => AliceState::XmrRefunded,