aboutsummaryrefslogtreecommitdiffstats
path: root/routes/payments.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-14 15:46:01 -0800
committerAdam Soltys <[email protected]>2026-02-14 15:46:01 -0800
commit526b21bc668c453250ebce8dece9ba330bac0133 (patch)
tree5e9c84a2cca6b4a5766c6cdc9f33f6c62f5776f3 /routes/payments.ts
parent843c343db567cd224dadf347ac16736bdc8b24a8 (diff)
downloadcoinos-server-526b21bc668c453250ebce8dece9ba330bac0133.tar.gz
coinos-server-526b21bc668c453250ebce8dece9ba330bac0133.zip
custodial ark sends
Diffstat (limited to 'routes/payments.ts')
-rw-r--r--routes/payments.ts66
1 files changed, 51 insertions, 15 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);
}