Game Pass: no pass is ever bought with credits again (Marty, 2026-10-22). Buy only opens a waiting order and sends the member to buy a package of at least the tier price; the order is fulfilled only by a fresh on-chain package Purchase by one of the member's own positions (main or linked), mined after the order was opened (block time, 30 s clock grace), each purchase tx used once across every account. The member keeps the package credits for ads; sponsors and team are paid by the package as usual. Existing passes untouched. Card and confirm copy say so; my.js tag bumped. qa/gamepass.mjs updated for the new flow (older-than-order, too small, another member, replayed tx): ALL PASS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-22 12:42:59 -05:00
parent 839c867595
commit 6a3313a861
5 changed files with 100 additions and 58 deletions
+6 -5
View File
@@ -624,6 +624,7 @@ async function boot() {
blog.init({ dataDir: DATA_DIR });
adminMember.init({ accounts, ads, chain, tank, legacy, promos, messages, dataDir: DATA_DIR });
gamepass.init({ dataDir: DATA_DIR, siteConfig, accounts, marks, isProd: IS_PROD, persistedMap, polUsd: polUsdLive,
blockTime: async n => { const blk = await chain.rpc('eth_getBlockByNumber', ['0x' + Number(n).toString(16), false]); return blk && blk.timestamp ? parseInt(blk.timestamp, 16) : 0; }, // a pass order is fulfilled only by a purchase mined after it
telegram: async html => { const sc = siteConfig(); const chat = String(sc.telegramGamesChatId || sc.telegramEchoChatId || '').trim(); if (!sc.telegramBotToken || !chat) return false; await telegramSend(chat, html, sc.telegramGamesTopicId || null); return true; },
notify: (to, subject, html) => messages.deliver(1, ADMIN_EMAIL || 'house@instantadpay.com', [to], subject, html, 'notice') }); // before loadOpenTokens: its maps must exist to be restored
loadOpenTokens();
@@ -3965,14 +3966,14 @@ const server = http.createServer(async (req, res) => {
if (p === '/api/my/gamepass/buy' && req.method === 'POST') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
if (fraud.isSuspended(s.email)) return json(res, 403, { error: 'This account is suspended.' });
const b = await readBody(req); const { ids } = await myMemberIds(s);
// purchased-grade credits only, from a position's package balance (the PolyWarriors mint rule); devPaid = local tests only
const charge = (!IS_PROD && b.devPaid) ? async () => ({ ok: true, campaignId: 0, dev: true }) : (price, label) => ads.gamePurchase(s.email, ids, price, label, 'https://instantadpay.com/my#games', { purchasedOnly: true });
const b = await readBody(req);
// 2026-10-22 (Marty): no pass is ever bought with credits. Buy only opens a waiting order; a FRESH package purchase of at least the
// tier price, by one of this member's own positions, fulfils it (gamepass.onEvent), so the sponsor and team are paid as usual.
// tier: weekly (missing) | explorer | champion | sovereign | legend; every tier above weekly is refused unless sovTiers is on, except for the ADMIN_EMAIL account (testing)
const r = await gamepass.buy(s.email, charge, gpDevNow(b.devDay), b.tier, { admin: !!ADMIN_EMAIL && String(s.email).toLowerCase() === ADMIN_EMAIL });
const r = gamepass.buy(s.email, gpDevNow(b.devDay), b.tier, { admin: !!ADMIN_EMAIL && String(s.email).toLowerCase() === ADMIN_EMAIL });
return json(res, r.error ? 400 : 200, r);
}
if (!IS_PROD && p === '/api/dev/gamepass-purchase' && req.method === 'POST') { const b = await readBody(req); return json(res, 200, { order: await gamepass.onEvent({ type: 'Purchase', priceCents: Number(b.cents) || 500, buyerId: 0, tx: '0x' + crypto.randomBytes(32).toString('hex'), ts: Date.now(), devEmail: b.email }) }); } // local tests only
if (!IS_PROD && p === '/api/dev/gamepass-purchase' && req.method === 'POST') { const b = await readBody(req); return json(res, 200, { order: await gamepass.onEvent({ type: 'Purchase', priceCents: Number(b.cents) || 500, buyerId: 0, tx: /^0x[0-9a-f]{64}$/.test(String(b.tx || '')) ? b.tx : '0x' + crypto.randomBytes(32).toString('hex'), ts: Date.now(), devEmail: b.email, devMinedAt: Number(b.minedAt) || 0, devNow: Number(b.now) || 0 }) }); } // local tests only (minedAt fakes the block time, now the fulfilment time, tx replays a hash)
if (p === '/api/admin/gamepass/stats' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, gamepass.adminStats()); }
if (p === '/api/admin/gamepass/comp' && req.method === 'POST') { // support: give an account a pass week without a purchase
if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); const b = await readBody(req); const e = String(b.email || '').trim().toLowerCase(); if (!e) return json(res, 400, { error: 'email required' });