diff options
| author | Adam Soltys <[email protected]> | 2026-02-14 15:46:01 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-14 15:46:01 -0800 |
| commit | 526b21bc668c453250ebce8dece9ba330bac0133 (patch) | |
| tree | 5e9c84a2cca6b4a5766c6cdc9f33f6c62f5776f3 /routes | |
| parent | 843c343db567cd224dadf347ac16736bdc8b24a8 (diff) | |
| download | coinos-server-526b21bc668c453250ebce8dece9ba330bac0133.tar.gz coinos-server-526b21bc668c453250ebce8dece9ba330bac0133.zip | |
custodial ark sends
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/payments.ts | 66 | ||||
| -rw-r--r-- | routes/users.ts | 4 |
2 files changed, 53 insertions, 17 deletions
diff --git a/routes/payments.ts b/routes/payments.ts index 13e3cb29..5f6f7a85 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -774,7 +774,31 @@ export default { try { await requirePin({ body, user }); + // Check for local vault - do internal transfer + const vault = await g(`arkaddr:${address}`); + if (vault) { + const recipient = await getUser(vault.uid); + if (recipient) { + // Find recipient's pending ark invoice via custodial mapping + let invoice; + const account = await g(`account:${vault.aid}`); + if (account?.arkAddress) { + const iid = await g(`custodial-ark-invoice:${account.arkAddress}`); + if (iid) { + invoice = await getInvoice(iid); + if (invoice && !invoice.hash) invoice.hash = invoice.id; + } + } + + l("ark local send", user.username, recipient.username, amount, "invoice:", invoice?.id, "received:", invoice?.received, "hash:", invoice?.hash); + const p = await sendInternal({ amount, invoice, recipient, sender: user }); + return res.send(p); + } + } + + l("ark send", user.username, address, amount); const txid = await sendArk(address, amount); + l("ark send complete", txid); const hash = txid; const p = await debit({ @@ -785,20 +809,6 @@ 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); @@ -903,6 +913,9 @@ export default { await completePayment(invoice, p, user); + // Clean up custodial ark invoice index + if (invoice.text) await db.del(`custodial-ark-invoice:${invoice.text}`); + res.send(p); } catch (e) { bail(res, e.message); @@ -982,7 +995,30 @@ export default { } } - res.send({ synced, received, payments }); + // Check for pending custodial ark invoice to forward + let forward; + if (received > 0) { + const account = await g(`account:${aid}`); + l("arkSync forward check", aid, account?.arkAddress, received); + if (account?.arkAddress) { + const iid = await g(`custodial-ark-invoice:${account.arkAddress}`); + l("arkSync custodial invoice lookup", account.arkAddress, iid); + if (iid) { + const inv = await getInvoice(iid); + if (inv && (inv.received < inv.amount || inv.amount === 0)) { + const serverArkAddress = await getArkAddress(); + forward = { + iid, + amount: inv.amount || received, + serverArkAddress, + }; + l("arkSync returning forward", forward); + } + } + } + } + + res.send({ synced, received, payments, forward }); } finally { await db.del(lockKey); } diff --git a/routes/users.ts b/routes/users.ts index cf958927..4435ba6f 100644 --- a/routes/users.ts +++ b/routes/users.ts @@ -2,7 +2,7 @@ import { createReadStream } from "node:fs"; import { unlink, writeFile } from "node:fs/promises"; import config from "$config"; import { requirePin } from "$lib/auth"; -import { db, g, ga, gf, s } from "$lib/db"; +import { db, g, ga, gf, s, scan } from "$lib/db"; import { err, l, warn } from "$lib/logging"; import { mail, templates } from "$lib/mail"; import { getNostrUser, getProfile, serverPubkey2 } from "$lib/nostr"; @@ -119,7 +119,7 @@ export default { const users = []; - for await (const k of db.scanIterator({ MATCH: "user:*" })) { + for await (const k of scan("user:*")) { const val = await g(k); if (!val || typeof val !== "object" || !val.id || !val.username) continue; const uid = val.id; |
