aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-12-19 13:30:58 -0800
committerAdam Soltys <[email protected]>2024-12-19 13:30:58 -0800
commite53f8f175ccb467469d7c7fcc9b2f3ed3b980a8c (patch)
treeb1c3e1d2c9b9ce7537af8d245c98b69700eaaff2 /lib
parent34bc04093ac503bd6be441822bf53afd9ed2179e (diff)
downloadcoinos-server-e53f8f175ccb467469d7c7fcc9b2f3ed3b980a8c.tar.gz
coinos-server-e53f8f175ccb467469d7c7fcc9b2f3ed3b980a8c.zip
handle offers
Diffstat (limited to 'lib')
-rw-r--r--lib/invoices.ts4
-rw-r--r--lib/lightning.ts10
2 files changed, 8 insertions, 6 deletions
diff --git a/lib/invoices.ts b/lib/invoices.ts
index 3259c46b..c892517c 100644
--- a/lib/invoices.ts
+++ b/lib/invoices.ts
@@ -91,12 +91,12 @@ export const generate = async ({ invoice, user }) => {
amount: amount ? `${amount + tip}sat` : "any",
label: id,
description: memo || "",
- absolute_expiry: expiry,
});
- console.log("R", r);
hash = r.bolt12;
text = r.bolt12;
+
+ await s(`invoice:${r.offer_id}`, id);
} else if (type === types.bitcoin) {
hash = await bc.getNewAddress();
text = bip21(hash, invoice);
diff --git a/lib/lightning.ts b/lib/lightning.ts
index ce39f0ad..e3d59f90 100644
--- a/lib/lightning.ts
+++ b/lib/lightning.ts
@@ -1,13 +1,14 @@
-import { handleZap } from "$lib/nostr";
+import { g, s } from "$lib/db";
import ln from "$lib/ln";
import { err, warn } from "$lib/logging";
-import { g, s } from "$lib/db";
+import { handleZap } from "$lib/nostr";
import { credit, types } from "$lib/payments";
import { getPayment } from "$lib/utils";
export async function listenForLightning() {
const inv = await ln.waitanyinvoice((await g("pay_index")) || 0);
const {
+ local_offer_id,
bolt11,
description,
pay_index,
@@ -23,7 +24,8 @@ export async function listenForLightning() {
try {
if (!preimage) return;
- const id = await g(`invoice:${bolt11}`);
+ const id =
+ (await g(`invoice:${bolt11}`)) || (await g(`invoice:${local_offer_id}`));
const invoice = await g(`invoice:${id}`);
if (!invoice) return warn("received lightning with no invoice", bolt11);
@@ -40,7 +42,7 @@ export async function listenForLightning() {
if (p) return warn("already processed", bolt11);
await credit({
- hash: bolt11,
+ hash: bolt11 || local_offer_id,
amount: received,
memo: invoice.memo,
ref: preimage,