diff --git a/swap/src/protocol/alice/swap.rs b/swap/src/protocol/alice/swap.rs index 6bfc8af1..a26474fb 100644 --- a/swap/src/protocol/alice/swap.rs +++ b/swap/src/protocol/alice/swap.rs @@ -8,37 +8,22 @@ use crate::protocol::alice::AliceState; use crate::protocol::alice::AliceState::XmrLockTransferProofSent; use crate::{bitcoin, database, monero}; use anyhow::{bail, Context, Result}; -use rand::{CryptoRng, RngCore}; use tokio::select; use tokio::time::timeout; use tracing::{error, info}; -trait Rng: RngCore + CryptoRng + Send {} - -impl Rng for T where T: RngCore + CryptoRng + Send {} - -pub fn is_complete(state: &AliceState) -> bool { - matches!( - state, - AliceState::XmrRefunded - | AliceState::BtcRedeemed - | AliceState::BtcPunished - | AliceState::SafelyAborted - ) -} - pub async fn run(swap: alice::Swap) -> Result { - run_until(swap, is_complete).await + run_until(swap, |_| false).await } -#[tracing::instrument(name = "swap", skip(swap,is_target_state), fields(id = %swap.swap_id))] +#[tracing::instrument(name = "swap", skip(swap,exit_early), fields(id = %swap.swap_id))] pub async fn run_until( mut swap: alice::Swap, - is_target_state: fn(&AliceState) -> bool, + exit_early: fn(&AliceState) -> bool, ) -> Result { let mut current_state = swap.state; - while !is_target_state(¤t_state) { + while !is_complete(¤t_state) && !exit_early(¤t_state) { current_state = next_state( current_state, &mut swap.event_loop_handle, @@ -372,3 +357,13 @@ async fn next_state( AliceState::SafelyAborted => AliceState::SafelyAborted, }) } + +fn is_complete(state: &AliceState) -> bool { + matches!( + state, + AliceState::XmrRefunded + | AliceState::BtcRedeemed + | AliceState::BtcPunished + | AliceState::SafelyAborted + ) +}