aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lightning
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-09-02 14:47:08 -0700
committerAdam Soltys <[email protected]>2022-09-02 14:47:14 -0700
commit3161dd7ee95b6c7d70f8341298dd4fab84cda8b0 (patch)
tree16cd6c55d5dc481331b1e8b640d179f193e7ea13 /routes/lightning
parent7a8d64833de8873afb92982b3f5bfff59b30c542 (diff)
downloadcoinos-server-3161dd7ee95b6c7d70f8341298dd4fab84cda8b0.tar.gz
coinos-server-3161dd7ee95b6c7d70f8341298dd4fab84cda8b0.zip
es6 migration
Diffstat (limited to 'routes/lightning')
-rw-r--r--routes/lightning/channel.js16
-rw-r--r--routes/lightning/channelRequest.js9
-rw-r--r--routes/lightning/conversionFee.js7
-rw-r--r--routes/lightning/index.js13
-rw-r--r--routes/lightning/invoice.js5
-rw-r--r--routes/lightning/query.js8
-rw-r--r--routes/lightning/receive.js3
-rw-r--r--routes/lightning/send.js11
8 files changed, 46 insertions, 26 deletions
diff --git a/routes/lightning/channel.js b/routes/lightning/channel.js
index fe6d9520..168f55ab 100644
--- a/routes/lightning/channel.js
+++ b/routes/lightning/channel.js
@@ -1,6 +1,6 @@
-import axios from 'axios';
+import axios from "axios";
-export default ah(async (req, res) => {
+export default async (req, res) => {
const { params } = req.body;
const [pubkey, host] = params.uri.split("@");
@@ -12,7 +12,7 @@ export default ah(async (req, res) => {
perm: true
});
} catch (e) {
- if (!e.message.includes('already connected')) {
+ if (!e.message.includes("already connected")) {
l.error("problem connecting to peer", e.message);
return res.status(500).send(e.message);
}
@@ -22,18 +22,18 @@ export default ah(async (req, res) => {
let remoteid;
try {
remoteid = (await lnp.getInfo({})).identity_pubkey;
- } catch(e) {
+ } catch (e) {
l.error("problem getting lightning node info", e.message);
return res.status(500).send(e.message);
- }
+ }
let url = `${callback}?k1=${k1}&remoteid=${remoteid}&private=0`;
try {
let response = await axios.get(url);
res.send(response.data);
- } catch(e) {
+ } catch (e) {
l.error("problem sending channel request", e.message);
return res.status(500).send({ status: "ERROR", reason: e.message });
- }
-});
+ }
+};
diff --git a/routes/lightning/channelRequest.js b/routes/lightning/channelRequest.js
index 96b6d71f..3aecaa61 100644
--- a/routes/lightning/channelRequest.js
+++ b/routes/lightning/channelRequest.js
@@ -1,10 +1,13 @@
-export default ah(async (req, res) => {
+import { lnurlServer } from "../lnurl.js";
+
+export default async (req, res) => {
let { localAmt, pushAmt } = req.body;
pushAmt = 0;
try {
- if (localAmt < 20000) throw new Error("amount must be greater than 20000 SAT");
+ if (localAmt < 20000)
+ throw new Error("amount must be greater than 20000 SAT");
if (localAmt > 1000000) throw new Error("amount must be <= 1000000");
const result = await lnurlServer.generateNewUrl("channelRequest", {
@@ -17,4 +20,4 @@ export default ah(async (req, res) => {
l.error("problem generating channel request", e.message);
res.status(500).send(e.message);
}
-});
+};
diff --git a/routes/lightning/conversionFee.js b/routes/lightning/conversionFee.js
index 161f18e6..62c0ec28 100644
--- a/routes/lightning/conversionFee.js
+++ b/routes/lightning/conversionFee.js
@@ -2,14 +2,11 @@
// This is in a separate file so that the same function can be used by ./send and ./receive
const conversionFeeMultiplier = 0.01;
-const conversionFeeReceiver = "coinosfees"; // account that receives the fees
+export const conversionFeeReceiver = "coinosfees"; // account that receives the fees
/**
* Returns the fee you have to pay for withdrawing 'amount' lightning BTC.
*/
-function computeConversionFee(amount) {
+export function computeConversionFee(amount) {
return Math.floor(amount * conversionFeeMultiplier);
}
-
-module.exports.conversionFeeReceiver = conversionFeeReceiver;
-module.exports.computeConversionFee = computeConversionFee;
diff --git a/routes/lightning/index.js b/routes/lightning/index.js
new file mode 100644
index 00000000..5d82cb5b
--- /dev/null
+++ b/routes/lightning/index.js
@@ -0,0 +1,13 @@
+import channel from "./channel.js";
+import channelRequest from "./channelRequest.js";
+import invoice from "./invoice.js";
+import query from "./query.js";
+import send from "./send.js";
+
+export default {
+ channel,
+ channelRequest,
+ invoice,
+ query,
+ send
+};
diff --git a/routes/lightning/invoice.js b/routes/lightning/invoice.js
index 38bad042..7d8a10cc 100644
--- a/routes/lightning/invoice.js
+++ b/routes/lightning/invoice.js
@@ -1,5 +1,4 @@
-
-export default ah(async (req, res) => {
+export default async (req, res) => {
let { amount, memo, tip } = req.body;
if (!tip) tip = 0;
let value = amount + tip;
@@ -22,4 +21,4 @@ export default ah(async (req, res) => {
l.error("problem creating invoice", e.message, e.stack);
res.status(500).send(e.message);
}
-});
+};
diff --git a/routes/lightning/query.js b/routes/lightning/query.js
index 0d034604..36c297f6 100644
--- a/routes/lightning/query.js
+++ b/routes/lightning/query.js
@@ -1,17 +1,17 @@
-export default ah(async (req, res) => {
+export default async (req, res) => {
const { payreq } = req.body;
const invoice = await db.Invoice.findOne({
include: {
- attributes: ['username'],
+ attributes: ["username"],
model: db.User,
as: "user"
},
where: {
- text: payreq,
+ text: payreq
}
});
if (invoice) emit(req.user.username, "to", invoice.user);
res.end();
-});
+};
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js
index 1c3dc8eb..405eed38 100644
--- a/routes/lightning/receive.js
+++ b/routes/lightning/receive.js
@@ -1,4 +1,7 @@
+import { notify } from "../../lib/notifications.js";
+import { callWebhook } from "../../lib/webhooks.js";
import { computeConversionFee } from './conversionFee.js';
+import { sendLiquid } from "../liquid/send.js";
const handlePayment = async (msg) => {
l.info("incoming lightning payment", msg.value, msg.payment_request, msg.settled);
diff --git a/routes/lightning/send.js b/routes/lightning/send.js
index a2eedcc8..807b4bb8 100644
--- a/routes/lightning/send.js
+++ b/routes/lightning/send.js
@@ -1,11 +1,16 @@
-export default ah(async (req, res) => {
+export default async (req, res) => {
let { amount, route, memo, payreq } = req.body;
let { user } = req;
try {
res.send(await send(amount, memo, payreq, user));
} catch (e) {
- l.error("problem sending lightning payment", user.username, payreq, e.message);
+ l.error(
+ "problem sending lightning payment",
+ user.username,
+ payreq,
+ e.message
+ );
res.status(500).send(e.message);
}
-});
+};