aboutsummaryrefslogtreecommitdiffstats
path: root/lib/nwc.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-02-11 20:07:21 -0800
committerAdam Soltys <[email protected]>2025-02-11 20:07:21 -0800
commiteb3c2aad4cef9b86294bc9a13a36da4918529209 (patch)
tree33c58529ee50bf875620a5a33d97e8ab57b673ae /lib/nwc.ts
parent004ac3ccbfb6a12227a81d6e0dc0beaf9a740827 (diff)
downloadcoinos-server-eb3c2aad4cef9b86294bc9a13a36da4918529209.tar.gz
coinos-server-eb3c2aad4cef9b86294bc9a13a36da4918529209.zip
nwc notifications
Diffstat (limited to 'lib/nwc.ts')
-rw-r--r--lib/nwc.ts26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/nwc.ts b/lib/nwc.ts
index 3f346b87..a902b0a6 100644
--- a/lib/nwc.ts
+++ b/lib/nwc.ts
@@ -22,6 +22,7 @@ const methods = [
"make_invoice",
"lookup_invoice",
"list_transactions",
+ "notifications",
];
const week = 7 * 24 * 60 * 60;
@@ -31,14 +32,19 @@ export default () => {
r.on("open", async (_) => {
r.subscribe("nwc", { kinds: [23194], "#p": [serverPubkey] });
- let info: UnsignedEvent = {
- created_at: Math.floor(Date.now() / 1000),
- kind: 13194,
- tags: [["p", serverPubkey]],
- pubkey: serverPubkey,
- content: methods.join(" "),
- };
- info = await finalizeEvent(info, sk);
+ const info = await finalizeEvent(
+ {
+ created_at: Math.floor(Date.now() / 1000),
+ kind: 13194,
+ tags: [
+ ["p", serverPubkey],
+ ["notifications", "payment_received payment_sent"],
+ ],
+ pubkey: serverPubkey,
+ content: methods.join(" "),
+ },
+ sk,
+ );
r.send(["EVENT", info]);
});
@@ -314,9 +320,7 @@ const handle = (method, params, ev, app, user) =>
async list_transactions() {
const { from, until, limit = 10, offset = 0, type } = params;
- const { pubkey } = app;
- const k = pubkey === user.pubkey ? user.id : pubkey;
- const payments = await db.lRange(`${k}:payments`, 0, -1);
+ const payments = await db.lRange(`${user.id}:payments`, 0, -1);
let transactions = [];
for (const pid of payments) {