aboutsummaryrefslogtreecommitdiffstats
path: root/lib/lightning.js
diff options
context:
space:
mode:
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}`);