From 3cc687aff5ac82416d1362b96eb5a41d53e07e9c Mon Sep 17 00:00:00 2001 From: martbost Date: Wed, 11 Nov 2026 08:58:10 -0600 Subject: [PATCH] Holding tank admin grant: POST /api/admin/tank/grant {adopter, count} assigns N real BTC4Hits imports on top of the cap as auto adoptions, skipping the bot patterns (yandex, dotted gmail); adopt/eligibility take skipCap (Marty 2026-11-11: the adopters who picked up the Yandex batch keep them and get the same number more). tank-cap 15/15, tank-hold all passed Co-Authored-By: Claude Opus 5.5 --- server.js | 5 +++++ tank.js | 21 +++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index e3a2df9..8b8e2b4 100644 --- a/server.js +++ b/server.js @@ -2614,6 +2614,11 @@ const server = http.createServer(async (req, res) => { const r = await tank.recordGift(s.email, b.email, b.tx, b.pol); return json(res, r.error ? 400 : 200, r); } + if (p === '/api/admin/tank/grant' && req.method === 'POST') { // admin: assign N real BTC4Hits imports to an adopter on top of the cap (Marty 2026-11-11) + if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); + const b = await readBody(req); const a = await adminMember.resolve(String(b.adopter || '')); if (!a) return json(res, 404, { error: 'No member matches that adopter.' }); + tankWaitCache = null; return json(res, 200, await tank.grant(a.email, b.count)); + } if (p === '/api/admin/tank' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, await tank.adminView()); diff --git a/tank.js b/tank.js index f684f46..f850cf1 100644 --- a/tank.js +++ b/tank.js @@ -104,13 +104,13 @@ function hasOwnBuy(memberId) { for (const ev of chain.recentEvents(200000)) if (ev.type === 'Purchase' && ev.buyerId === memberId && Number(ev.priceCents) >= MIN_OWN_BUY_CENTS) return true; return false; } -async function eligibility(email) { +async function eligibility(email, opts) { const a = await accounts.byEmail(email); if (!a) return { ok: false, reason: 'Sign in first.' }; if (!a.memberId) return { ok: false, reason: 'Switch on payouts and buy your first $25 package to adopt from the tank.' }; if (!hasOwnBuy(a.memberId)) return { ok: false, reason: 'Buy your own $25 or larger package first. Adopting is for members who have made that move themselves.' }; const open = await impl().open(a.email); const held = await holding(open); const cap = capOpen(); - if (held.length >= cap) return { ok: false, reason: 'You are already helping ' + held.length + ' people from the holding tank, and ' + cap + ' at one time is the most anyone can hold. A slot opens when one of them switches on payouts, or when their 7-day window ends.', full: true, cap, held: held.length }; + if (held.length >= cap && !(opts && opts.skipCap)) return { ok: false, reason: 'You are already helping ' + held.length + ' people from the holding tank, and ' + cap + ' at one time is the most anyone can hold. A slot opens when one of them switches on payouts, or when their 7-day window ends.', full: true, cap, held: held.length }; return { ok: true, account: a, open }; } @@ -128,7 +128,7 @@ async function view(email) { async function adopt(adopterEmail, who, note, opts) { const auto = !!(opts && opts.auto); // the 24-hour safety net (autoAssign): same path, a different record note, both sides emailed const e = String(adopterEmail || '').toLowerCase(); - const el = await eligibility(e); + const el = await eligibility(e, { skipCap: !!(opts && opts.skipCap) }); // skipCap: an admin grant on top of the cap (Marty 2026-11-11) if (!el.ok) return { error: el.reason }; const me = el.account; const key = String(who || '').trim().toLowerCase().replace(/^@/, ''); @@ -671,4 +671,17 @@ async function adminView() { return { waiting: await waiting(), adoptions: recent.map(ad => Object.assign({}, ad, { adopteeName: names[ad.adoptee], adopterName: names[ad.adopter] })), cap: capOpen(), ttlDays: TTL_MS / 86400000, holdHours: READY_MS / 3600000, aligned: alignedRecent(30) }; } -module.exports = { init, view, adopt, holdFor, gate, markReady, readyRec, readyTick, autoAssign, alignToNetwork, alignedRecent, setClock, eligibility, inTank, READY_MS, release, sweep, rescueSweep, rescueInfo, markContacted, adminView, waiting, adoptable, adoptableOf, openedSince, leftText, inviteAsk, dismissInvite, nameSponsor, GRACE_MS, hasOwnBuy, recordGift, onFollow, summaryMap, summaryFor, historyMap, capOpen, TTL_MS, WARN_DAYS, RESCUE_DAYS, MAX_ADOPTIONS }; +// admin grant (Marty 2026-11-11): the adopters who picked up the Yandex batch from the BTC4Hits import keep those, and get the same number of +// real imports assigned on top of the cap. Picks BTC4Hits imports from the waiting list, skipping the bot patterns (yandex, dotted gmail). +const JUNK = e => /@yandex\./i.test(e) || (/@gmail\.com$/i.test(e) && (e.split('@')[0].match(/\./g) || []).length >= 3); +async function grant(adopterEmail, count) { + const out = []; let left = Math.max(0, Math.min(20, Number(count) || 0)); + for (const w of await waiting()) { + if (!left) break; if (JUNK(w.email)) continue; + const a = await accounts.byEmail(w.email); if (!a || !(a.joinedRef === 'btc4hits' || a.joinedVia === 'btc4hits')) continue; + const r = await adopt(adopterEmail, w.email, '', { auto: true, skipCap: true, recordNote: 'Admin grant (BTC4Hits import)' }); + out.push({ adoptee: mask(w.email), ok: !r.error, error: r.error || undefined }); if (!r.error) left--; + } + return { adopter: adopterEmail, assigned: out.filter(x => x.ok).length, tried: out }; +} +module.exports = { grant, init, view, adopt, holdFor, gate, markReady, readyRec, readyTick, autoAssign, alignToNetwork, alignedRecent, setClock, eligibility, inTank, READY_MS, release, sweep, rescueSweep, rescueInfo, markContacted, adminView, waiting, adoptable, adoptableOf, openedSince, leftText, inviteAsk, dismissInvite, nameSponsor, GRACE_MS, hasOwnBuy, recordGift, onFollow, summaryMap, summaryFor, historyMap, capOpen, TTL_MS, WARN_DAYS, RESCUE_DAYS, MAX_ADOPTIONS };