From 075db8164e6aefdb1f1d23b2b5c645064b1c6813 Mon Sep 17 00:00:00 2001 From: patrini32 <171664803+patrini32@users.noreply.github.com> Date: Wed, 12 Jun 2024 23:08:01 +0300 Subject: [PATCH] fix error --- swap/src/cli/cancel_and_refund.rs | 1 + swap/src/protocol/bob/state.rs | 22 +++++++++------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/swap/src/cli/cancel_and_refund.rs b/swap/src/cli/cancel_and_refund.rs index 092c4979..12588ca6 100644 --- a/swap/src/cli/cancel_and_refund.rs +++ b/swap/src/cli/cancel_and_refund.rs @@ -83,6 +83,7 @@ pub async fn cancel( tracing::info!("General error trying to submit cancel transaction"); } let state = BobState::BtcCancelled(state6); + let txid = state6.construct_tx_cancel().txid(); db.insert_latest_state(swap_id, state.clone().into()) .await?; Ok((txid, state)) diff --git a/swap/src/protocol/bob/state.rs b/swap/src/protocol/bob/state.rs index 58c1d723..9c15626d 100644 --- a/swap/src/protocol/bob/state.rs +++ b/swap/src/protocol/bob/state.rs @@ -646,18 +646,20 @@ impl State6 { tx_cancel_status, )) } - - pub async fn check_for_tx_cancel( - &self, - bitcoin_wallet: &bitcoin::Wallet, - ) -> Result { - let tx_cancel = bitcoin::TxCancel::new( + pub async fn construct_tx_cancel(&self) -> Result { + bitcoin::TxCancel::new( &self.tx_lock, self.cancel_timelock, self.A, self.b.public(), self.tx_cancel_fee, )?; + } + pub async fn check_for_tx_cancel( + &self, + bitcoin_wallet: &bitcoin::Wallet, + ) -> Result { + let tx_cancel = self.construct_tx_cancel()?; let tx = bitcoin_wallet.get_raw_transaction(tx_cancel.txid()).await?; @@ -668,13 +670,7 @@ impl State6 { &self, bitcoin_wallet: &bitcoin::Wallet, ) -> Result<(Txid, Subscription)> { - let transaction = bitcoin::TxCancel::new( - &self.tx_lock, - self.cancel_timelock, - self.A, - self.b.public(), - self.tx_cancel_fee, - )? + let transaction = self.construct_tx_cancel()? .complete_as_bob(self.A, self.b.clone(), self.tx_cancel_sig_a.clone()) .context("Failed to complete Bitcoin cancel transaction")?;