aboutsummaryrefslogtreecommitdiffstats
path: root/lib/nwc.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-12-02 12:53:19 -0800
committerAdam Soltys <[email protected]>2024-12-02 12:53:19 -0800
commit501e2ba1942911a98278a95121a7553da19795d2 (patch)
tree5d55f8e88a95fbf708d47c0afc86ad559ccfaf18 /lib/nwc.ts
parentd16675345757dc7bf180f4aa51ccb0d124ea7e12 (diff)
downloadcoinos-server-501e2ba1942911a98278a95121a7553da19795d2.tar.gz
coinos-server-501e2ba1942911a98278a95121a7553da19795d2.zip
keysend
Diffstat (limited to 'lib/nwc.ts')
-rw-r--r--lib/nwc.ts27
1 files changed, 25 insertions, 2 deletions
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({