mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-11-09 19:10:36 +00:00
Update swap.rs
This commit is contained in:
parent
26e66ce9b9
commit
ef75019ac6
@ -17,12 +17,12 @@ pub fn is_complete(state: &BobState) -> bool {
|
||||
)
|
||||
}
|
||||
|
||||
// Checks if this is a state where we should exit after
|
||||
// Checks if this is a state where we should exit after reaching it
|
||||
// but we don't want to prevent resuming the swap in this state
|
||||
// This is currently only used for the BtcPunished state because we might be able to
|
||||
// recover from this state by attempting a cooperative XMR redeem but it might also fail.
|
||||
// We want to avoid an infinite retry loop but also allow the user to retry manually by resuming the swap.
|
||||
pub fn is_exit_early(state: &BobState) -> bool {
|
||||
pub fn is_run_at_most_once(state: &BobState) -> bool {
|
||||
matches!(state, BobState::BtcPunished { .. })
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ pub async fn run_until(
|
||||
let mut current_state = swap.state.clone();
|
||||
|
||||
while !is_target_state(¤t_state) {
|
||||
current_state = next_state(
|
||||
let next_state = next_state(
|
||||
swap.id,
|
||||
current_state.clone(),
|
||||
&mut swap.event_loop_handle,
|
||||
@ -50,12 +50,14 @@ pub async fn run_until(
|
||||
.await?;
|
||||
|
||||
swap.db
|
||||
.insert_latest_state(swap.id, current_state.clone().into())
|
||||
.insert_latest_state(swap.id, next_state.clone().into())
|
||||
.await?;
|
||||
|
||||
if is_exit_early(¤t_state) {
|
||||
if is_run_at_most_once(¤t_state) && next_state == current_state {
|
||||
break;
|
||||
}
|
||||
|
||||
current_state = next_state;
|
||||
}
|
||||
|
||||
Ok(current_state)
|
||||
|
Loading…
Reference in New Issue
Block a user