From a58030323a46ebaf2dd7f439e469dd47c1da3986 Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 9 Apr 2026 19:08:31 +0400 Subject: [PATCH] fix: update payment apis --- apps/pay/src/freedom.ts | 12 ++++++------ apps/pay/src/monitor.ts | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/apps/pay/src/freedom.ts b/apps/pay/src/freedom.ts index 1a0e693..2b8db2a 100644 --- a/apps/pay/src/freedom.ts +++ b/apps/pay/src/freedom.ts @@ -1,12 +1,12 @@ -const API = process.env.FREEDOM_API ?? "https://api-v1.freedom.st"; +const API = process.env.FREEDOM_API ?? "https://api.freedom.st"; export async function getChainInfo(): Promise> { - const res = await fetch(`${API}/rpc/info`); + const res = await fetch(`${API}/info`); return res.json(); } export async function getExchangeRates(): Promise> { - const res = await fetch(`${API}/invoice/rates`); + const res = await fetch(`${API}/rates`); return res.json(); } @@ -20,13 +20,13 @@ export async function getAddressInfoBulk(addresses: string[]): Promise { - const url = `${API}/invoice/qr/${encodeURIComponent(text)}`; + const url = `${API}/qr/${encodeURIComponent(text)}`; try { const res = await fetch(url); if (!res.ok) return url; @@ -42,6 +42,6 @@ export async function fetchQrBase64(text: string): Promise { export async function getAvailableCoins(): Promise { const info = await getChainInfo(); return Object.entries(info) - .filter(([_, v]) => v && v.uptime != null) + .filter(([_, v]) => v?.node?.uptime != null) .map(([k]) => k); } diff --git a/apps/pay/src/monitor.ts b/apps/pay/src/monitor.ts index 65f2a1d..fed6eea 100644 --- a/apps/pay/src/monitor.ts +++ b/apps/pay/src/monitor.ts @@ -3,7 +3,7 @@ import { getAddressInfo, getAddressInfoBulk } from "./freedom"; import { COINS, planTier } from "../../shared/plans"; import { generateReceipt } from "./receipt"; -const SOCK_API = process.env.FREEDOM_SOCK ?? "https://sock-v1.freedom.st"; +const SOCK_API = process.env.FREEDOM_SOCK ?? "https://sock.freedom.st"; const THRESHOLD = 0.95; let addressMap = new Map(); // address → payment @@ -95,19 +95,19 @@ async function evaluatePayment(paymentId: number) { } async function handleTxEvent(event: any) { - const txHash = event.data?.tx?.hash; + const txHash = event.data?.hash; if (!txHash || seenTxids.has(txHash)) return; seenTxids.add(txHash); - const outputs = event.data?.out ?? []; + const outputs = event.data?.to ?? []; for (const out of outputs) { - const addr = out?.script?.address; + const addr = out?.address; const payment = addr && addressMap.get(addr); if (!payment) continue; const txValue = outputs - .filter((o: any) => o?.script?.address === addr) - .reduce((s: number, o: any) => s + Number(o.value ?? 0), 0); + .filter((o: any) => o?.address === addr) + .reduce((s: number, o: any) => s + Number(o.amount ?? 0), 0); if (txValue <= 0) continue; console.log(`SSE: tx ${txHash} for payment ${payment.id}: +${txValue} ${payment.coin}`); @@ -119,7 +119,7 @@ async function handleTxEvent(event: any) { } async function handleBlockEvent(event: any) { - const blockTxs: string[] = event.data?.tx ?? []; + const blockTxs: string[] = (event.data?.transactions ?? []).map((t: any) => typeof t === 'string' ? t : t.hash); const matched = blockTxs.filter(t => txidToPayment.has(t)); if (matched.length === 0) return; @@ -192,9 +192,10 @@ export async function checkPayments() { if (!info) try { info = await getAddressInfo(payment.address); } catch { continue; } if (!info || info.error) continue; - for (const tx of info.in ?? []) { - if (!tx.txid) continue; - await recordTx(payment.id, payment.address, tx.txid, Number(tx.amount ?? 0), tx.block != null); + const inbound = (info.transactions ?? []).filter((tx: any) => tx.amount > 0); + for (const tx of inbound) { + if (!tx.hash) continue; + await recordTx(payment.id, payment.address, tx.hash, Number(tx.amount ?? 0), tx.block != null); } await evaluatePayment(payment.id); } catch (e) {