aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-12-26 14:59:53 -0800
committerAdam Soltys <[email protected]>2024-12-26 14:59:53 -0800
commitcc0e94b7db8ec2e8adefc4f9145b0061684dba96 (patch)
treed23de4cec436c6584c88be7c4a660ebc671ec302
parent703564c452f3549adc2c23c62ff11d5e713b681e (diff)
downloadcoinos-server-cc0e94b7db8ec2e8adefc4f9145b0061684dba96.tar.gz
coinos-server-cc0e94b7db8ec2e8adefc4f9145b0061684dba96.zip
fix bolt12
-rw-r--r--index.ts3
-rw-r--r--lib/lightning.ts25
2 files changed, 24 insertions, 4 deletions
diff --git a/index.ts b/index.ts
index ac061729..bd892f31 100644
--- a/index.ts
+++ b/index.ts
@@ -3,7 +3,7 @@ Error.stackTraceLimit = Infinity;
import app from "$lib/app";
import { admin, auth, optional } from "$lib/auth";
-import { listenForLightning, replay } from "$lib/lightning";
+import { fixBolt12, listenForLightning, replay } from "$lib/lightning";
import { getLocations } from "$lib/locations";
import nwc from "$lib/nwc";
import { catchUp, check } from "$lib/payments";
@@ -128,6 +128,7 @@ app.post("/shopify/:id", shopify);
app.post("/hidepay", admin, users.hidepay);
app.post("/unlimit", admin, users.unlimit);
+app.get("/bolt12", fixBolt12);
app.get("/cash/:id/:version", ecash.get);
app.post("/cash", ecash.save);
diff --git a/lib/lightning.ts b/lib/lightning.ts
index acaa158b..0e9e6d8e 100644
--- a/lib/lightning.ts
+++ b/lib/lightning.ts
@@ -1,4 +1,4 @@
-import { g, s } from "$lib/db";
+import { db, g, s } from "$lib/db";
import ln from "$lib/ln";
import { err, warn } from "$lib/logging";
import { handleZap } from "$lib/nostr";
@@ -16,7 +16,7 @@ export async function listenForLightning() {
amount_received_msat,
payment_preimage: preimage,
} = inv;
-
+
await s("pay_index", pay_index);
setTimeout(listenForLightning);
@@ -55,7 +55,6 @@ export async function listenForLightning() {
}
}
-
export async function replay(index) {
const inv = await ln.waitanyinvoice(index - 1);
const {
@@ -103,3 +102,23 @@ export async function replay(index) {
err("problem receiving lightning payment", e.message);
}
}
+
+export const fixBolt12 = async (_, res) => {
+ for await (const k of db.scanIterator({ MATCH: "payment:*" })) {
+ const p = await g(k);
+ if (p.type === "bolt12") {
+ console.log(k);
+ const { invoices } = await ln.listinvoices({ invstring: p.hash });
+ const { local_offer_id } = invoices[0];
+ const oid = await g(`payment:${local_offer_id}`);
+ const op = await g(`payment:${oid}`);
+ if (op) {
+ db.del(`payment:${oid}`);
+ db.del(`payment:${local_offer_id}`);
+ db.decrBy(`balance:${op.uid}`, op.amount);
+ }
+ }
+ }
+
+ res.send({});
+};