The Draft on the real holding tank (2026-11-15, LOCAL ONLY): tankpool.js 'iap' mode = signed client for InstantAdPay's draft partner routes
TANK_MODE=iap (or hub) + IAP_URL + DRAFT_PARTNER_SECRET: pool / adopt / release / status as HMAC-signed POSTs ('draft.v1.' + ts +
newline + body, X-Draft-Ts / X-Draft-Sig). The stub stays the default and keeps every existing test. adopt carries the coach claim
(wallet, hubId, username, positions = store.positionsOf) and a request id; one retry with the same rid on a network failure, so a
retry never makes two adoptions. release sends why 'coach' | 'return' + the pick's iap ref and takes InstantAdPay's outcome
(returned / kept / done). league.sweep follows a pick InstantAdPay closed first (its own 3-day sweep, a release there, a LinkSpin
follow). Surfing arrives as ad credits (surfCredits, shown "N ad credits" to coaches, +10 scouting like surf POL); games stay
"not tracked yet" (InstantAdPay has no per-member game record).
Fix found by the cross test: a tank refusal about the COACH (no InstantAdPay account, full, not vested, hub off) used to mark the
person unavailable and let the same coach choose again, which would burn the whole pool; now the slot passes (skip 'tank: <code>')
and a silent tank pauses the draft (nothing recorded, the next tick retries the same slot). Manual picks record nothing on either.
Tests: unit 62/62 (2 new: skip + wait), smoke 156/156 (ports 3561-3564), qa/iap-tank.test.cjs 23/23 (this client + league against
InstantAdPay's REAL draftpartner.js + tank.js from the sibling checkout behind a signed server on 3565, then a dead port 3566).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,12 +38,16 @@ async function pool(now) { return draft.pool(await candidates(now), store.picks(
|
||||
const ownTeam = id => { const m = store.memberByHub(id); return m && store.positionsOf(m.address) > 0 ? (store.firstPositionAt(m.address) || 1) : 0; };
|
||||
|
||||
// ---- a pick = an adoption ----
|
||||
// refusals about the COACH (the draft passes their slot instead of marking the person unavailable) and the ones that mean "try later"
|
||||
const COACH_CODES = new Set(['coach_unknown', 'not_vested', 'no_wallet', 'no_contract_line', 'excluded', 'payout_blocked', 'full', 'hub_off', 'not_eligible', 'bad_coach']);
|
||||
const WAIT_CODES = new Set(['unreachable', 'no_secret']);
|
||||
async function makePick(coach, person, kind, extra, now) {
|
||||
const c = cands.find(x => x.id === person) || { id: person };
|
||||
const r = await tank.adopt({ coach: { address: coach, username: nameOf(coach), hubId: (store.member(coach) || {}).hubId || null }, person, kind });
|
||||
if (!r || !r.ok) return { error: (r && r.error) || 'The holding tank did not answer.' };
|
||||
const r = await tank.adopt({ coach: { address: coach, username: nameOf(coach), hubId: (store.member(coach) || {}).hubId || null, positions: store.positionsOf(coach) }, person, kind,
|
||||
week: weekInfo(now).week, slot: extra && extra.slot ? extra.slot : null });
|
||||
if (!r || !r.ok) { const code = r && r.code; return { error: (r && r.error) || 'The holding tank did not answer.', code: code || null, skip: COACH_CODES.has(code) ? 'tank: ' + code : null, wait: !r || WAIT_CODES.has(code) }; }
|
||||
const s = (await tank.status([person], now))[person] || {};
|
||||
const m = Object.assign({ lastSeen: s.lastSeen || 0, username: s.username || c.username || null, wallet: s.wallet || 0, payouts: s.payouts || 0, purchase: s.purchase || 0, ownTeam: ownTeam(person) }, { door: s.door || c.door || null, games: s.games || c.games || null, surfWei: s.surfWei || c.surfWei || null });
|
||||
const m = Object.assign({ lastSeen: s.lastSeen || 0, username: s.username || c.username || null, wallet: s.wallet || 0, payouts: s.payouts || 0, purchase: s.purchase || 0, ownTeam: ownTeam(person) }, { door: s.door || c.door || null, games: s.games || c.games || null, surfWei: s.surfWei || c.surfWei || null, surfCredits: s.surfCredits != null ? s.surfCredits : (c.surfCredits != null ? c.surfCredits : null) });
|
||||
const p = store.addPick(Object.assign({ week: weekInfo(now).week, kind, coach, coachName: nameOf(coach), person, personName: c.username || s.username || null, door: c.door || null,
|
||||
status: 'open', at: now, expires: now + C.picks.returnDays * D, m, tier: draft.tierOf(m), ref: r.ref || null }, extra || {}));
|
||||
candsAt = 0; // the pool changed
|
||||
@@ -57,12 +61,22 @@ async function sweep(now) {
|
||||
if (!open.length) return { changed: 0 };
|
||||
const ids = [...new Set(open.map(p => p.person))];
|
||||
const sts = await tank.status(ids, now);
|
||||
const statusOf = id => { const s = sts[id]; if (!s) return null; return Object.assign({}, s, { ownTeam: ownTeam(id) }); };
|
||||
const statusOf = id => { const s = sts[id]; if (!s) return null; const m = Object.assign({}, s, { ownTeam: ownTeam(id) }); delete m.pick; return m; };
|
||||
// the tank closed an open pick on its side (its own 3-day sweep, a release on InstantAdPay, a LinkSpin follow): follow its outcome
|
||||
for (const p of open.filter(x => x.status === 'open')) {
|
||||
const s = sts[p.person]; const pk = s && s.pick; if (!pk || !p.ref || pk.ref !== p.ref || pk.status === 'open') continue;
|
||||
const m = statusOf(p.person); const set = pk.status === 'done' ? { status: 'done', doneAt: now } : pk.status === 'kept' ? { status: 'kept', keptAt: now } : { status: 'returned', returnedAt: now, closedBy: 'tank:' + pk.status };
|
||||
Object.assign(p, set, { m, tier: draft.tierOf(m) }); store.savePick(p); candsAt = 0;
|
||||
}
|
||||
// done / kept picks only refresh their milestones (cards keep levelling up)
|
||||
for (const p of open.filter(x => x.status !== 'open')) { const m = statusOf(p.person); if (m) { const t = draft.tierOf(m); if (t !== p.tier || JSON.stringify(m) !== JSON.stringify(p.m)) { if (t !== p.tier) p.levelAt = now; p.m = m; p.tier = t; store.savePick(p); } } }
|
||||
const ch = draft.sweep(store.picks(), statusOf, rules(), now);
|
||||
for (const c of ch) {
|
||||
if (c.release) { const r = await tank.release({ coach: c.pick.coach, person: c.pick.person, why: 'return window ended' }); if (!r || !r.ok) continue; }
|
||||
if (c.release) {
|
||||
const r = await tank.release({ coach: c.pick.coach, person: c.pick.person, ref: c.pick.ref || null, kind: 'return', why: 'return window ended' }); if (!r || !r.ok) continue;
|
||||
if (r.outcome === 'kept') c.set = Object.assign({}, c.set, { status: 'kept', keptAt: now }); else if (r.outcome === 'done') c.set = Object.assign({}, c.set, { status: 'done', doneAt: now }); // the tank decides
|
||||
delete c.set.returnedAt; if (c.set.status === 'returned') c.set.returnedAt = now;
|
||||
}
|
||||
if (c.set.tier && c.set.tier !== c.pick.tier) c.pick.levelAt = now; // the toast time, on the league clock
|
||||
Object.assign(c.pick, c.set); store.savePick(c.pick);
|
||||
}
|
||||
@@ -118,6 +132,7 @@ async function manualPick(coach, person) {
|
||||
await candidates(now);
|
||||
const act = draft.manual(d, coach, person, ctx(d, now), now); if (act.error) return act;
|
||||
const res = await makePick(coach, person, 'draft', { slot: draft.slotLabel(act.slot), round: act.slot.round, auto: false }, now);
|
||||
if (res.error && (res.wait || res.skip)) return { error: res.error }; // nothing recorded: the person stays available, the clock keeps running
|
||||
draft.record(d, act, res, now); store.putDraft(d);
|
||||
if (res.error) return res;
|
||||
await advance(d, now);
|
||||
@@ -142,7 +157,8 @@ async function release(coach, pickId) {
|
||||
const now = clock.now(); const p = store.pick(pickId);
|
||||
if (!p || p.coach !== coach) return { error: 'Not your pick.' };
|
||||
const why = draft.canRelease(p, rules(), now); if (why) return { error: why };
|
||||
const r = await tank.release({ coach, person: p.person, why: 'released by the coach' }); if (!r || !r.ok) return { error: (r && r.error) || 'The holding tank did not answer.' };
|
||||
const r = await tank.release({ coach, person: p.person, ref: p.ref || null, kind: 'coach', why: 'released by the coach' }); if (!r || !r.ok) return { error: (r && r.error) || 'The holding tank did not answer.' };
|
||||
if (r.outcome === 'done') { p.status = 'done'; p.doneAt = now; store.savePick(p); candsAt = 0; return { error: 'They already started, so they stay on your team.' }; }
|
||||
p.status = 'returned'; p.releasedAt = now; p.released = true; store.savePick(p); candsAt = 0;
|
||||
return { ok: true };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user