aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/nostr.ts16
-rw-r--r--lib/payments.ts7
2 files changed, 12 insertions, 11 deletions
diff --git a/lib/nostr.ts b/lib/nostr.ts
index 35a864d0..bb47696b 100644
--- a/lib/nostr.ts
+++ b/lib/nostr.ts
@@ -1,8 +1,8 @@
import config from "$config";
-import { l } from "$lib/logging";
+import { l, err } from "$lib/logging";
import { Relay, RelayPool, calculateId, signId, getPublicKey } from "nostr";
import { g, s, db } from "$lib/db";
-import { fail, sleep, wait } from "$lib/utils";
+import { fail, getInvoice, sleep, wait } from "$lib/utils";
import { nip04, nip19, finalizeEvent } from "nostr-tools";
import type { UnsignedEvent } from "nostr-tools";
import { emit } from "$lib/sockets";
@@ -297,14 +297,16 @@ r.on("event", async (sub, ev) => {
if (method === "pay_invoice") {
let { invoice: pr } = params;
let { amount_msat, payee } = await ln.decode(pr);
- let { id } = await ln.getInfo();
+ let { id } = await ln.getinfo();
let amount = Math.round(amount_msat / 1000);
if (payee === id) {
- let inv = await g(pr);
- let recipient = await g(`user:${inv.uid}`);
+ let invoice = await getInvoice(pr);
+ let recipient = await g(`user:${invoice.uid}`);
+
await sendInternal({
amount,
+ invoice,
recipient,
sender: user,
});
@@ -333,7 +335,7 @@ r.on("event", async (sub, ev) => {
ret.error = { code: "INTERNAL", message: "Payment timed out" };
}
} else if (method === "get_info") {
- let { alias, blockheight, color } = await ln.getInfo();
+ let { alias, blockheight, color } = await ln.getinfo();
ret.result = {
alias,
color,
@@ -364,6 +366,6 @@ r.on("event", async (sub, ev) => {
response = await finalizeEvent(response, sk);
r.send(["EVENT", response]);
} catch (e) {
- console.log("problem with nwc", e);
+ err("problem with nwc", e.message);
}
});
diff --git a/lib/payments.ts b/lib/payments.ts
index 8f197044..66e725c7 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -12,7 +12,6 @@ import {
fail,
fiat,
getInvoice,
- getUser,
sleep,
SATS,
sats,
@@ -605,14 +604,14 @@ export let sendLightning = async ({
}
};
-export let sendInternal = async ({ amount, recipient, sender }) => {
- let inv = await generate({
+export let sendInternal = async ({ amount, invoice = undefined, recipient, sender }) => {
+ if (!invoice) invoice = await generate({
invoice: { amount, type: "lightning" },
user: recipient,
sender,
});
- let { hash } = inv;
+ let { hash } = invoice;
let memo;
let p = await debit({ hash, amount, memo, user: sender });