From 25ebcf731dac589f79ccd70674674c6e44b56472 Mon Sep 17 00:00:00 2001 From: patrini32 <171664803+patrini32@users.noreply.github.com> Date: Wed, 5 Jun 2024 21:12:02 +0300 Subject: [PATCH] fix formatting --- swap/src/cli/cancel_and_refund.rs | 19 ++++++++++++------- swap/src/protocol/bob/state.rs | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/swap/src/cli/cancel_and_refund.rs b/swap/src/cli/cancel_and_refund.rs index 630fb9db..be7a6100 100644 --- a/swap/src/cli/cancel_and_refund.rs +++ b/swap/src/cli/cancel_and_refund.rs @@ -19,7 +19,8 @@ pub async fn cancel_and_refund( Ok(s) => s, Err(e) => bail!(e), }; - if matches!(state, BobState::BtcRefunded { .. }) { //Print success message only if refund succeeded. + if matches!(state, BobState::BtcRefunded { .. }) { + //Print success message only if refund succeeded. tracing::info!("Refund transaction submitted"); } Ok(state) @@ -65,14 +66,16 @@ 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 { .. } = // Check if timelock haven't expired. - state6.expired_timelock(bitcoin_wallet.as_ref()).await? + if let ExpiredTimelocks::None { .. } = // Check if timelock hasn't expired. + 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 { // Timelock expired and network rejected tx_cancel, so we are out-of-sync with Alice. (I assume that there's no other states under these conditions, am I right?) + } else { + // Timelock expired and network rejected tx_cancel, so we are out-of-sync with Alice. (I assume that there's no other states under these conditions, am I right?) let txid = state6 - .construct_tx_cancel() // Construct tx_cancel without broadcasting to the network, because swap has already been cancelled by Alice. + // Construct tx_cancel without broadcasting to the network, because swap has already been cancelled by Alice. + .construct_tx_cancel() .expect("Error when constructing tx_cancel") .txid(); let state = BobState::BtcCancelled(state6); // Set state to cancelled to sync with Alice. @@ -121,11 +124,13 @@ pub async fn refund( Err(error) => { if let Ok(error_code) = parse_rpc_error_code(&error) { if error_code == i64::from(RpcErrorCode::RpcVerifyError) { - if let ExpiredTimelocks::None { .. } = // Check if timelock haven't expired. + // Check if timelock hasn't expired. + if let ExpiredTimelocks::None { .. } = state6.expired_timelock(bitcoin_wallet.as_ref()).await? { bail!(error); - } else { // Timelock expired and network rejected refund, so we are out-of-sync with Alice. (I assume that there's no other states under these conditions, am I right?) + // Timelock expired and network rejected refund, so we are out-of-sync with Alice. (I assume that there's no other states under these conditions, am I right?) + } else { let state = BobState::BtcPunished { tx_lock_id: state6.tx_lock_id(), }; // Set state to punished. diff --git a/swap/src/protocol/bob/state.rs b/swap/src/protocol/bob/state.rs index 20c177fe..042257f8 100644 --- a/swap/src/protocol/bob/state.rs +++ b/swap/src/protocol/bob/state.rs @@ -663,7 +663,8 @@ impl State6 { Ok(tx) } - pub fn construct_tx_cancel(&self) -> Result { // Just construct the tx_cancel without broadcasting. + pub fn construct_tx_cancel(&self) -> Result { + // Just construct the tx_cancel without broadcasting. bitcoin::TxCancel::new( &self.tx_lock, self.cancel_timelock,