aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2018-04-04 20:14:19 -0700
committerAdam Soltys <[email protected]>2018-04-04 20:14:34 -0700
commitabd58592aece5a6483395fabcf57104efc75023c (patch)
tree2b0bb4cca5f4d793227c7f1ba612c981a6886ba8
parent5846fd948279de7e43d3d8406254286220b716e4 (diff)
downloadcoinos-server-abd58592aece5a6483395fabcf57104efc75023c.tar.gz
coinos-server-abd58592aece5a6483395fabcf57104efc75023c.zip
disallow paying the same invoice twice
-rw-r--r--index.js11
1 files 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)
}
})