From 5c4b8d7ce23e7285d85e0a704e347910fb994112 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 26 Jul 2022 23:25:06 -0700 Subject: return json for lightning invoice --- routes/lightning/invoice.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'routes') diff --git a/routes/lightning/invoice.js b/routes/lightning/invoice.js index 054a4a46..31f23bd6 100644 --- a/routes/lightning/invoice.js +++ b/routes/lightning/invoice.js @@ -13,10 +13,10 @@ module.exports = ah(async (req, res) => { memo, 360 ); - res.send(invoice.bolt11); + res.send({ text: invoice.bolt11 }); } else { const invoice = await lnp.addInvoice({ value, memo }); - res.send(invoice.payment_request); + res.send({ text: invoice.payment_request }); } } catch (e) { l.error("problem creating invoice", e.message, e.stack); -- cgit v1.2.3 From 82f9acc60b7edbdfee96f1553d0fb1dcc705b866 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sat, 30 Jul 2022 11:10:47 -0700 Subject: don't require auth for invoice, default uuid value --- db/models/invoices.js | 2 +- routes/invoices.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'routes') diff --git a/db/models/invoices.js b/db/models/invoices.js index a51ee3f9..324da9ad 100644 --- a/db/models/invoices.js +++ b/db/models/invoices.js @@ -76,7 +76,7 @@ const attributes = { uuid: { type: DataTypes.STRING(255), allowNull: true, - defaultValue: null, + defaultValue: DataTypes.UUIDV4, primaryKey: false, autoIncrement: false, comment: null, diff --git a/routes/invoices.js b/routes/invoices.js index 51906b8c..1208e14e 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -3,7 +3,6 @@ const axios = require("axios"); app.get( "/invoice", - auth, ah(async (req, res, next) => { try { const invoice = await db.Invoice.findOne({ -- cgit v1.2.3 From 99b7b4fbeb64e2e4512211c9c2a4a085bacd96d8 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 1 Aug 2022 22:17:58 -0700 Subject: record invoice status --- db/models/invoices.js | 9 +++++++++ routes/invoices.js | 9 +++++++-- routes/lightning/receive.js | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) (limited to 'routes') diff --git a/db/models/invoices.js b/db/models/invoices.js index 324da9ad..d985ce82 100644 --- a/db/models/invoices.js +++ b/db/models/invoices.js @@ -154,6 +154,15 @@ const attributes = { comment: null, field: "webhook" }, + status: { + type: DataTypes.TEXT, + allowNull: true, + defaultValue: "unpaid", + primaryKey: false, + autoIncrement: false, + comment: null, + field: "status" + }, tip: { type: DataTypes.DOUBLE, allowNull: true, diff --git a/routes/invoices.js b/routes/invoices.js index 1208e14e..b5650735 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -8,7 +8,12 @@ app.get( const invoice = await db.Invoice.findOne({ where: { uuid: req.query.uuid - } + }, + include: { + model: db.User, + as: "user", + attributes: ['username'] + } }); res.send(invoice); @@ -23,7 +28,7 @@ app.post( optionalAuth, ah(async (req, res, next) => { try { - let { liquidAddress, invoice, user, tx } = req.body; + let { liquidAddress, id, invoice, user, tx } = req.body; let { blindkey } = invoice; if (invoice.amount < 0) throw new Error("amount out of range"); diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js index 89ad4c29..c9e7dec7 100644 --- a/routes/lightning/receive.js +++ b/routes/lightning/receive.js @@ -61,6 +61,9 @@ const handlePayment = async (msg) => { total = amount + tip; invoice.received += total; + invoice.status = 'paid'; + await invoice.save({ transaction }); + await account.increment({ balance: total }, { transaction }); // get the # of fee credits you would need to pay off this amount of bitcoin await account.increment({ lightning_credits: computeConversionFee(total) }, { transaction }); @@ -71,6 +74,7 @@ const handlePayment = async (msg) => { payment = payment.get({ plain: true }); payment.account = account.get({ plain: true }); + payment.invoice= invoice.get({ plain: true }); callWebhook(invoice, payment); -- cgit v1.2.3 From e78c557feb3c0ea0068758cd2d560fff66823736 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 22 Aug 2022 16:03:58 -0700 Subject: select user currency with invoice --- routes/invoices.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'routes') diff --git a/routes/invoices.js b/routes/invoices.js index b5650735..02a8308d 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -12,7 +12,7 @@ app.get( include: { model: db.User, as: "user", - attributes: ['username'] + attributes: ['username', 'currency'] } }); -- cgit v1.2.3 From 906a72dc7db448848587bf5bc36c0d8caf7ef7cc Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 23 Aug 2022 15:53:10 -0700 Subject: enable vouchers --- routes/send.js | 1 - routes/users.js | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'routes') diff --git a/routes/send.js b/routes/send.js index 4c8afa34..653da87b 100644 --- a/routes/send.js +++ b/routes/send.js @@ -66,7 +66,6 @@ module.exports = ah(async (req, res, next) => { }; if (!username) { - throw new Error("Vouchers temporarily disabled"); l.info("creating redeemable payment"); params.redeemcode = uuidv4(); params.hash = `${req.get("origin")}/redeem/${params.redeemcode}`; diff --git a/routes/users.js b/routes/users.js index 4fe1362b..c9367c9a 100644 --- a/routes/users.js +++ b/routes/users.js @@ -634,12 +634,16 @@ app.post( }) ); +let redeeming = {}; app.post( "/redeem", optionalAuth, ah(async function(req, res) { + try { await db.transaction(async transaction => { const { redeemcode } = req.body; + if (redeeming[redeemcode]) fail("redemption in progress"); + redeeming[redeemcode] = true; if (!redeemcode) fail("no code provided"); let { user } = req; @@ -652,6 +656,7 @@ app.post( model: db.Account, as: "account" }, + lock: transaction.LOCK.UPDATE, transaction }); @@ -717,6 +722,9 @@ app.post( res.send({ payment }); }); + } catch(e) { + l.error("problem redeeming", e.message); + return res.status(500).send("There was a problem redeeming the voucher"); }) ); -- cgit v1.2.3 From 3f144a605f8f24c526581a2050d21a62b66c2f72 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 8 Jul 2022 01:43:08 -0400 Subject: fix lnurl path --- routes/lnurl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'routes') diff --git a/routes/lnurl.js b/routes/lnurl.js index 30184d01..3dd436eb 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -12,7 +12,7 @@ withdrawals = persist("data/withdrawals.json"); lnurlServer = lnurl.createServer(config.lnurl); -let { computeConversionFee, conversionFeeReceiver } = require('lightning/conversionFee.js'); +let { computeConversionFee, conversionFeeReceiver } = require('./lightning/conversionFee.js'); var optionalAuth = function(req, res, next) { passport.authenticate("jwt", { session: false }, function(err, user, info) { -- cgit v1.2.3