aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-11-26 10:56:20 -0800
committerAdam Soltys <[email protected]>2026-02-06 08:57:26 -0800
commit2a408a3a7486464296e4e7f996fc2140a664d407 (patch)
treed2855fef7c52bdb0758523dea50c2853d2d305f0 /routes
parent9089698e8df9d0c09c165c45eb6b05335a818699 (diff)
downloadcoinos-server-2a408a3a7486464296e4e7f996fc2140a664d407.tar.gz
coinos-server-2a408a3a7486464296e4e7f996fc2140a664d407.zip
ark
Diffstat (limited to 'routes')
-rw-r--r--routes/invoices.ts4
-rw-r--r--routes/payments.ts67
2 files changed, 70 insertions, 1 deletions
diff --git a/routes/invoices.ts b/routes/invoices.ts
index a18f4263..63338621 100644
--- a/routes/invoices.ts
+++ b/routes/invoices.ts
@@ -4,6 +4,7 @@ import { generate } from "$lib/invoices";
import { err } from "$lib/logging";
import { bail, fail, fields, getInvoice, getUser } from "$lib/utils";
import rpc from "@coinos/rpc";
+import { v4 } from "uuid";
export default {
async get(req, res) {
@@ -53,7 +54,7 @@ export default {
try {
const { id } = req.params;
const { body } = req;
- const { tip, webhook, secret } = body.invoice;
+ const { tip, webhook, secret, received } = body.invoice;
if (tip < 0) fail("Invalid tip");
@@ -69,6 +70,7 @@ export default {
}
invoice = await generate({ invoice, user });
+
await s(`invoice:${id}`, invoice);
res.send(invoice);
diff --git a/routes/payments.ts b/routes/payments.ts
index a640d8e2..cfbae56b 100644
--- a/routes/payments.ts
+++ b/routes/payments.ts
@@ -749,4 +749,71 @@ export default {
bail(res, e.message);
}
},
+
+ async ark(req, res) {
+ const { user } = req;
+ const { amount, hash, aid } = req.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(),
+ };
+
+ res.send(p);
+ },
+
+ async arkReceive(req, res) {
+ try {
+ const { body, user } = req;
+ const { iid, amount } = body;
+ const { id: uid } = user;
+
+ if (amount <= 0) fail("Invalid amount");
+
+ const invoice = await getInvoice(iid);
+ if (invoice.uid !== user?.id) fail("Unauthorized");
+ invoice.received += amount;
+
+ const { aid, type, currency } = invoice;
+ const rates = await g("rates");
+ const rate = rates[currency];
+
+ const p = {
+ id: v4(),
+ aid: aid,
+ iid,
+ amount,
+ hash,
+ confirmed: true,
+ rate,
+ currency,
+ type,
+ uid,
+ created: Date.now(),
+ };
+
+ const m = await 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)
+ .exec();
+
+ await completePayment(invoice, p, user);
+
+ res.send(p);
+ } catch (e) {
+ bail(res, e.message);
+ }
+ },
};