Return tx_lock_fee to API caller on GetSwapInfo call

Update request.rs
pull/1276/head
binarybaron 7 months ago
parent 6c75f59ba1
commit 8bd242c825

@ -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<Context>) -> Result<serde_json::Value> {
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
})
}
}

@ -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<Amount> {
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()
}

Loading…
Cancel
Save