aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-11-12 15:37:34 -0800
committerAdam Soltys <[email protected]>2020-11-12 15:37:34 -0800
commit92e913ba9238bbc6aab147515631328db3f8b7f3 (patch)
treea08a5864affa35bf5839317d261d1ef1c0d3599e /routes
parent42ad55c926902587affc34a484396a00e16d534e (diff)
downloadcoinos-server-92e913ba9238bbc6aab147515631328db3f8b7f3.tar.gz
coinos-server-92e913ba9238bbc6aab147515631328db3f8b7f3.zip
persist lnurl data between server restarts
Diffstat (limited to 'routes')
-rw-r--r--routes/lnurl.js36
-rw-r--r--routes/send.js2
2 files changed, 31 insertions, 7 deletions
diff --git a/routes/lnurl.js b/routes/lnurl.js
index 04cadc13..f47cf6f4 100644
--- a/routes/lnurl.js
+++ b/routes/lnurl.js
@@ -2,11 +2,12 @@ const axios = require("axios");
const lnurl = require("lnurl");
const jwt = require("jsonwebtoken");
const qs = require("query-string");
+const persist = require("../lib/persist");
-logins = {};
-recipients = {};
-payments = {};
-withdrawals = {};
+logins = persist('data/logins.json');
+recipients = persist('data/recipients.json');
+payments = persist('data/payments.json');
+withdrawals = persist('data/withdrawals.json');
lnurlServer = lnurl.createServer(config.lnurl);
@@ -166,15 +167,36 @@ app.post(
params: { callback, k1 }
} = req.body;
- const url = `${callback}${callback.includes('?') ? '&' : '?'}amount=${amount * 1000}${comment ? '&comment=' + comment : ''}`;
+ let url = `${callback}${callback.includes("?") ? "&" : "?"}amount=${amount *
+ 1000}${comment ? "&comment=" + comment : ""}`;
+ console.log(url);
try {
const parts = callback.split("/");
const secret = parts[parts.length - 1];
payments[secret] = user;
- const result = (await axios.get(url)).data;
- res.send(await send(amount, "", result.pr, user));
+ if (recipients[secret]) {
+ url = `${req.protocol}://${req.get("host")}/api/send`;
+ const { data } = await axios.post(
+ url,
+ {
+ amount,
+ memo: comment,
+ username: recipients[secret].username
+ },
+ {
+ headers: {
+ Authorization: req.get("Authorization")
+ }
+ }
+ );
+
+ res.send(data);
+ } else {
+ const { data } = await axios.get(url);
+ res.send(await send(amount, "", data.pr, user));
+ }
} catch (e) {
l.error("failed to send payment", e.message);
res.status(500).send(e.message);
diff --git a/routes/send.js b/routes/send.js
index ab67bfaa..78c6d9b7 100644
--- a/routes/send.js
+++ b/routes/send.js
@@ -5,6 +5,8 @@ module.exports = ah(async (req, res, next) => {
let { amount, asset, memo, username } = req.body;
let { user } = req;
+ if (!asset) asset = config.liquid.btcasset;
+
if (!amount || amount < 0)
return res.status(500).send("Amount must be greater than zero");