diff --git a/swap/src/bitcoin/wallet.rs b/swap/src/bitcoin/wallet.rs index db1df5c2..76e17c98 100644 --- a/swap/src/bitcoin/wallet.rs +++ b/swap/src/bitcoin/wallet.rs @@ -1,5 +1,5 @@ use crate::{ - bitcoin::{timelocks::BlockHeight, Address, Amount, Transaction, TxLock}, + bitcoin::{timelocks::BlockHeight, Address, Amount, Transaction}, execution_params::ExecutionParams, }; use ::bitcoin::{util::psbt::PartiallySignedTransaction, Txid}; @@ -165,16 +165,15 @@ impl Wallet { Ok(txid) } - pub async fn sign_tx_lock(&self, tx_lock: TxLock) -> Result { - let txid = tx_lock.txid(); - tracing::debug!("signing tx lock: {}", txid); - let psbt = PartiallySignedTransaction::from(tx_lock); + pub async fn sign_and_finalize(&self, psbt: PartiallySignedTransaction) -> Result { let (signed_psbt, finalized) = self.inner.lock().await.sign(psbt, None)?; + if !finalized { - bail!("Could not finalize TxLock psbt") + bail!("PSBT is not finalized") } + let tx = signed_psbt.extract_tx(); - tracing::debug!("signed tx lock: {}", txid); + Ok(tx) } diff --git a/swap/src/protocol/bob/state.rs b/swap/src/protocol/bob/state.rs index f057d41c..f7e562ac 100644 --- a/swap/src/protocol/bob/state.rs +++ b/swap/src/protocol/bob/state.rs @@ -13,7 +13,7 @@ use crate::{ CROSS_CURVE_PROOF_SYSTEM, }, }; -use anyhow::{anyhow, bail, Result}; +use anyhow::{anyhow, bail, Context, Result}; use ecdsa_fun::{ adaptor::{Adaptor, HashTranscript}, nonce::Deterministic, @@ -269,9 +269,12 @@ impl State2 { } pub async fn lock_btc(self, bitcoin_wallet: &bitcoin::Wallet) -> Result { - let signed_tx_lock = bitcoin_wallet.sign_tx_lock(self.tx_lock.clone()).await?; + let signed_tx = bitcoin_wallet + .sign_and_finalize(self.tx_lock.clone().into()) + .await + .context("failed to sign Bitcoin lock transaction")?; - let _ = bitcoin_wallet.broadcast(signed_tx_lock, "lock").await?; + let _ = bitcoin_wallet.broadcast(signed_tx, "lock").await?; Ok(State3 { A: self.A,