aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-07-12 17:45:34 -0400
committerAdam Soltys <[email protected]>2020-07-12 17:45:54 -0400
commit63a3b3275bd58d3fe5ab6ffb41e6beb6b7c47cde (patch)
tree094e0888419cc754e6f97c956af6330ce2027738
parent657be6094bee823ddfa1d3fb1f96dfa0d4170eff (diff)
downloadcoinos-server-63a3b3275bd58d3fe5ab6ffb41e6beb6b7c47cde.tar.gz
coinos-server-63a3b3275bd58d3fe5ab6ffb41e6beb6b7c47cde.zip
pay username
-rw-r--r--routes/lnurl.js28
1 files changed, 28 insertions, 0 deletions
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;