From 501e2ba1942911a98278a95121a7553da19795d2 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 2 Dec 2024 12:53:19 -0800 Subject: keysend --- lib/nwc.ts | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'lib/nwc.ts') diff --git a/lib/nwc.ts b/lib/nwc.ts index 1c0c0eb6..3f6f24e7 100644 --- a/lib/nwc.ts +++ b/lib/nwc.ts @@ -4,7 +4,7 @@ import { generate } from "$lib/invoices"; import ln from "$lib/ln"; import { err } from "$lib/logging"; import { handleZap, serverPubkey } from "$lib/nostr"; -import { sendInternal, sendLightning } from "$lib/payments"; +import { sendInternal, sendKeysend, sendLightning } from "$lib/payments"; import { getInvoice, sleep } from "$lib/utils"; import { Relay } from "nostr"; import { finalizeEvent, nip04, nip19 } from "nostr-tools"; @@ -122,7 +122,7 @@ const handle = (method, params, user) => } await sendLightning({ amount, - maxfee: Math.max(5, Math.round(amount * 0.005)), + fee: Math.max(5, Math.round(amount * 0.005)), user, pr, }); @@ -140,6 +140,29 @@ const handle = (method, params, user) => return error({ code: "INTERNAL", message: "Payment timed out" }); }, + async pay_keysend() { + const { amount, pubkey } = params; + + await sendKeysend({ + amount, + pubkey, + fee: Math.max(5, Math.round(amount * 0.005)), + user, + }); + + for (let i = 0; i < 10; i++) { + const { pays } = await ln.listpays(pr); + const p = pays.find((p) => p.status === "complete"); + if (p) { + const { preimage } = p; + return result({ preimage }); + } + await sleep(2000); + } + + return error({ code: "INTERNAL", message: "Payment timed out" }); + }, + async get_info() { const { alias, blockheight, color } = await ln.getinfo(); return result({ -- cgit v1.2.3