aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lightning.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-10-31 09:29:04 -0700
committerAdam Soltys <[email protected]>2024-10-31 09:34:42 -0700
commitaa4cd39c943b67169def224e224bd07b815b70ec (patch)
tree2af857ac971705f4d20eb017864f0365d0b57ea6 /lib/lightning.ts
parentbc9c04f6519f32d3b444d4df0b276eba960480a9 (diff)
downloadcoinos-server-aa4cd39c943b67169def224e224bd07b815b70ec.tar.gz
coinos-server-aa4cd39c943b67169def224e224bd07b815b70ec.zip
biome lint
Diffstat (limited to 'lib/lightning.ts')
-rw-r--r--lib/lightning.ts22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/lightning.ts b/lib/lightning.ts
index 7a35c9f2..ce39f0ad 100644
--- a/lib/lightning.ts
+++ b/lib/lightning.ts
@@ -6,8 +6,8 @@ import { credit, types } from "$lib/payments";
import { getPayment } from "$lib/utils";
export async function listenForLightning() {
- let inv = await ln.waitanyinvoice((await g("pay_index")) || 0);
- let {
+ const inv = await ln.waitanyinvoice((await g("pay_index")) || 0);
+ const {
bolt11,
description,
pay_index,
@@ -18,16 +18,16 @@ export async function listenForLightning() {
await s("pay_index", pay_index);
setTimeout(listenForLightning);
- let received = Math.round(amount_received_msat / 1000);
+ const received = Math.round(amount_received_msat / 1000);
try {
if (!preimage) return;
- let id = await g(`invoice:${bolt11}`);
- let invoice = await g(`invoice:${id}`);
+ const id = await g(`invoice:${bolt11}`);
+ const invoice = await g(`invoice:${id}`);
if (!invoice) return warn("received lightning with no invoice", bolt11);
- if (invoice && invoice.memo) {
+ if (invoice?.memo) {
try {
if (JSON.parse(description).kind === 9734) await handleZap(inv);
} catch (e) {
@@ -36,10 +36,16 @@ export async function listenForLightning() {
}
}
- let p = await getPayment(bolt11);
+ const p = await getPayment(bolt11);
if (p) return warn("already processed", bolt11);
- await credit({ hash:bolt11, amount:received, memo:invoice.memo, ref:preimage, type:types.lightning});
+ await credit({
+ hash: bolt11,
+ amount: received,
+ memo: invoice.memo,
+ ref: preimage,
+ type: types.lightning,
+ });
} catch (e) {
console.log(e);
err("problem receiving lightning payment", e.message);