diff options
| -rw-r--r-- | names/server.js | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/names/server.js b/names/server.js index 71ebcc0..e12e71b 100644 --- a/names/server.js +++ b/names/server.js @@ -961,12 +961,18 @@ function pendingSummary() { }; } -let retryTicking = false; -setInterval(async () => { +let retryTicking = false, retryAgain = false; +async function tick() { if (!fwd || retryTicking) return; retryTicking = true; - try { await retryTick(); } finally { retryTicking = false; } -}, 60_000); + try { do { retryAgain = false; await retryTick(); } while (retryAgain); } + finally { retryTicking = false; } +} +setInterval(tick, 60_000); +// A wallet that just told us it is listening must not wait for the next +// minute — or for a tick that already looked past its entry: run again as +// soon as the current pass is done. +function kickRetry() { if (retryTicking) retryAgain = true; else tick().catch(() => {}); } async function retryTick() { // always sync: it reads ark mail AND drives pending actions (a board // waiting out its confirmations, an ln-recv mid-claim, a queued top-up) @@ -1463,6 +1469,31 @@ Bun.serve({ return json({ receipts: receipts.slice(0, 100) }); } + // A wallet on another ark server (Second, a custom captaind) can only be + // paid over Lightning, and only while it is open to answer our offer + // request; the queue's hourly retry with its six-second window rarely + // overlapped a short phone session (manna's 52 sats: 449 tries from + // 2026-10-18). The wallet says so once its offer listener is up, and + // whatever is queued for its names goes now. NIP-98 authed: only the + // owner (or manager) can hurry their own payments along. + if (url.pathname === '/listening' && req.method === 'POST') { + if (!rateOk(ip, 30)) return json({ error: 'rate limited' }, 429); + const bodyText = await req.text(); + const a = await checkNip98(req, url, bodyText); + if (a.error) return json({ error: a.error }, 401); + const mine = (state.pending || []).filter((p) => { + const rec = state.names[p.name]; + return p.pubkey === a.pubkey || rec?.pubkey === a.pubkey || rec?.manager === a.pubkey; + }); + for (const p of mine) p.next = 0; + if (mine.length) { + log(`${mine.map((p) => p.name).join(', ')} is listening — ${mine.length} queued forward(s) go now`); + persist(); + kickRetry(); + } + return json({ waiting: mine.length, sat: mine.reduce((n, p) => n + p.sat, 0) }); + } + // Prefix search over registered names — powers recipient search in the // wallet's DMs. Public data (every name is a public DNS record). if (url.pathname === '/search' && req.method === 'GET') { |
