From 4421db7aad8758dfa7021e5f68f6e25a0f2ea565 Mon Sep 17 00:00:00 2001 From: patrini32 <171664803+patrini32@users.noreply.github.com> Date: Wed, 5 Jun 2024 13:04:05 +0300 Subject: [PATCH] Revert "introduce better approach for checking for error" This reverts commit 7844ad1483afe8830ef7119071b7307551592ae2. --- swap/src/cli/cancel_and_refund.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/swap/src/cli/cancel_and_refund.rs b/swap/src/cli/cancel_and_refund.rs index 549dddbe..c61bea45 100644 --- a/swap/src/cli/cancel_and_refund.rs +++ b/swap/src/cli/cancel_and_refund.rs @@ -1,4 +1,4 @@ -use crate::bitcoin::{parse_rpc_error_code, RpcErrorCode, Wallet}; +use crate::bitcoin::{parse_rpc_error_code, ExpiredTimelocks, RpcErrorCode, Wallet}; use crate::protocol::bob::BobState; use crate::protocol::Database; use anyhow::{bail, Result}; @@ -16,12 +16,11 @@ pub async fn cancel_and_refund( }; let state = match refund(swap_id, bitcoin_wallet, db).await { - Ok(s) => { - tracing::info!("Refund transaction submitted"); - s - } + Ok(s) => s, Err(e) => bail!(e), }; + + tracing::info!("Refund transaction submitted"); Ok(state) } @@ -65,10 +64,12 @@ pub async fn cancel( Err(err) => { if let Ok(error_code) = parse_rpc_error_code(&err) { if error_code == i64::from(RpcErrorCode::RpcVerifyError) { - if err - .to_string() - .contains("Failed to broadcast Bitcoin refund transaction") + if let ExpiredTimelocks::None { .. } = + state6.expired_timelock(bitcoin_wallet.as_ref()).await? { + tracing::debug!(%error_code, "parse rpc error"); + tracing::info!("General error trying to submit cancel transaction"); + } else { let txid = state6 .construct_tx_cancel() .expect("Error when constructing tx_cancel") @@ -78,9 +79,6 @@ pub async fn cancel( .await?; tracing::info!("Cancel transaction has already been confirmed on chain. The swap has therefore already been cancelled by Alice."); return Ok((txid, state)); - } else { - tracing::debug!(%error_code, "parse rpc error"); - tracing::info!("General error trying to submit cancel transaction"); } } }