aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lightning/receive.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-01-16 23:40:25 -0800
committerAdam Soltys <[email protected]>2023-01-16 23:40:25 -0800
commit91e847126c832efa25ab0bf8d6f3b7e537378fa7 (patch)
tree4a42b6e3bec6eb0f640ed44533b54e6d3d6a5e0e /routes/lightning/receive.js
parent6bafea9bffe24d2227d269812a73a9a513d92ddf (diff)
downloadcoinos-server-91e847126c832efa25ab0bf8d6f3b7e537378fa7.tar.gz
coinos-server-91e847126c832efa25ab0bf8d6f3b7e537378fa7.zip
shuffle things around
Diffstat (limited to 'routes/lightning/receive.js')
-rw-r--r--routes/lightning/receive.js92
1 files changed, 0 insertions, 92 deletions
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js
deleted file mode 100644
index ffb0ad95..00000000
--- a/routes/lightning/receive.js
+++ /dev/null
@@ -1,92 +0,0 @@
-import { v4 } from "uuid";
-import store from "$lib/store";
-import { emit } from "$lib/sockets";
-import config from "$config";
-import { notify } from "$lib/notifications";
-import { callWebhook } from "$lib/webhooks";
-import { computeConversionFee } from "./conversionFee";
-import ln from "$lib/ln";
-import { l, err, warn } from "$lib/logging";
-import { g, s, rd } from "$lib/redis";
-
-let handle = async () => {
- let {
- payment_hash,
- bolt11: request,
- pay_index,
- status,
- msatoshi_received,
- payment_preimage: secret
- } = await ln.waitanyinvoice(await g("pay_index"));
-
- await s("pay_index", pay_index);
-
- let received = Math.round(msatoshi_received / 1000);
-
- try {
- l("incoming lightning payment", received);
-
- if (!secret) return;
- let account, total, user;
-
- let invoice = await g(`invoice:${payment_hash}`);
- if (!invoice) return warn("received lightning with no invoice", request);
-
- let { text: hash, currency, memo, rate, tip, user_id } = invoice;
- let amount = parseInt(received) - tip;
- if (amount < 0) throw new Error("amount out of range");
-
- let id = v4();
- let payment = {
- id,
- user_id,
- hash,
- memo,
- amount,
- currency,
- secret,
- rate,
- tip,
- invoice_id: invoice.id,
- created_at: Date.now()
- };
-
- total = amount + tip;
-
- invoice.status = "paid";
- invoice.received += total;
- await s(`invoice:${payment_hash}`, invoice);
-
- let t = async () => {
- await rd.watch(`user:${user_id}`);
- user = await g(`user:${user_id}`);
- user.balance += total;
- let m = await rd.multi();
- await s(`user:${user.id}`, user);
- if (!(await m.exec())) t();
- };
- await t();
-
- payment.invoice = invoice;
-
- await s(`payment:${id}`, payment);
- await rd.lPush(`${user.id}:payments`, id);
-
- callWebhook(invoice, payment);
-
- emit(user.username, "payment", payment);
- notify(user, `Received ${total} SAT`);
-
- l("lightning payment received", user.username, payment.amount, payment.tip);
- } catch (e) {
- console.log(e);
- err("problem receiving lightning payment", e.message);
- }
-};
-
-let listen = async () => {
- await handle();
- listen();
-};
-
-listen();