sync: correctly detect payment by refund tx ID (#470)

* sync: correctly detect payment by refund tx ID

* Payment: extract get_refund_tx_id() as own method
This commit is contained in:
ok300
2024-09-08 20:12:32 +00:00
committed by GitHub
parent b20c27a399
commit fc820176a1
2 changed files with 20 additions and 3 deletions

View File

@@ -1271,6 +1271,16 @@ impl Payment {
},
}
}
pub(crate) fn get_refund_tx_id(&self) -> Option<String> {
match self.details.clone() {
Some(PaymentDetails::Lightning { refund_tx_id, .. }) => Some(refund_tx_id),
Some(PaymentDetails::Bitcoin { refund_tx_id, .. }) => Some(refund_tx_id),
Some(PaymentDetails::Liquid { .. }) => None,
None => None,
}
.flatten()
}
}
/// Returned when calling [crate::sdk::LiquidSdk::recommended_fees].

View File

@@ -1874,9 +1874,16 @@ impl LiquidSdk {
.list_payments(&ListPaymentsRequest::default())
.await?
.into_iter()
.filter_map(|payment| {
let tx_id = payment.tx_id.clone();
tx_id.map(|tx_id| (tx_id, payment))
.flat_map(|payment| {
// Index payments by both tx_id (lockup/claim) and refund_tx_id
let mut res = vec![];
if let Some(tx_id) = payment.tx_id.clone() {
res.push((tx_id, payment.clone()));
}
if let Some(refund_tx_id) = payment.get_refund_tx_id() {
res.push((refund_tx_id, payment));
}
res
})
.collect();
if with_scan {