aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-03 09:15:39 -0800
committerAdam Soltys <[email protected]>2026-02-06 08:58:12 -0800
commit5e3bfba5eb3d54cc03551f98624a2e92dca5825f (patch)
tree723e0be4e4f0a987fa2375fcf0360022f1232eaa /routes
parent4850177f50b7ff5a0f37acaa92190219d6f72da5 (diff)
downloadcoinos-server-5e3bfba5eb3d54cc03551f98624a2e92dca5825f.tar.gz
coinos-server-5e3bfba5eb3d54cc03551f98624a2e92dca5825f.zip
custodial ark payments
Diffstat (limited to 'routes')
-rw-r--r--routes/payments.ts44
-rw-r--r--routes/users.ts2
2 files changed, 20 insertions, 26 deletions
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 { body, user } = req;
+ const { address, amount, aid } = 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(),
- };
+ try {
+ await requirePin({ body, user });
+ const txid = await sendArk(address, amount);
+ const hash = txid;
- 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();
+ const p = await debit({
+ hash,
+ amount,
+ user,
+ type: PaymentType.ark,
+ aid,
+ });
- res.send(p);
+ 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();