From 1584ac7d838396a30470e0c439d68a4745d3c058 Mon Sep 17 00:00:00 2001 From: patrini32 <171664803+patrini32@users.noreply.github.com> Date: Wed, 12 Jun 2024 22:59:24 +0300 Subject: [PATCH] Better error messages --- swap/src/cli/cancel_and_refund.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/swap/src/cli/cancel_and_refund.rs b/swap/src/cli/cancel_and_refund.rs index 7b773e1e..092c4979 100644 --- a/swap/src/cli/cancel_and_refund.rs +++ b/swap/src/cli/cancel_and_refund.rs @@ -71,21 +71,24 @@ pub async fn cancel( .await?; tracing::info!("Cancel transaction has already been confirmed on chain"); return Ok((tx.txid(), state)); - } - if let ExpiredTimelocks::None { .. } = + } else if let ExpiredTimelocks::None { .. } = state6.expired_timelock(bitcoin_wallet.as_ref()).await? { - bail!("Cancel timelock hasn't expired yet"); - } - if let Ok(error_code) = parse_rpc_error_code(&err) { + bail!("Cancel timelock hasn't expired yet. Bob tried to cancel the swap too early"); + } else if let Ok(error_code) = parse_rpc_error_code(&err) { tracing::debug!(%error_code, "parse rpc error"); if error_code == i64::from(RpcErrorCode::RpcVerifyAlreadyInChain) { tracing::info!("Cancel transaction has already been confirmed on chain"); } else if error_code == i64::from(RpcErrorCode::RpcVerifyError) { tracing::info!("General error trying to submit cancel transaction"); } + let state = BobState::BtcCancelled(state6); + db.insert_latest_state(swap_id, state.clone().into()) + .await?; + Ok((txid, state)) + } else { + bail!("Error while trying to submit cancel transaction, this shouldn't have happened. {}", err); } - bail!(err); } } }