From 63a3b3275bd58d3fe5ab6ffb41e6beb6b7c47cde Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 12 Jul 2020 17:45:34 -0400 Subject: pay username --- routes/lnurl.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/routes/lnurl.js b/routes/lnurl.js index 74e5cc0a..80ccc313 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -64,6 +64,34 @@ app.post("/withdraw", auth, async (req, res) => { } }); +app.get("/pay/:username", auth, async (req, res) => { + const { username } = req.params; + let user = await db.user.findOne({ + where: { + username, + }, + }); + let { amount, minSendable, maxSendable } = req.query; + + minSendable = minSendable || 1000; + maxSendable = maxSendable || 1000000000; + if (parseInt(amount)) minSendable = maxSendable = amount * 1000; + + try { + const result = await lnurlServer.generateNewUrl("payRequest", { + minSendable, + maxSendable, + metadata: JSON.stringify([["text/plain", `fund coinos account ${user.username}`]]), + }); + + recipients[result.secret] = req.user; + res.send(result); + } catch (e) { + l.error("problem generating payment url", e.message); + res.status(500).send(e.message); + } +}); + app.get("/pay", auth, async (req, res) => { const { user } = req; const { amount } = req.query; -- cgit v1.2.3