From 517065e5bd34f7e1d5c27ce8c86476cd0810636a Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 23 Jan 2024 12:51:20 -0800 Subject: return ourfee minus covered credits --- index.js | 1 + lib/db.js | 2 +- lib/payments.js | 6 +++--- routes/payments.js | 7 ++++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 48246f42..9cbd373f 100644 --- a/index.js +++ b/index.js @@ -63,6 +63,7 @@ app.get("/fund/:name/withdraw", payments.withdraw); app.post("/take", auth, payments.take); app.post("/print", auth, payments.print); app.post("/send/:lnaddress/:amount", auth, payments.lnaddress); +app.post("/gateway", payments.gateway); app.get("/encode", lnurl.encode); app.get("/decode", lnurl.decode); diff --git a/lib/db.js b/lib/db.js index 10c54f02..20fc2cd2 100644 --- a/lib/db.js +++ b/lib/db.js @@ -24,7 +24,7 @@ end redis.call('decrby', creditKey, tostring(math.floor(covered))) redis.call('decrby', balanceKey, tostring(math.floor(amount + tip + fee + ourfee))) -return {ok = 'ok'} +return {ok = ourfee} `; let debit = defineScript({ diff --git a/lib/payments.js b/lib/payments.js index 796ad18b..8da04b38 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -72,7 +72,7 @@ export let debit = async ({ ? Math.round(amount * config.fee) : 0; - let r = await db.debit( + let r = await db.debit( `balance:${uid}`, `credit:${type}:${uid}`, amount || 0, @@ -81,7 +81,7 @@ export let debit = async ({ ourfee || 0, ); - if (r !== "ok") fail("Problem debiting account"); + if (!r || r.err) fail("Problem debiting account"); let id = v4(); let p = { @@ -89,7 +89,7 @@ export let debit = async ({ amount: -amount, fee, hash, - ourfee, + ourfee: r.ourfee, memo, iid, uid, diff --git a/routes/payments.js b/routes/payments.js index 768307c0..6e0f1159 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -327,7 +327,7 @@ export default { type === types.liquid ? await node.blindRawTransaction(hex) : hex, ); - ({ txid } = await node.decodeRawTransaction(signed)); + ({ txid } = await node.decodeRawTransaction(signed)); let r = await node.testMempoolAccept([signed]); if (!r[0].allowed) fail("transaction rejected"); @@ -463,4 +463,9 @@ export default { bail(res, e.message); } }, + + async gateway({ body: { short_channel_id, webhook } }, res) { + await s(short_channel_id, webhook); + res.send({ ok: true }); + }, }; -- cgit v1.2.3