22407fe9ae
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
3.8 KiB
Python
37 lines
3.8 KiB
Python
# Game pool guardrail (Marty, 2026-10-03): a game's POL pool must only grow from REAL money. gamePurchase now reports
|
|
# `paid` = the purchased part of the charge (earned viewing credits are spent first and are not money), and the Gem Kingdom
|
|
# and Spooky Doors receipts carry it so the games book poolSharePct of `paid`, never of earned credits.
|
|
ROOT = 'D:/Projects/HighRisk/onchain-ad-membership/site/'
|
|
def edit(path, pairs):
|
|
b = open(ROOT + path, 'rb').read(); crlf = b.count(b'\r\n') > b.count(b'\n') // 2
|
|
s = b.decode('utf-8').replace('\r\n', '\n')
|
|
for a, r in pairs:
|
|
if s.count(a) != 1: raise SystemExit('%s anchor %d: %s' % (path, s.count(a), a[:70]))
|
|
s = s.replace(a, r)
|
|
if crlf: s = s.replace('\n', '\r\n')
|
|
open(ROOT + path, 'wb').write(s.encode('utf-8')); print('patched', path)
|
|
|
|
edit('ads.js', [
|
|
(" let memberId = best.memberId || (ids || [])[0] || 0;\n if (free < credits) {",
|
|
" let memberId = best.memberId || (ids || [])[0] || 0;\n"
|
|
" // the purchased part: from the shared pool, earned viewing credits go first (spendEarned keeps purchase_grade longest);\n"
|
|
" // from a position's balance it is all purchased. Games fund their POL pools from this, never from earned credits.\n"
|
|
" let paid = credits - Math.min(Math.max(0, bal.earned || 0), credits);\n"
|
|
" if (free < credits) { paid = credits;"),
|
|
(" return { ok: true, campaignId: c.id, charged: credits };\n}\n// ---- admin ----",
|
|
" return { ok: true, campaignId: c.id, charged: credits, paid: Math.max(0, Math.min(credits, paid)) };\n}\n// ---- admin ----"),
|
|
])
|
|
edit('server.js', [
|
|
# Gem Kingdom: remember paid, put it on both receipts
|
|
("if (done && done.status === 'paid') { const rc = gkMint({ kind: 'gk-receipt', order: c.order, email: c.email, crowns: c.crowns, credits: c.credits, ref: done.campaignId }, 24 * 3600000);",
|
|
"if (done && done.status === 'paid') { const rc = gkMint({ kind: 'gk-receipt', order: c.order, email: c.email, crowns: c.crowns, credits: c.credits, paid: done.paid != null ? done.paid : c.credits, ref: done.campaignId }, 24 * 3600000);"),
|
|
(" gkOrders.set(c.order, { status: 'paid', email: s.email, campaignId: out.campaignId, ts: Date.now() });\n console.log('gemkingdom crowns', s.email, c.crowns, 'for', c.credits, 'credits, campaign', out.campaignId);\n const rc = gkMint({ kind: 'gk-receipt', order: c.order, email: String(c.email).toLowerCase(), crowns: Number(c.crowns), credits: Number(c.credits), ref: out.campaignId }, 24 * 3600000);",
|
|
" gkOrders.set(c.order, { status: 'paid', email: s.email, campaignId: out.campaignId, paid: out.paid, ts: Date.now() });\n console.log('gemkingdom crowns', s.email, c.crowns, 'for', c.credits, 'credits (' + out.paid + ' purchased), campaign', out.campaignId);\n const rc = gkMint({ kind: 'gk-receipt', order: c.order, email: String(c.email).toLowerCase(), crowns: Number(c.crowns), credits: Number(c.credits), paid: Number(out.paid), ref: out.campaignId }, 24 * 3600000);"),
|
|
# Spooky Doors: same
|
|
("const rc = sdMint({ kind: 'sd-receipt', order: c.order, email: String(c.email).toLowerCase(), item: String(c.item), credits: Number(c.credits), ref: done.campaignId }, 24 * 3600000);",
|
|
"const rc = sdMint({ kind: 'sd-receipt', order: c.order, email: String(c.email).toLowerCase(), item: String(c.item), credits: Number(c.credits), paid: done.paid != null ? done.paid : Number(c.credits), ref: done.campaignId }, 24 * 3600000);"),
|
|
(" const rc = sdMint({ kind: 'sd-receipt', order: c.order, email: String(c.email).toLowerCase(), item: String(c.item), credits: Number(c.credits), ref: out.campaignId }, 24 * 3600000);",
|
|
" const rc = sdMint({ kind: 'sd-receipt', order: c.order, email: String(c.email).toLowerCase(), item: String(c.item), credits: Number(c.credits), paid: Number(out.paid), ref: out.campaignId }, 24 * 3600000);"),
|
|
])
|
|
print('ok')
|