mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-26 16:09:41 -05:00
Use tokio::select macro instead of function
This is slightly less verbose and therefore hopefully easier to read.
This commit is contained in:
parent
b1affe3ecf
commit
776a50137d
@ -10,8 +10,6 @@ use crate::protocol::alice::AliceState;
|
|||||||
use crate::{bitcoin, database, monero};
|
use crate::{bitcoin, database, monero};
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use async_recursion::async_recursion;
|
use async_recursion::async_recursion;
|
||||||
use futures::future::{select, Either};
|
|
||||||
use futures::pin_mut;
|
|
||||||
use rand::{CryptoRng, RngCore};
|
use rand::{CryptoRng, RngCore};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::select;
|
use tokio::select;
|
||||||
@ -297,11 +295,10 @@ async fn run_until_internal(
|
|||||||
let refund_tx_seen =
|
let refund_tx_seen =
|
||||||
bitcoin_wallet.watch_until_status(&tx_refund, |status| status.has_been_seen());
|
bitcoin_wallet.watch_until_status(&tx_refund, |status| status.has_been_seen());
|
||||||
|
|
||||||
pin_mut!(punish_tx_finalised);
|
select! {
|
||||||
pin_mut!(refund_tx_seen);
|
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 =
|
let published_refund_tx =
|
||||||
bitcoin_wallet.get_raw_transaction(tx_refund.txid()).await?;
|
bitcoin_wallet.get_raw_transaction(tx_refund.txid()).await?;
|
||||||
|
|
||||||
@ -317,10 +314,9 @@ async fn run_until_internal(
|
|||||||
monero_wallet_restore_blockheight,
|
monero_wallet_restore_blockheight,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Either::Left((Err(e), _)) => {
|
_ = punish_tx_finalised => {
|
||||||
bail!(e.context("Failed to monitor refund transaction"))
|
AliceState::BtcPunished
|
||||||
}
|
}
|
||||||
Either::Right(_) => AliceState::BtcPunished,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AliceState::XmrRefunded => AliceState::XmrRefunded,
|
AliceState::XmrRefunded => AliceState::XmrRefunded,
|
||||||
|
Loading…
Reference in New Issue
Block a user