From 321ce8473ec1a9df367af057c6e35e228e926e65 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 13 Aug 2021 09:21:18 -0400 Subject: lnurlp endpoint --- routes/lnurl.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/routes/lnurl.js b/routes/lnurl.js index 67f581d1..feceb913 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -114,6 +114,41 @@ app.post( }) ); +app.get( + "/lnurlp/:username", + ah(async (req, res, next) => { + 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 { + let result = await lnurlServer.generateNewUrl("payRequest", { + minSendable, + maxSendable, + metadata: JSON.stringify([["text/plain", `paying ${user.username}`]]) + }); + + recipients[result.secret] = user; + l.info("recipient", user.username, result.secret); + + result = await axios.get(result.url); + + res.send(result.data); + } catch (e) { + l.error("problem generating payment url", e.message); + res.status(500).send(e.message); + } + }) +); + app.get( "/pay/:username", ah(async (req, res, next) => { -- cgit v1.2.3