From 4850177f50b7ff5a0f37acaa92190219d6f72da5 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 2 Feb 2026 23:30:00 -0800 Subject: ark sync --- index.ts | 1 + routes/payments.ts | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++- wallet.Dockerfile | 4 ++-- 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index faab936d..a5e60310 100644 --- a/index.ts +++ b/index.ts @@ -90,6 +90,7 @@ app.post("/replace", auth, payments.replace); app.get("/decode/:bolt11", payments.decode); app.post("/fetchinvoice", payments.fetchinvoice); app.post("/ark/receive", auth, payments.arkReceive); +app.post("/ark/sync", auth, payments.arkSync); app.get("/square/connect", auth, square.connect); app.get("/square/auth", auth, square.auth); diff --git a/routes/payments.ts b/routes/payments.ts index cfbae56b..752c7ce8 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -769,13 +769,22 @@ export default { created: Date.now(), }; + 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(); + res.send(p); }, async arkReceive(req, res) { try { const { body, user } = req; - const { iid, amount } = body; + const { iid, amount, hash } = body; const { id: uid } = user; if (amount <= 0) fail("Invalid amount"); @@ -816,4 +825,55 @@ export default { bail(res, e.message); } }, + + async arkSync(req, res) { + try { + const { user } = req; + const { transactions, aid } = req.body; + const { id: uid, currency } = user; + + const rates = await g("rates"); + const rate = rates[currency]; + + let synced = 0; + for (const tx of transactions) { + const existingId = await g(`payment:${tx.hash}`); + if (existingId) { + const existing = await g(`payment:${existingId}`); + if (existing && !existing.confirmed && tx.settled) { + existing.confirmed = true; + await s(`payment:${existingId}`, existing); + } + continue; + } + + const p = { + id: v4(), + aid, + amount: tx.amount, + hash: tx.hash, + confirmed: tx.settled, + rate, + currency, + type: PaymentType.ark, + uid, + created: tx.createdAt, + }; + + await s(`payment:${tx.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(); + + synced++; + } + + res.send({ synced }); + } catch (e) { + bail(res, e.message); + } + }, }; diff --git a/wallet.Dockerfile b/wallet.Dockerfile index db080737..8c1d48fd 100644 --- a/wallet.Dockerfile +++ b/wallet.Dockerfile @@ -1,11 +1,11 @@ # First stage: build the ark-wallet-daemon binary -FROM golang:1.25.3 AS builder +FROM golang:1.25.6 AS builder ARG VERSION ARG TARGETOS ARG TARGETARCH -ARG BRANCH=v0.8.4 +ARG BRANCH=master WORKDIR /app -- cgit v1.2.3