diff options
| author | Adam Soltys <[email protected]> | 2026-02-05 16:44:47 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-06 09:00:10 -0800 |
| commit | 4e9c0c5198c7884cfd97cb4495f6156632e3124a (patch) | |
| tree | ce8144806d7f88a7c3084eca3fd9669f13df54af /routes | |
| parent | 635ca5ad96c791bdd229f50c138b4f3292ae29ad (diff) | |
| download | coinos-server-4e9c0c5198c7884cfd97cb4495f6156632e3124a.tar.gz coinos-server-4e9c0c5198c7884cfd97cb4495f6156632e3124a.zip | |
payment forwarding
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/payments.ts | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/routes/payments.ts b/routes/payments.ts index e3cd8e5e..a93a1882 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -1,6 +1,6 @@ import config from "$config"; import api from "$lib/api"; -import { sendArk } from "$lib/ark"; +import { getArkAddress, sendArk } from "$lib/ark"; import { requirePin } from "$lib/auth"; import { archive, db, g, gf, s } from "$lib/db"; import { getTx } from "$lib/esplora"; @@ -21,7 +21,7 @@ import { sendOnchain, } from "$lib/payments"; import { emit } from "$lib/sockets"; -import { fundDebit, getBalance, getCredit, tbConfirm } from "$lib/tb"; +import { fundDebit, getBalance, getCredit, tbConfirm, tbCredit } from "$lib/tb"; import { PaymentType } from "$lib/types"; import { SATS, @@ -63,7 +63,7 @@ export default { const recipient = invoice ? await getUser(invoice.uid) : undefined; if (payreq) { if (invoice && recipient.username !== "mint") { - if (invoice.aid === user.id) fail("Cannot send to self"); + if (invoice.aid === (aid || user.id)) fail("Cannot send to self"); hash = payreq; if (!amount) ({ amount } = invoice); } else { @@ -809,6 +809,10 @@ export default { } }, + async arkAddress(_, res) { + res.send(await getArkAddress()); + }, + async arkReceive(req, res) { try { const { body, user } = req; @@ -821,13 +825,16 @@ export default { if (invoice.uid !== user?.id) fail("Unauthorized"); invoice.received += amount; - const { aid, type, currency } = invoice; + let { aid, type, currency } = invoice; const rates = await g("rates"); const rate = rates[currency]; + // Always credit custodial balance (Ark funds received by server) + await tbCredit(uid, uid, type, amount, false); + const p = { id: v4(), - aid: aid, + aid: uid, iid, amount, hash, @@ -842,10 +849,10 @@ export default { const m = db.multi(); m.set(`invoice:${invoice.id}`, JSON.stringify(invoice)) .set(`payment:${p.id}`, JSON.stringify(p)) - .lPush(`${aid || uid}:payments`, p.id) - .set(`${aid || uid}:payments:last`, p.created); + .lPush(`${uid}:payments`, p.id) + .set(`${uid}:payments:last`, p.created); - if (hash) m.set(`payment:${aid || uid}:${hash}`, p.id); + if (hash) m.set(`payment:${aid}:${hash}`, p.id); await m.exec(); @@ -878,6 +885,9 @@ export default { continue; } + // Skip received/change VTXOs — handled by arkReceive + if (tx.amount > 0) continue; + const p = { id: v4(), aid, |
