aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/nostr.ts9
-rw-r--r--lib/nwc.ts19
-rw-r--r--lib/payments.ts3
3 files changed, 22 insertions, 9 deletions
diff --git a/lib/nostr.ts b/lib/nostr.ts
index d6c9c643..90c33694 100644
--- a/lib/nostr.ts
+++ b/lib/nostr.ts
@@ -6,6 +6,7 @@ import { fail, wait } from "$lib/utils";
import { nip19, finalizeEvent } from "nostr-tools";
import { emit } from "$lib/sockets";
import { hex } from "@scure/base";
+import { Relay as ntr } from 'nostr-tools/relay'
export const serverPubkey = hex.encode(
getPublicKey(nip19.decode(config.nostrKey).data),
@@ -264,9 +265,13 @@ export async function handleZap(invoice) {
tags.push(["preimage", invoice.payment_preimage]);
let ev = { pubkey, kind, created_at, content, tags };
- ev = await finalizeEvent(ev, sk);
+ let signed = await finalizeEvent(ev, sk);
l("sending receipt");
- await Promise.allSettled(relays.map((r) => send(ev, r)));
+ await Promise.allSettled(relays.map(async (url) => {
+ let r = await ntr.connect(url);
+ await r.publish(signed);
+ r.close()
+ }));
}
diff --git a/lib/nwc.ts b/lib/nwc.ts
index e889dfdf..2b2649a6 100644
--- a/lib/nwc.ts
+++ b/lib/nwc.ts
@@ -71,12 +71,6 @@ let handle = (method, params, user) =>
let invoice = await getInvoice(pr);
let recipient = await g(`user:${invoice.uid}`);
- if (invoice.memo.includes("9734")) {
- try {
- await handleZap(invoice);
- } catch (e) {}
- }
-
let { id: preimage } = await sendInternal({
amount,
invoice,
@@ -84,6 +78,19 @@ let handle = (method, params, user) =>
sender: user,
});
+ if (invoice.memo.includes("9734")) {
+ let { invoices } = await ln.listinvoices({ invstring: pr });
+ let inv = invoices[0];
+ inv.payment_preimage = preimage;
+ inv.paid_at = Math.floor(Date.now() / 1000);
+ try {
+ await handleZap(inv);
+ } catch (e) {
+ console.log("zap receipt failed", e);
+ }
+ }
+
+
return result({ preimage });
} else {
await sendLightning({
diff --git a/lib/payments.ts b/lib/payments.ts
index 3a02bfda..60989924 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -502,7 +502,8 @@ export let sendLightning = async ({
}
let total = amount;
- let { amount_msat } = await ln.decode(pr);
+ let decoded = await ln.decode(pr);
+ let { amount_msat } = decoded;
if (amount_msat) total = Math.round(amount_msat / 1000);
maxfee = parseInt(maxfee) || getMaxFee(total);