diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/payments.ts | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/payments.ts b/lib/payments.ts index 3005e71b..6c78f40e 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -579,7 +579,14 @@ export const sendKeysend = async ({ extratlvs, }); } catch (e) { - try { await reverse(p); } catch (_) {} + try { + const { pays } = await ln.listpays({ payment_hash: hash }); + const failed = !pays.length || pays.every((p) => p.status === "failed"); + if (failed) await reverse(p); + // else: pending or completed — leave the debit; check() loop will + // reconcile. Reversing on pending would refund while CLN may still + // settle the keysend. + } catch (_) {} throw e; } }; @@ -656,12 +663,16 @@ export const sendLightning = async ({ try { const { pays } = await ln.listpays(pr); const completed = pays.find((p) => p.status === "complete"); + const failed = !pays.length || pays.every((p) => p.status === "failed"); if (completed) { warn("payment completed despite error, finalizing", p.id); try { await finalize(completed, p); } catch (_) {} - } else { + } else if (failed) { await reverse(p); } + // else: pending — leave the debit in place; check() loop will reconcile + // once CLN confirms outcome. Reversing while still in flight would + // refund the user even though the payment may yet complete. } catch (_) {} throw e; } |
