diff options
| author | Adam Soltys <[email protected]> | 2023-09-03 20:49:34 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-09-03 20:49:34 -0700 |
| commit | c8043f25ff3c9fc6e17724061c0fec456b9f3c2c (patch) | |
| tree | 71d27f182563394eef30d84a553676baf30db276 /routes | |
| parent | dd93caa76eee95ace50f05ca13a344bc3bc5ad4a (diff) | |
| parent | 3aa200db295438827bfff48f80e3f4b25f44e8ea (diff) | |
| download | coinos-server-c8043f25ff3c9fc6e17724061c0fec456b9f3c2c.tar.gz coinos-server-c8043f25ff3c9fc6e17724061c0fec456b9f3c2c.zip | |
Merge branch 'prod'
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/invoices.js | 4 | ||||
| -rw-r--r-- | routes/payments.js | 9 |
2 files changed, 5 insertions, 8 deletions
diff --git a/routes/invoices.js b/routes/invoices.js index a1ead582..9f2e4c99 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -9,10 +9,6 @@ import ln from "$lib/ln"; export default { async get({ params: { hash } }, res) { let pr; - if (hash.startsWith("ln")) { - ({ payment_hash: hash } = await ln.decode(hash)); - } - let invoice = await g(`invoice:${hash}`); if (invoice) { diff --git a/routes/payments.js b/routes/payments.js index c13f7bec..383b89fc 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -61,11 +61,11 @@ export default { let total = amount; let { amount_msat, payment_hash } = await ln.decode(payreq); if (amount_msat) total = Math.round(amount_msat / 1000); - let invoice = await g(`invoice:${payment_hash}`); + let invoice = await g(`invoice:${payreq}`); if (invoice) { if (invoice.uid === user.id) fail("Cannot send to self"); - hash = payment_hash; + hash = payreq; } else { p = await debit(hash, total, maxfee, memo, user, types.lightning); @@ -79,7 +79,8 @@ export default { maxfee: maxfee * 1000, retry_for: 5 }); - if (r.status !== "complete") fail("payment did not complete"); + + if (r.status !== "complete" || !r.payment_preimage) fail("payment did not complete"); p.amount = -amount; p.tip = total - amount; @@ -93,7 +94,7 @@ export default { await db.incrBy(`balance:${p.uid}`, maxfee - p.fee); } catch (e) { warn("something went wrong", e.message); - if (!(r && r.status === "complete")) { + if (!(r && r.status === "complete" && r.payment_preimage)) { let credit = Math.round(total * config.fee) - p.ourfee; warn("crediting balance", total + maxfee + p.ourfee); await db.incrBy(`balance:${p.uid}`, total + maxfee + p.ourfee); |
