aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2018-12-29 19:33:39 -0800
committerAdam Soltys <[email protected]>2019-02-05 20:53:45 -0800
commit7668c1476381ac2877fbc771c31e40cb6908db66 (patch)
tree39979a658b2f50b2dca6303ef6aa00f02856ab70
parent00df5f108299152e0a1f8c2e92cb4bd5c427c0ef (diff)
downloadcoinos-server-7668c1476381ac2877fbc771c31e40cb6908db66.tar.gz
coinos-server-7668c1476381ac2877fbc771c31e40cb6908db66.zip
pay user endpoint
-rw-r--r--index.js37
1 files changed, 36 insertions, 1 deletions
diff --git a/index.js b/index.js
index affc0e2e..e90dc628 100644
--- a/index.js
+++ b/index.js
@@ -324,7 +324,7 @@ const l = console.log
if (seen.includes(m.payment_preimage)) return
seen.push(m.payment_preimage)
- let total = parseInt(m.payment_route.total_amt) + parseInt(m.payment_route.total_fees)
+ let total = parseInt(m.payment_route.total_amt)
req.user.balance -= total
await db.Payment.create({
@@ -356,6 +356,41 @@ const l = console.log
})
})
+ app.post('/payUser', auth, async (req, res) => {
+ let { payuser, amount } = req.body
+
+ let user = await db.User.findOne({
+ where: {
+ username: payuser
+ }
+ })
+
+ if (!user) return res.status(401).end()
+ let err = m => res.status(500).send(m)
+
+ let invoice
+ try {
+ invoice = await lnb.addInvoice({ value: amount })
+ } catch (e) {
+ return err(e.message)
+ }
+
+ let hash = invoice.payment_request
+
+ await db.Payment.create({
+ user_id: user.id,
+ hash,
+ amount,
+ currency: 'CAD',
+ rate: app.get('rates').ask,
+ tip: 0,
+ })
+
+ req.url = '/sendPayment'
+ req.body.payreq = invoice.payment_request
+ return app._router.handle(req, res)
+ })
+
app.post('/sendCoins', auth, async (req, res) => {
const MINFEE = 3000