aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lightning.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-11-30 15:34:45 -0800
committerAdam Soltys <[email protected]>2023-11-30 15:34:45 -0800
commita7322928c45848cfb9984454bf8ece6e3439c673 (patch)
tree9b1031c31ee1f8160306ac66749afe0802f8aa54 /lib/lightning.js
parentacb93f29e83b35c0917d88ebbc62812e2dff989f (diff)
downloadcoinos-server-a7322928c45848cfb9984454bf8ece6e3439c673.tar.gz
coinos-server-a7322928c45848cfb9984454bf8ece6e3439c673.zip
zaps and emails
Diffstat (limited to 'lib/lightning.js')
-rw-r--r--lib/lightning.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/lightning.js b/lib/lightning.js
index 77a429ed..d4664458 100644
--- a/lib/lightning.js
+++ b/lib/lightning.js
@@ -1,4 +1,5 @@
import { emit } from "$lib/sockets";
+import { handleZap } from "$lib/nostr";
import config from "$config";
import { notify } from "$lib/notifications";
import { callWebhook } from "$lib/webhooks";
@@ -8,14 +9,15 @@ import { g, s, t, db } from "$lib/db";
import { credit, types } from "$lib/payments";
export async function listenForLightning() {
- let event = await ln.waitanyinvoice((await g("pay_index")) || 0);
+ let inv = await ln.waitanyinvoice((await g("pay_index")) || 0);
let {
bolt11,
+ description,
pay_index,
status,
amount_received_msat,
payment_preimage: preimage
- } = event;
+ } = inv;
await s("pay_index", pay_index);
setTimeout(listenForLightning);
@@ -31,6 +33,14 @@ export async function listenForLightning() {
let invoice = await g(`invoice:${id}`);
if (!invoice) return warn("received lightning with no invoice", bolt11);
+ if (invoice && invoice.memo) {
+ try {
+ if (JSON.parse(description).kind === 9734) await handleZap(inv);
+ } catch (e) {
+ warn("failed to handle zap", e.message);
+ }
+ }
+
let p = await g(`payment:${bolt11}`);
if (typeof p === "string") p = await g(`payment:${p}`);