From 039db6babe6db7d24ebf622018bf3a0738c9f57e Mon Sep 17 00:00:00 2001 From: patrini32 <171664803+patrini32@users.noreply.github.com> Date: Wed, 5 Jun 2024 02:07:12 +0300 Subject: [PATCH] introduce better approach for checking for error --- swap/src/cli/cancel_and_refund.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/swap/src/cli/cancel_and_refund.rs b/swap/src/cli/cancel_and_refund.rs index c61bea45..549dddbe 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, ExpiredTimelocks, RpcErrorCode, Wallet}; +use crate::bitcoin::{parse_rpc_error_code, RpcErrorCode, Wallet}; use crate::protocol::bob::BobState; use crate::protocol::Database; use anyhow::{bail, Result}; @@ -16,11 +16,12 @@ pub async fn cancel_and_refund( }; let state = match refund(swap_id, bitcoin_wallet, db).await { - Ok(s) => s, + Ok(s) => { + tracing::info!("Refund transaction submitted"); + s + } Err(e) => bail!(e), }; - - tracing::info!("Refund transaction submitted"); Ok(state) } @@ -64,12 +65,10 @@ pub async fn cancel( Err(err) => { if let Ok(error_code) = parse_rpc_error_code(&err) { if error_code == i64::from(RpcErrorCode::RpcVerifyError) { - if let ExpiredTimelocks::None { .. } = - state6.expired_timelock(bitcoin_wallet.as_ref()).await? + if err + .to_string() + .contains("Failed to broadcast Bitcoin refund transaction") { - 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") @@ -79,6 +78,9 @@ 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"); } } }