diff --git a/swap/src/api/request.rs b/swap/src/api/request.rs index 75c2d400..acf6777b 100644 --- a/swap/src/api/request.rs +++ b/swap/src/api/request.rs @@ -228,6 +228,7 @@ impl Request { tx_lock_id, tx_cancel_fee, tx_refund_fee, + tx_lock_fee, btc_refund_address, cancel_timelock, punish_timelock, @@ -245,16 +246,23 @@ impl Request { let tx_lock_id = state2.tx_lock.txid(); let btc_refund_address = state2.refund_address.to_string(); - Some(( - xmr_amount, - btc_amount, - tx_lock_id, - tx_cancel_fee, - tx_refund_fee, - btc_refund_address, - state2.cancel_timelock, - state2.punish_timelock, - )) + if let Ok(tx_lock_fee) = state2.tx_lock.fee() { + let tx_lock_fee = tx_lock_fee.to_sat(); + + Some(( + xmr_amount, + btc_amount, + tx_lock_id, + tx_cancel_fee, + tx_refund_fee, + tx_lock_fee, + btc_refund_address, + state2.cancel_timelock, + state2.punish_timelock, + )) + }else { + None + } } else { None } @@ -295,6 +303,7 @@ impl Request { "txLockId": tx_lock_id, "txCancelFee": tx_cancel_fee, "txRefundFee": tx_refund_fee, + "txLockFee": tx_lock_fee, "btcRefundAddress": btc_refund_address.to_string(), "cancelTimelock": cancel_timelock, "punishTimelock": punish_timelock, @@ -805,12 +814,15 @@ impl Request { pub async fn call(self, context: Arc) -> Result { let method_span = self.cmd.get_tracing_span(self.log_reference.clone()); - self.handle_cmd(context).instrument(method_span.clone()).await.map_err(|err| { - method_span.in_scope(|| { - tracing::debug!(%err, "API call resulted in an error"); - }); - err - }) + self.handle_cmd(context) + .instrument(method_span.clone()) + .await + .map_err(|err| { + method_span.in_scope(|| { + tracing::debug!(%err, "API call resulted in an error"); + }); + err + }) } } diff --git a/swap/src/bitcoin/lock.rs b/swap/src/bitcoin/lock.rs index 42819ad5..f8aa9a39 100644 --- a/swap/src/bitcoin/lock.rs +++ b/swap/src/bitcoin/lock.rs @@ -4,9 +4,10 @@ use crate::bitcoin::{ }; use ::bitcoin::util::psbt::PartiallySignedTransaction; use ::bitcoin::{OutPoint, TxIn, TxOut, Txid}; -use anyhow::{bail, Result}; +use anyhow::{bail, Context, Result}; use bdk::database::BatchDatabase; use bdk::miniscript::Descriptor; +use bdk::psbt::PsbtUtils; use bitcoin::{PackedLockTime, Script, Sequence}; use serde::{Deserialize, Serialize}; @@ -100,6 +101,15 @@ impl TxLock { Amount::from_sat(self.inner.clone().extract_tx().output[self.lock_output_vout()].value) } + pub fn fee(&self) -> Result { + Ok(Amount::from_sat( + self.inner + .clone() + .fee_amount() + .context("The PSBT is missing a TxOut for an input")?, + )) + } + pub fn txid(&self) -> Txid { self.inner.clone().extract_tx().txid() }