From e29dd4dcf2c89e39690761cb1958c80a1fd7d6d1 Mon Sep 17 00:00:00 2001 From: Mohan <86064887+binarybaron@users.noreply.github.com> Date: Mon, 14 Jul 2025 22:04:17 +0200 Subject: [PATCH] feat(swap): Allow refunding manually Bitcoin even if we are in BobState::SwapSetupCompleted (#455) --- swap/src/cli/cancel_and_refund.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/swap/src/cli/cancel_and_refund.rs b/swap/src/cli/cancel_and_refund.rs index c9ef9461..296238a2 100644 --- a/swap/src/cli/cancel_and_refund.rs +++ b/swap/src/cli/cancel_and_refund.rs @@ -1,4 +1,5 @@ use crate::bitcoin::{ExpiredTimelocks, Wallet}; +use crate::monero::BlockHeight; use crate::protocol::bob::BobState; use crate::protocol::Database; use anyhow::{bail, Result}; @@ -31,6 +32,16 @@ pub async fn cancel( let state = db.get_state(swap_id).await?.try_into()?; let state6 = match state { + BobState::SwapSetupCompleted(state2) => { + // This is only useful if we **lost** the [`BtcLocked`] state (e.g due to a manual deletion of crash) + let state3 = state2.lock_btc().await?.0; + let assumed_tx_lock_id = state3.tx_lock_id(); + + tracing::warn!(%assumed_tx_lock_id, "We are trying to refund despite being in state SwapSetupCompleted. We have not locked the Bitcoin. We will attempt this but it is unlikely to work."); + + // We do not know the block height, so we set it to 0 + state3.cancel(BlockHeight { height: 0 }) + } BobState::BtcLocked { state3, monero_wallet_restore_blockheight,