From 5e3bfba5eb3d54cc03551f98624a2e92dca5825f Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 3 Feb 2026 09:15:39 -0800 Subject: custodial ark payments --- routes/payments.ts | 46 ++++++++++++++++++++-------------------------- routes/users.ts | 2 +- 2 files changed, 21 insertions(+), 27 deletions(-) (limited to 'routes') diff --git a/routes/payments.ts b/routes/payments.ts index 752c7ce8..9b079e11 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -1,5 +1,6 @@ import config from "$config"; import api from "$lib/api"; +import { sendArk } from "$lib/ark"; import { requirePin } from "$lib/auth"; import { archive, db, g, gf, s } from "$lib/db"; import { generate } from "$lib/invoices"; @@ -751,34 +752,27 @@ export default { }, async ark(req, res) { - const { user } = req; - const { amount, hash, aid } = req.body; - - const { currency } = user; - const rates = await g("rates"); - const rate = rates[currency]; - const p = { - id: v4(), - aid, - amount: -amount, - hash, - confirmed: true, - rate, - currency, - type: PaymentType.ark, - created: Date.now(), - }; + const { body, user } = req; + const { address, amount, aid } = body; - const { id: uid } = user; - await s(`payment:${hash}`, p.id); - await s(`payment:${p.id}`, p); - await db - .multi() - .lPush(`${aid || uid}:payments`, p.id) - .set(`${aid || uid}:payments:last`, p.created) - .exec(); + try { + await requirePin({ body, user }); + const txid = await sendArk(address, amount); + const hash = txid; - res.send(p); + const p = await debit({ + hash, + amount, + user, + type: PaymentType.ark, + aid, + }); + + res.send(p); + } catch (e) { + warn(user.username, "ark payment failed", e.message); + res.code(500).send(e.message); + } }, async arkReceive(req, res) { diff --git a/routes/users.ts b/routes/users.ts index ca15924f..a63ac4ae 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -846,7 +846,7 @@ export default { const vtxoHex = Buffer.from(vtxoTaprootKey).toString("hex"); const r = await fetch( - `http://arkd:7070/v1/indexer/vtxos?scripts=5120${vtxoHex}`, + `http://arkd:7070/v1/indexer/vtxos?scripts=5120${vtxoHex}&spendable_only=true`, { "content-type": "application/json" }, ); const { vtxos } = await r.json(); -- cgit v1.2.3