diff options
| -rw-r--r-- | index.js | 1 | ||||
| -rw-r--r-- | routes/payments.js | 24 |
2 files changed, 25 insertions, 0 deletions
@@ -60,6 +60,7 @@ app.get("/decode", lnurl.decode); app.get("/lnurlp/:username", lnurl.lnurlp); app.get("/lnurl/:id", lnurl.lnurl); +app.post("/fix", auth, payments.fix); app.post("/bitcoin", payments.bitcoin); app.post("/bitcoin/fee", auth, payments.fee); app.post("/bitcoin/send", auth, payments.send); diff --git a/routes/payments.js b/routes/payments.js index 62c5f737..c09fcf93 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -399,5 +399,29 @@ export default { } catch (e) { bail(res, e.message); } + }, + + async fix({ body: { uid }, user }, res) { + try { + if (!user.admin) fail("unauthorized"); + + let { username } = await g(`user:${uid}`); + let balance = await g(`balance:${uid}`); + + let payments = await db.lRange(`${uid}:payments`, 0, -1); + + let total = 0; + for (let pid of payments) { + let p = await g(`payment:${pid}`); + total += p.amount; + if (p.amount < 0) total -= ((p.fee || 0) + (p.ourfee || 0)); + } + + l('corrected balance', username, uid, balance, total); + await s(`balance:${uid}`, total); + res.send("ok"); + } catch (e) { + bail(res, e.message); + } } }; |
