From abd58592aece5a6483395fabcf57104efc75023c Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 4 Apr 2018 20:14:19 -0700 Subject: disallow paying the same invoice twice --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 401100cb..d6278dae 100644 --- a/index.js +++ b/index.js @@ -268,8 +268,14 @@ const l = console.log app.post('/sendPayment', auth, async (req, res) => { await req.user.reload() + let hash = req.body.payreq + let payreq = bolt11.decode(hash) - if (req.user.channelbalance < bolt11.decode(req.body.payreq).satoshis) { + if (seen.includes(hash)) { + return res.status(500).send('Invoice has been paid, can\'t pay again') + } + + if (req.user.channelbalance < payreq.satoshis) { return res.status(500).send('Not enough satoshis') } @@ -289,12 +295,13 @@ const l = console.log await db.Payment.create({ amount: -total, user_id: req.user.id, - hash: req.body.payreq, + hash, rate: app.get('rates').ask, currency: 'CAD', }) await req.user.save() + seen.push(hash) res.send(m) } }) -- cgit v1.2.3