introduce better approach for checking for error

This commit is contained in:
patrini32 2024-06-05 02:07:12 +03:00 committed by patrini32
parent a9a1724ad3
commit e2b6538199

View File

@ -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");
}
}
}