Skip to content

Commit dbef121

Browse files
committed
Address PR review feedback for RBF payment lookup
1 parent fdae635 commit dbef121

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/wallet/mod.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,11 +1213,19 @@ impl Wallet {
12131213
}
12141214

12151215
// Also check the payment store for onchain payments with this txid.
1216+
// First try direct lookup by payment_id, then fall back to scanning by txid.
1217+
if let Some(payment) = self.payment_store.get(&direct_payment_id) {
1218+
if payment.status != PaymentStatus::Succeeded {
1219+
return Some(payment.id);
1220+
}
1221+
}
1222+
12161223
if let Some(payment) = self
12171224
.payment_store
1218-
.list_filter(
1219-
|p| matches!(&p.kind, PaymentKind::Onchain { txid, .. } if *txid == target_txid),
1220-
)
1225+
.list_filter(|p| {
1226+
matches!(&p.kind, PaymentKind::Onchain { txid, .. } if *txid == target_txid)
1227+
&& p.status != PaymentStatus::Succeeded
1228+
})
12211229
.first()
12221230
{
12231231
return Some(payment.id);
@@ -1233,12 +1241,14 @@ impl Wallet {
12331241
let spent_outpoints: std::collections::HashSet<OutPoint> =
12341242
tx.input.iter().map(|input| input.previous_output).collect();
12351243

1236-
let onchain_payments = self.payment_store.list_filter(|p| {
1237-
matches!(p.kind, PaymentKind::Onchain { .. }) && p.status != PaymentStatus::Failed
1244+
let pending_onchain_payments = self.pending_payment_store.list_filter(|p| {
1245+
matches!(p.details.kind, PaymentKind::Onchain { .. })
1246+
&& p.details.status != PaymentStatus::Failed
12381247
});
12391248

1240-
for payment in onchain_payments {
1241-
if let PaymentKind::Onchain { txid: existing_txid, .. } = &payment.kind {
1249+
for pending_payment in pending_onchain_payments {
1250+
if let PaymentKind::Onchain { txid: existing_txid, .. } = &pending_payment.details.kind
1251+
{
12421252
if *existing_txid == target_txid {
12431253
continue;
12441254
}
@@ -1249,7 +1259,7 @@ impl Wallet {
12491259
.iter()
12501260
.any(|input| spent_outpoints.contains(&input.previous_output));
12511261
if shares_inputs {
1252-
return Some(payment.id);
1262+
return Some(pending_payment.details.id);
12531263
}
12541264
}
12551265
}

0 commit comments

Comments
 (0)