aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-09-07 15:03:40 -0700
committerAdam Soltys <[email protected]>2022-09-07 15:03:40 -0700
commit5afcf12b214a3c81f00cfc03f892e299fceeac71 (patch)
tree7e0a428949573896ea58e8595e67dcc644e49dbe
parent3e11c9e4aa3618e58af413c98d6992ae18d444f7 (diff)
downloadcoinos-server-5afcf12b214a3c81f00cfc03f892e299fceeac71.tar.gz
coinos-server-5afcf12b214a3c81f00cfc03f892e299fceeac71.zip
es6 migration
-rw-r--r--index.js2
-rw-r--r--lib/account.js8
-rw-r--r--lib/sockets.js2
-rw-r--r--routes/lightning/invoice.js3
-rw-r--r--routes/lnurl.js16
-rw-r--r--routes/payments.js1
-rw-r--r--routes/send.js2
-rw-r--r--routes/users.js4
8 files changed, 22 insertions, 16 deletions
diff --git a/index.js b/index.js
index 8262967d..5a7a44bc 100644
--- a/index.js
+++ b/index.js
@@ -19,11 +19,11 @@ import "./routes/info";
import "./routes/users";
import "./routes/invoices";
import "./routes/payments";
+import "./routes/lnurl";
if (config.bitcoin) store.networks.push("bitcoin");
if (config.liquid) store.networks.push("liquid");
if (config.lna) store.networks.push("lightning");
-if (config.lnurl) import("./routes/lnurl");
let host = process.env.HOST || "0.0.0.0";
let port = process.env.PORT || 3119;
diff --git a/lib/account.js b/lib/account.js
index 6edb3fc1..1576546a 100644
--- a/lib/account.js
+++ b/lib/account.js
@@ -1,4 +1,6 @@
import axios from "axios";
+import db from "$db";
+import store from "$lib/store";
export default async (asset, user, transaction) => {
const account = await db.Account.findOne({
@@ -22,10 +24,8 @@ export default async (asset, user, transaction) => {
let ticker = asset.substr(0, 3).toUpperCase();
let precision = 8;
- const assets = assets;
-
- if (assets[asset]) {
- ({ domain, ticker, precision, name } = assets[asset]);
+ if (store.assets[asset]) {
+ ({ domain, ticker, precision, name } = store.assets[asset]);
} else {
const existing = await db.Account.findOne({
where: {
diff --git a/lib/sockets.js b/lib/sockets.js
index 9ff454aa..89278580 100644
--- a/lib/sockets.js
+++ b/lib/sockets.js
@@ -159,7 +159,7 @@ app.register(async function(app) {
ws.token = data;
break;
case "lnurl":
- sessions[data] = ws;
+ store.sessions[data] = ws;
break;
case "updateMemo":
const payment = await db.Payment.findOne({
diff --git a/routes/lightning/invoice.js b/routes/lightning/invoice.js
index f58169eb..05ec7e09 100644
--- a/routes/lightning/invoice.js
+++ b/routes/lightning/invoice.js
@@ -24,11 +24,10 @@ export default async (req, res) => {
tokens: value,
description: memo
});
- console.log(invoice)
res.send({ text: invoice.request });
}
} catch (e) {
- err("problem creating invoice", e.message, e.stack);
+ err("problem creating invoice", e.message);
res.code(500).send(e.message);
}
};
diff --git a/routes/lnurl.js b/routes/lnurl.js
index 54b82ade..2749262d 100644
--- a/routes/lnurl.js
+++ b/routes/lnurl.js
@@ -1,7 +1,9 @@
import app from "$app";
import config from "$config";
+import db from "$db";
import store from "$lib/store";
import { optionalAuth, auth } from "$lib/passport";
+import { l, err, warn } from "$lib/logging";
import lnd from "$lib/lnd";
import persist from "$lib/persist";
@@ -15,18 +17,18 @@ import bolt11 from "bolt11";
import { createInvoice, getPayments } from "lightning";
-export const logins = persist("data/logins.json");
-export const recipients = persist("data/recipients.json");
-export const lnurlPayments = persist("data/payments.json");
-export const withdrawals = persist("data/withdrawals.json");
-
-export const lnurlServer = lnurl.createServer(config.lnurl);
-
import {
computeConversionFee,
conversionFeeReceiver
} from "./lightning/conversionFee.js";
+const logins = persist("data/logins.json");
+const recipients = persist("data/recipients.json");
+const lnurlPayments = persist("data/payments.json");
+const withdrawals = persist("data/withdrawals.json");
+
+export const lnurlServer = lnurl.createServer(config.lnurl);
+
app.get("/url", async (req, res, next) => {
try {
const code = await db.Code.findOne({
diff --git a/routes/payments.js b/routes/payments.js
index 3e91e5fd..a9313520 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -1,4 +1,5 @@
import app from "$app";
+import db from "$db";
import config from "$config";
import store from "$lib/store";
diff --git a/routes/send.js b/routes/send.js
index f41b4874..ec6f924e 100644
--- a/routes/send.js
+++ b/routes/send.js
@@ -77,7 +77,7 @@ export default async (req, res, next) => {
if (!username) {
l("creating redeemable payment");
params.redeemcode = v4();
- params.hash = `${req.get("origin")}/redeem/${params.redeemcode}`;
+ params.hash = `${req.hostname}/redeem/${params.redeemcode}`;
}
let payment = await db.Payment.create(params, { transaction });
diff --git a/routes/users.js b/routes/users.js
index 599d6837..bd3c5c31 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -293,8 +293,11 @@ let login = async (req, res) => {
if (sig) {
const { callback } = params;
+ console.log(params, sig, key)
+
try {
const url = `${callback}&sig=${sig}&key=${key}`;
+ console.log(url)
const response = await axios.get(url);
res.send(response.data);
} catch (e) {
@@ -680,6 +683,7 @@ app.post("/redeem", optionalAuth, async function(req, res) {
});
} catch (e) {
delete redeeming[redeemcode];
+ console.log(e)
err("problem redeeming", e.message);
return res.code(500).send("There was a problem redeeming the voucher");
}