aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lightning/invoice.js
diff options
context:
space:
mode:
Diffstat (limited to 'routes/lightning/invoice.js')
-rw-r--r--routes/lightning/invoice.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/routes/lightning/invoice.js b/routes/lightning/invoice.js
new file mode 100644
index 00000000..59f0df47
--- /dev/null
+++ b/routes/lightning/invoice.js
@@ -0,0 +1,27 @@
+module.exports = async (req, res) => {
+ let err = m => res.status(500).send(m);
+ let { amount, address, tip } = req.body;
+
+ let invoice;
+ try {
+ invoice = await lnb.addInvoice({ value: amount });
+ } catch (e) {
+ return err(e.message);
+ }
+
+ let hash = invoice.payment_request;
+ if (address) hash = address;
+
+ await db.Payment.create({
+ user_id: req.user.id,
+ hash,
+ amount,
+ currency: "CAD",
+ rate: app.get("rates")[req.user.currency],
+ tip,
+ confirmed: 1,
+ asset: 'LNBTC',
+ });
+
+ res.send(invoice);
+};