aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-09 17:22:01 -0800
committerAdam Soltys <[email protected]>2026-02-09 17:22:01 -0800
commit0472ded5b52807f93ce5761ad884928008410e53 (patch)
tree3399462409e8ed1ac6de2390493ff0a27000c57b /lib
parent6f933c6e989f934364a276815826364fec5a85b4 (diff)
downloadcoinos-server-0472ded5b52807f93ce5761ad884928008410e53.tar.gz
coinos-server-0472ded5b52807f93ce5761ad884928008410e53.zip
ark fixes
Diffstat (limited to 'lib')
-rw-r--r--lib/invoices.ts2
-rw-r--r--lib/payments.ts60
2 files changed, 62 insertions, 0 deletions
diff --git a/lib/invoices.ts b/lib/invoices.ts
index e461c1a7..71f95b8c 100644
--- a/lib/invoices.ts
+++ b/lib/invoices.ts
@@ -63,6 +63,7 @@ export const generate = async ({ invoice, user }) => {
if (!id) id = v4();
let text;
+ let path;
let paymentHash;
if (account.type === "ark") {
@@ -156,6 +157,7 @@ export const generate = async ({ invoice, user }) => {
id,
items,
memo,
+ path,
rate,
paymentHash,
pending: 0,
diff --git a/lib/payments.ts b/lib/payments.ts
index 0fd87559..99f07cc8 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -62,6 +62,66 @@ const { URL } = process.env;
const dust = 547;
+export const getUserRate = async (user) => {
+ const rates = await g("rates");
+ const { currency } = user;
+ const rate = rates[currency];
+ return { rates, rate, currency };
+};
+
+export const acquireArkLock = async (hash) => {
+ const locked = await db.set(`arklock:${hash}`, "1", { NX: true, EX: 60 });
+ if (!locked) fail("Already processed");
+};
+
+export const createArkPayment = async ({
+ aid,
+ uid,
+ amount,
+ hash,
+ rate,
+ currency,
+ type = PaymentType.ark,
+ iid = undefined,
+ created = Date.now(),
+ mapHashToId = false,
+ extraHashMappings = [] as string[],
+ extraMultiOps = undefined as ((m: any, p: any) => void) | undefined,
+}) => {
+ const p = {
+ id: v4(),
+ aid,
+ amount,
+ hash,
+ confirmed: true,
+ rate,
+ currency,
+ type,
+ uid,
+ iid,
+ created,
+ };
+
+ const m = db.multi();
+ m.set(`payment:${p.id}`, JSON.stringify(p))
+ .lPush(`${aid}:payments`, p.id)
+ .set(`${aid}:payments:last`, p.created);
+
+ if (mapHashToId) {
+ m.set(`payment:${aid}:${hash}`, JSON.stringify(p.id));
+ }
+
+ for (const h of extraHashMappings) {
+ m.set(`payment:${aid}:${h}`, JSON.stringify(p.id));
+ }
+
+ if (extraMultiOps) extraMultiOps(m, p);
+
+ await m.exec();
+
+ return p;
+};
+
export const debit = async ({
aid = undefined,
hash,