Game POL pays to any LINKED wallet (Marty approved "build all three", 2026-10-27)
- walletnudge.js: the hourly push hands the member's signature-linked wallet (accounts.address, only set by auth.verifyChallenge -> accounts.linkWallet) to every game holding an unpaid balance, activated or not; memberId is the on-chain id when there is one, else 0 (a failed chain read falls back to the stored id instead of skipping the row). Holding-tank members waiting to switch on payouts no longer have their game POL stuck. Game side unchanged contract: signed POST, fill-empty-only (different wallet = 409, retried once a day), idempotent. - Nudge copy (no linked wallet only): "You've earned X POL in <game>. Link your wallet (one free signature) and it's sent automatically, including everything you've earned so far." + /my#wallet; never mentions switching on payouts. - The IAP -> game /auth tokens already carried wallet: a.address regardless of activation (no change). - chatbot.js: game-pol-wallet canned answer (ahead of the per-game entries) + GAME POL TO ANY LINKED WALLET prompt fact - qa/walletnudge.test.cjs (mock game: non-activated push with memberId 0, activated push, chain-read failure, nudge copy, 409 refusal + daily retry), wired into qa/run.sh member + walletnudge; chatbot-parse routing cases for the new answer Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+18
-10
@@ -9,6 +9,10 @@
|
||||
// account has a wallet that is an on-chain member (the same a.address the hand-off token carries) is PUSHED to that game's
|
||||
// signed POST /api/iap/wallet instead of nudged; the game's own payout sweep then pays it. Idempotent on the game side (the same
|
||||
// wallet twice is a no-op, a different one is refused), so the deploy overlap's two copies cannot do harm.
|
||||
// Any linked wallet (Marty, 2026-10-27, "build all three"): the push no longer waits for the wallet to be an on-chain member. A
|
||||
// holding-tank member can wait a day or more before switching on payouts, and their game POL sat unpaid with the nudges stopped.
|
||||
// accounts.address is only ever set after a verified wallet signature (auth.verifyChallenge -> accounts.linkWallet), so that is
|
||||
// the wallet every game pays. memberId goes along when the chain knows one, else 0.
|
||||
// nudge: false = push only. PolyBreak, SpellWheel and PolyWarriors joined 2026-10-25 push-only; Marty turned their nudges on the same day.
|
||||
const fs = require('fs'), path = require('path'), crypto = require('crypto'), https = require('https'), http = require('http');
|
||||
let R = {}, DATA_DIR = '.';
|
||||
@@ -48,11 +52,13 @@ function pushWallet(g, body) {
|
||||
rq.end(raw);
|
||||
});
|
||||
}
|
||||
// the wallet to push for an account: its linked address, only when that address is an on-chain member -> { wallet, memberId } | null
|
||||
async function activatedWallet(a) {
|
||||
if (!a || !a.address || !/^0x[a-f0-9]{40}$/i.test(a.address) || !R.chain || !R.chain.memberIdByAccount) return null;
|
||||
const id = await R.chain.memberIdByAccount(a.address); // throws on an RPC failure: the caller skips this row until next hour
|
||||
return Number(id) > 0 ? { wallet: a.address, memberId: Number(id) } : null;
|
||||
// the wallet to push for an account: its signature-linked address, activated or not -> { wallet, memberId } | null
|
||||
// memberId is the on-chain member id when there is one, else 0; a failed chain read falls back to the account's stored id.
|
||||
async function linkedWallet(a) {
|
||||
if (!a || !a.address || !/^0x[a-f0-9]{40}$/i.test(a.address)) return null;
|
||||
let id = Number(a.memberId) || 0;
|
||||
if (R.chain && R.chain.memberIdByAccount) { try { id = Number(await R.chain.memberIdByAccount(a.address)) || 0; } catch (e) { console.warn('walletnudge chain read', e.message); } }
|
||||
return { wallet: a.address, memberId: id > 0 ? id : 0 };
|
||||
}
|
||||
function fetchRows(g) {
|
||||
return new Promise(resolve => {
|
||||
@@ -66,12 +72,14 @@ function fetchRows(g) {
|
||||
rq.on('timeout', () => { rq.destroy(); resolve(null); }); rq.on('error', () => resolve(null));
|
||||
});
|
||||
}
|
||||
// copy (Marty, 2026-10-27): the ask is the LINK step only (one free signature), never "switch on payouts": a linked wallet is paid
|
||||
function copy(games, stage, link) {
|
||||
const total = games.reduce((n, g) => n + g.unpaid, 0);
|
||||
const list = games.map(g => g.unpaid.toFixed(2) + ' POL from ' + g.name).join(', ');
|
||||
const parts = games.map(g => g.unpaid.toFixed(2) + ' POL in ' + g.name);
|
||||
const list = parts.length > 1 ? parts.slice(0, -1).join(', ') + ' and ' + parts[parts.length - 1] : parts[0];
|
||||
const subject = total.toFixed(2) + ' POL is waiting for your wallet';
|
||||
const p1 = 'You have ' + list + ' sitting in your game balance' + (games.length > 1 ? 's' : '') + '. It cannot be paid out yet because no wallet is linked to your InstantAdPay account.';
|
||||
const p2 = 'Link a wallet on your Wallet tab. It is one free signature, no transaction, and it cannot move funds. Your POL pays out on the next sweep, and every game pays that same wallet from then on.';
|
||||
const p1 = "You've earned " + list + ". Link your wallet (one free signature) and it's sent automatically, including everything you've earned so far.";
|
||||
const p2 = 'It is not a transaction and it cannot move funds. Every game pays that same wallet from then on.';
|
||||
const p3 = stage >= 2 ? 'This is the last reminder about this balance. It stays yours; it just waits for a wallet.' : 'Not sure which wallet to use? SafePal is the one we recommend; MetaMask and Phantom work too. The Wallet tab has a short guide.';
|
||||
const text = [p1, '', p2, '', 'Link your wallet: ' + link, '', p3].join('\n');
|
||||
const html = '<p>' + esc(p1).replace(esc(list), '<b>' + esc(list) + '</b>') + '</p><p>' + esc(p2) + '</p><p><a href="' + esc(link) + '"><b>Link your wallet</b></a></p><p>' + esc(p3) + '</p>';
|
||||
@@ -88,9 +96,9 @@ async function tick() {
|
||||
if (!email && Number(r.memberId) > 0 && R.accounts.byMemberId) { acct = await R.accounts.byMemberId(Number(r.memberId)); email = acct ? acct.email : ''; }
|
||||
if (!email) continue;
|
||||
const unpaid = Math.max(0, Number(r.unpaid) || 0);
|
||||
// the IAP account already has an activated wallet: hand it to the game instead of asking the member for it
|
||||
// the IAP account already has a linked wallet (activated or not): hand it to the game instead of asking the member for it
|
||||
if (!acct) acct = await R.accounts.byEmail(email);
|
||||
let act = null; try { act = await activatedWallet(acct); } catch (e) { console.warn('walletnudge chain read', e.message); continue; }
|
||||
const act = await linkedWallet(acct);
|
||||
if (act) {
|
||||
const pk = g.key + ':' + email, prev = S.pushes[pk];
|
||||
// a refusal (different wallet already in the game, unknown player) is retried once a day, never every hour
|
||||
|
||||
Reference in New Issue
Block a user