diff options
| author | Adam Soltys <[email protected]> | 2026-02-16 11:51:41 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-16 11:51:41 -0800 |
| commit | ee0513838b1d336fa60eb9a8f7ca1ce43e6d9e40 (patch) | |
| tree | 04d097d676c4c0a48287f631a539b4055522dcfe /routes/payments.ts | |
| parent | 20cee249905ee6975e88089b76b2eccb4019e19a (diff) | |
| download | coinos-server-ee0513838b1d336fa60eb9a8f7ca1ce43e6d9e40.tar.gz coinos-server-ee0513838b1d336fa60eb9a8f7ca1ce43e6d9e40.zip | |
passkey auth
Diffstat (limited to 'routes/payments.ts')
| -rw-r--r-- | routes/payments.ts | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/routes/payments.ts b/routes/payments.ts index 4bdd0d30..c77da697 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -933,8 +933,9 @@ export default { async arkSync(req, res) { try { const { user } = req; - const { transactions, aid } = req.body; + const { transactions = [], aid } = req.body; const { id: uid } = user; + l("arkSync", user.username, aid, "txs:", transactions.length, "bal:", req.body.balance); // Per-account lock prevents concurrent syncs from racing const lockKey = `arksynclock:${aid}`; @@ -1003,6 +1004,34 @@ export default { } } + // Reconcile expired VTXOs + const { balance } = req.body; + if (typeof balance === "number" && balance >= 0) { + const paymentIds = await db.lRange(`${aid}:payments`, 0, -1); + let expectedBalance = 0; + for (const pid of paymentIds) { + const pay = await g(`payment:${pid}`); + if (pay) expectedBalance += pay.amount; + } + + if (expectedBalance > balance) { + const p = await createArkPayment({ + aid, + uid, + amount: balance - expectedBalance, + hash: `expired-${Date.now()}`, + rate, + currency, + created: Date.now(), + extraHashMappings: [], + }); + p.memo = "expired"; + await s(`payment:${p.id}`, p); + payments.push(p); + synced++; + } + } + // Check for pending custodial ark invoice to forward let forward; if (received > 0) { |
