diff options
| author | Adam Soltys <[email protected]> | 2023-09-19 06:48:33 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-09-19 06:48:33 -0700 |
| commit | 9f846760924ea58ccd120a812f2a3c9a42ec933f (patch) | |
| tree | fa5725d33df4fbad39c11e9e679a9f422e5408f4 | |
| parent | 79b8fa2d125d26d08c4c6880c04d29b35b8ca175 (diff) | |
| download | coinos-server-9f846760924ea58ccd120a812f2a3c9a42ec933f.tar.gz coinos-server-9f846760924ea58ccd120a812f2a3c9a42ec933f.zip | |
more payment logging
| -rw-r--r-- | routes/payments.js | 17 |
1 files changed, 14 insertions, 3 deletions
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; |
