From 9f846760924ea58ccd120a812f2a3c9a42ec933f Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 19 Sep 2023 06:48:33 -0700 Subject: more payment logging --- routes/payments.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'routes') diff --git a/routes/payments.js b/routes/payments.js index 07350828..8f9b90bd 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -78,12 +78,21 @@ export default { p = await debit(payreq, total, maxfee, memo, user, types.lightning); + let checks = 0; + let check = async () => { + checks++; + if (checks > 10) clearInterval(interval); + try { let { pays } = await ln.listpays(payreq); - l("checking", payreq, pays); - if ((!pays.length || pays[0].status === "failed") && (await g(`payment:${p.id}`))) { + let recordExists = !!(await g(`payment:${p.id}`)); + let paymentFailed = (pays.length && pays[pays.length - 1].status === "failed") + + l("checking", payreq, recordExists, paymentFailed); + + if (recordExists && paymentFailed) { await db.del(`payment:${p.id}`); let credit = Math.round(total * config.fee) - p.ourfee; @@ -119,18 +128,20 @@ export default { if (!(r.status === "complete" && r.payment_preimage)) fail("Payment did not complete"); + l("payment completed", p.id, r.payment_preimage); + p.amount = -amount; p.tip = total - amount; p.hash = r.payment_hash; p.fee = Math.round((r.amount_sent_msat - r.amount_msat) / 1000); p.ref = r.payment_preimage; + await s(`payment:${p.id}`, p); l("refunding fee", maxfee, p.fee, maxfee - p.fee, p.ref); await db.incrBy(`balance:${p.uid}`, maxfee - p.fee); } catch (e) { - clearInterval(interval); warn("something went wrong", e.message); await check(); throw e; -- cgit v1.2.3