From a7322928c45848cfb9984454bf8ece6e3439c673 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 30 Nov 2023 15:34:45 -0800 Subject: zaps and emails --- lib/lightning.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib/lightning.js') 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}`); -- cgit v1.2.3