From ddbe2e8afa46f3c8906b0abe0683998f85ab2e68 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 13 Feb 2026 23:47:26 -0800 Subject: ark payment notifications --- routes/payments.ts | 34 +++++++++++++++++++++++++++++++++- routes/users.ts | 8 ++++---- 2 files changed, 37 insertions(+), 5 deletions(-) (limited to 'routes') diff --git a/routes/payments.ts b/routes/payments.ts index 52e9057e..13e3cb29 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -773,6 +773,7 @@ export default { try { await requirePin({ body, user }); + const txid = await sendArk(address, amount); const hash = txid; @@ -784,6 +785,20 @@ export default { aid, }); + const vault = await g(`arkaddr:${address}`); + if (vault) { + const { rate, currency } = await getUserRate(user); + await createArkPayment({ + aid: vault.aid, + uid: vault.uid, + amount, + hash, + rate, + currency, + extraHashMappings: [hash], + }); + } + res.send(p); } catch (e) { warn(user.username, "ark payment failed", e.message); @@ -947,7 +962,24 @@ export default { payments.push(p); synced++; - if (tx.amount > 0) received += tx.amount; + if (tx.amount > 0) { + received += tx.amount; + + // Find an unpaid ark invoice for this account and mark it received + const invoiceIds = await db.lRange(`${aid}:invoices`, 0, 20); + for (const iid of invoiceIds) { + const inv = await getInvoice(iid); + if (!inv || inv.type !== "ark") continue; + if (inv.received >= inv.amount && inv.amount > 0) continue; + if (inv.amount > 0 && tx.amount < inv.amount) continue; + inv.received += tx.amount; + p.iid = iid; + await s(`invoice:${iid}`, inv); + await s(`payment:${p.id}`, p); + emit(uid, "payment", p); + break; + } + } } res.send({ synced, received, payments }); diff --git a/routes/users.ts b/routes/users.ts index d1df6e5d..cf958927 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -897,11 +897,11 @@ export default { // ARK accounts don't need Bitcoin Core wallet setup if (type === "ark") { - await db - .multi() + const m = db.multi() .set(`account:${id}`, JSON.stringify(account)) - .lPush(`${user.id}:accounts`, id) - .exec(); + .lPush(`${user.id}:accounts`, id); + if (arkAddress) m.set(`arkaddr:${arkAddress}`, JSON.stringify({ aid: id, uid })); + await m.exec(); res.send(account); return; -- cgit v1.2.3