diff --git a/swap/src/alice/swap.rs b/swap/src/alice/swap.rs index 87deec4b..cc5e421a 100644 --- a/swap/src/alice/swap.rs +++ b/swap/src/alice/swap.rs @@ -45,12 +45,12 @@ pub enum AliceState { state0: State0, }, Negotiated { - channel: ResponseChannel, + channel: Option>, amounts: SwapAmounts, state3: State3, }, BtcLocked { - channel: ResponseChannel, + channel: Option>, amounts: SwapAmounts, state3: State3, }, @@ -159,7 +159,7 @@ pub async fn run_until( run_until( AliceState::Negotiated { - channel, + channel: Some(channel), amounts, state3, }, @@ -176,48 +176,84 @@ pub async fn run_until( channel, amounts, } => { - let _ = - wait_for_locked_bitcoin(state3.tx_lock.txid(), bitcoin_wallet.clone(), config) + match channel { + Some(channel) => { + let _ = wait_for_locked_bitcoin( + state3.tx_lock.txid(), + bitcoin_wallet.clone(), + config, + ) .await?; - run_until( - AliceState::BtcLocked { - channel, - amounts, - state3, - }, - is_target_state, - event_loop_handle, - bitcoin_wallet, - monero_wallet, - config, - ) - .await + run_until( + AliceState::BtcLocked { + channel: Some(channel), + amounts, + state3, + }, + is_target_state, + event_loop_handle, + bitcoin_wallet, + monero_wallet, + config, + ) + .await + } + None => { + tracing::info!("Cannot resume swap from negotiated state, aborting"); + + // Alice did not lock Xmr yet + run_until( + AliceState::SafelyAborted, + is_target_state, + event_loop_handle, + bitcoin_wallet, + monero_wallet, + config, + ) + .await + } + } } AliceState::BtcLocked { channel, amounts, state3, - } => { - lock_xmr( - channel, - amounts, - state3.clone(), - &mut event_loop_handle, - monero_wallet.clone(), - ) - .await?; + } => match channel { + Some(channel) => { + lock_xmr( + channel, + amounts, + state3.clone(), + &mut event_loop_handle, + monero_wallet.clone(), + ) + .await?; - run_until( - AliceState::XmrLocked { state3 }, - is_target_state, - event_loop_handle, - bitcoin_wallet, - monero_wallet, - config, - ) - .await - } + run_until( + AliceState::XmrLocked { state3 }, + is_target_state, + event_loop_handle, + bitcoin_wallet, + monero_wallet, + config, + ) + .await + } + None => { + tracing::info!("Cannot resume swap from BTC locked state, aborting"); + + // Alice did not lock Xmr yet + swap( + AliceState::SafelyAborted, + event_loop_handle, + bitcoin_wallet, + monero_wallet, + config, + ) + .await + } + }, AliceState::XmrLocked { state3 } => { // todo: match statement and wait for t1 can probably be expressed more cleanly match state3.current_epoch(bitcoin_wallet.as_ref()).await? {