aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-01-30 20:31:59 +0000
committerAdam Soltys <[email protected]>2026-01-30 20:31:59 +0000
commitedd76a99a90d56ab641c48b95dd5891558baa133 (patch)
tree7298026a3823645ab67d7cd8093d7a9c89433ade
parent3e2b756e5b97db690b9a707049060805ca88c9de (diff)
downloadcoinos-server-edd76a99a90d56ab641c48b95dd5891558baa133.tar.gz
coinos-server-edd76a99a90d56ab641c48b95dd5891558baa133.zip
consult archive for older payments
-rw-r--r--lib/nwc.ts12
-rw-r--r--lib/payments.ts4
-rw-r--r--routes/invoices.ts4
-rw-r--r--routes/lnurl.ts4
-rw-r--r--routes/payments.ts5
5 files changed, 17 insertions, 12 deletions
diff --git a/lib/nwc.ts b/lib/nwc.ts
index c7f8d7e9..c888ee55 100644
--- a/lib/nwc.ts
+++ b/lib/nwc.ts
@@ -1,5 +1,5 @@
import config from "$config";
-import { db, g } from "$lib/db";
+import { archive, db, g, gf } from "$lib/db";
import { generate } from "$lib/invoices";
import ln from "$lib/ln";
import { err, l, warn } from "$lib/logging";
@@ -428,11 +428,15 @@ const handle = (method, params, ev, app, user) =>
async list_transactions() {
const { from, until, limit = 10, offset = 0, type } = params;
- const payments = await db.lRange(`${user.id}:payments`, 0, -1);
+ const listKey = `${user.id}:payments`;
+ const main = (await db.lRange(listKey, 0, -1)) || [];
+ const archived = (await archive.lRange(listKey, 0, -1)) || [];
+ const payments = [...new Set([...main, ...archived])];
let transactions = [];
for (const pid of payments) {
- const p = await g(`payment:${pid}`);
+ const p = await gf(`payment:${pid}`);
+ if (!p) continue;
const created_at = Math.floor(p.created / 1000);
if (created_at < from || created_at > until) continue;
if (p.amount < 0 && type === "incoming") continue;
@@ -457,7 +461,7 @@ const handle = (method, params, ev, app, user) =>
description: p.memo,
preimage: p.ref,
payment_hash,
- amount: (Math.abs(p.amount) + p.tip) * 1000,
+ amount: (Math.abs(p.amount) + (p.tip || 0)) * 1000,
fees_paid: (p?.fee || 0) * 1000,
created_at,
expires_at: created_at + week,
diff --git a/lib/payments.ts b/lib/payments.ts
index 931bf167..80aee8b7 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -1,6 +1,6 @@
import config from "$config";
import api from "$lib/api";
-import { db, g, ga, s } from "$lib/db";
+import { db, g, ga, gf, s } from "$lib/db";
import { generate } from "$lib/invoices";
import ln from "$lib/ln";
import { err, l, warn } from "$lib/logging";
@@ -493,7 +493,7 @@ export const sendKeysend = async ({
}) => {
fee = Math.max(Number.parseInt(fee || amount * 0.005), 5);
- let p = await g(`payment:${hash}`);
+ let p = await gf(`payment:${hash}`);
if (p) fail("duplicate keysend");
p = await debit({
diff --git a/routes/invoices.ts b/routes/invoices.ts
index 36869575..a18f4263 100644
--- a/routes/invoices.ts
+++ b/routes/invoices.ts
@@ -1,5 +1,5 @@
import config from "$config";
-import { db, g, s } from "$lib/db";
+import { db, g, gf, s } from "$lib/db";
import { generate } from "$lib/invoices";
import { err } from "$lib/logging";
import { bail, fail, fields, getInvoice, getUser } from "$lib/utils";
@@ -57,7 +57,7 @@ export default {
if (tip < 0) fail("Invalid tip");
- let invoice = await g(`invoice:${id}`);
+ let invoice = await gf(`invoice:${id}`);
const user = await g(`user:${invoice.uid}`);
if (typeof tip !== "undefined") invoice.tip = tip;
diff --git a/routes/lnurl.ts b/routes/lnurl.ts
index 729cca58..0358488e 100644
--- a/routes/lnurl.ts
+++ b/routes/lnurl.ts
@@ -1,4 +1,4 @@
-import { db, g, s } from "$lib/db";
+import { db, g, gf, s } from "$lib/db";
import { generate } from "$lib/invoices";
import { err, warn } from "$lib/logging";
import { serverPubkey2 } from "$lib/nostr";
@@ -126,7 +126,7 @@ export default {
}
const invoice = iid
- ? await g(`invoice:${iid}`)
+ ? await gf(`invoice:${iid}`)
: await generate({
invoice: {
amount: Math.round(amount / 1000),
diff --git a/routes/payments.ts b/routes/payments.ts
index a61c4c3c..a640d8e2 100644
--- a/routes/payments.ts
+++ b/routes/payments.ts
@@ -575,7 +575,8 @@ export default {
user,
} = req;
try {
- const p = await g(`payment:${id}`);
+ const p = await gf(`payment:${id}`);
+ if (!p) fail("Payment not found");
if (p.uid !== user.id) fail("unauthorized");
emit(user.id, "payment", p);
@@ -647,7 +648,7 @@ export default {
user,
} = req;
try {
- const p = await g(`payment:${id}`);
+ const p = await gf(`payment:${id}`);
if (!p) fail("Payment not found");
if (p.uid !== user.id) fail("unauthorized");