Sponsor follow + one network holding tank + Sponsor check (Marty, 2026-10-22, approved 1-3)
Deliberate sponsor changes (tank adoption, dormant-lead rescue, release, adoption window ending, admin edit) are now recorded (sponsorfollow.json: when, how, the sponsor before, origin) and travel on the LinkSpin sync rows as sponsorSetAt/By/PrevEmail/Origin. A deliberate change from LinkSpin is applied here (a clear back to the tank included) only when the member is not bound on the InstantAdPay contract (memberId or wallet on chain), it is newer than our own deliberate change, and both sides agreed before it (or we have no sponsor). Bound, diverged and race cases change nothing and are logged. Race within 15 min: the earlier change wins on both. Ordinary bindings keep the first-platform rule. Accounts with no record behave as before; rows without the new facts hash exactly as before (no resend on deploy). Network tank: rows carry this site's own adoptions of a person; the waiting list hides someone adopted on LinkSpin, the two-adoptions limit counts both sites, the 3-day hold applies to a LinkSpin adoption too, follows close local open adoptions quietly (no chat, mail or feed post). Admin > Members > Sponsor check: shared members whose sponsor differs or is one-sided, each side's when/how, chain binding, and Use InstantAdPay's / Use LinkSpin's sponsor (applied on the other site, refused when bound there). Partner endpoints /api/partner/sponsor-facts and /api/partner/sponsor-apply (same HMAC as the registry rows). Tests: qa/sponsorfollow.test.cjs 27/27, qa/sponsorfollow-e2e.mjs 20/20 (local IAP + local LinkSpin, throwaway data), QA member walk 0 bugs. No sponsor was changed on production. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -49,6 +49,15 @@ const sbcheck = require('./sbcheck');
|
||||
const reach = require('./reach');
|
||||
const lssync = require('./lssync');
|
||||
const lsinbound = require('./lsinbound'); // reverse registry sync: LinkSpin-first members arrive as waiting accounts (2026-10-15)
|
||||
const SF = require('./sponsorfollow'); // deliberate sponsor changes follow to LinkSpin until chain-bound + one network tank (2026-10-22)
|
||||
let follow = null, followStore = null;
|
||||
const LS_BASE = () => String(process.env.LS_URL || 'https://linkspin.app').replace(/\/+$/, '');
|
||||
let activationCache = { at: 0, map: null };
|
||||
function activationByAddress() { // MemberActivated events by wallet, for the Sponsor check (when the contract bound the sponsor)
|
||||
if (activationCache.map && Date.now() - activationCache.at < 60000) return activationCache.map;
|
||||
const m = new Map(); for (const ev of chain.recentEvents(1e9)) if (ev.type === 'MemberActivated' && ev.account) { const k = String(ev.account).toLowerCase(); if (!m.has(k)) m.set(k, { id: ev.id, sponsorId: ev.sponsorId, block: ev.block, tx: ev.tx }); }
|
||||
activationCache = { at: Date.now(), map: m }; return m;
|
||||
}
|
||||
const gamestats = require('./gamestats');
|
||||
const marks = require('./marks');
|
||||
const gamepass = require('./gamepass'); // the $5 weekly Game Pass + the account-wide POL cap service the games call (2026-10-16)
|
||||
@@ -572,12 +581,27 @@ async function boot() {
|
||||
override.init({ dataDir: DATA_DIR, chain, siteConfig, notify: supportTelegram });
|
||||
setInterval(() => override.tick().catch(e => console.error('override', e.message)), 30 * 60 * 1000);
|
||||
setInterval(() => snapshot.tick().catch(e => console.error('snapshot', e.message)), 10 * 60 * 1000);
|
||||
tank.init({ dataDir: DATA_DIR, chain, accounts, messages, mailer, ads, site: 'https://instantadpay.com' });
|
||||
// sponsor follow (sponsorfollow.js): a deliberate change (tank adoption, rescue, release, window expiry, admin edit) is
|
||||
// recorded and follows to LinkSpin, and LinkSpin's deliberate changes are applied here, until the member is bound on
|
||||
// InstantAdPay's contract (memberId, or the wallet already on chain). Ordinary bindings keep the first-platform rule.
|
||||
followStore = SF.create({ dataDir: DATA_DIR, platform: 'instantadpay' });
|
||||
follow = SF.glue({ store: followStore, accounts, tank: () => tank, peer: 'linkspin',
|
||||
isBound: async a => {
|
||||
if (Number(a.memberId) > 0) return { bound: true, why: 'InstantAdPay member #' + a.memberId };
|
||||
if (!a.address) return { bound: false };
|
||||
try { const id = Number(await chain.memberIdByAccount(a.address)) || 0; return id ? { bound: true, why: 'wallet is InstantAdPay member #' + id } : { bound: false }; }
|
||||
catch (e) { return { retry: true, why: 'InstantAdPay chain read failed' }; }
|
||||
},
|
||||
sponsorAccount: em => accounts.byEmail(em),
|
||||
wouldCycle: async (email, sp) => { let cur = sp; const seen = new Set(); for (let i = 0; cur && i < 60; i++) { if (cur.email === email || seen.has(cur.email)) return true; seen.add(cur.email); cur = await accounts.sponsorOf(cur.email); } return false; },
|
||||
activationOf: a => a.address ? activationByAddress().get(String(a.address).toLowerCase()) || null : null });
|
||||
tank.init({ dataDir: DATA_DIR, chain, accounts, messages, mailer, ads, site: 'https://instantadpay.com', follow, store: followStore });
|
||||
// LinkSpin registry sync (2026-10-08): every account change is pushed to LinkSpin within seconds; a 2-minute reconcile catches the rest
|
||||
lssync.init({ dataDir: DATA_DIR, accounts }); accounts.onChange(email => lssync.touch(email));
|
||||
lsinbound.init({ dataDir: DATA_DIR, accounts, lssync });
|
||||
lssync.init({ dataDir: DATA_DIR, accounts, follow: followStore, tank: () => tank }); accounts.onChange(email => lssync.touch(email));
|
||||
lsinbound.init({ dataDir: DATA_DIR, accounts, lssync, follow, store: followStore });
|
||||
setTimeout(() => lssync.tick().catch(e => console.error('lssync', e.message)), 2 * 60 * 1000);
|
||||
setInterval(() => lssync.tick().catch(e => console.error('lssync', e.message)), 2 * 60 * 1000);
|
||||
setInterval(() => follow.retryPending().catch(e => console.error('sponsorfollow retry', e.message)), 2 * 60 * 1000); // follows waiting on a chain read or a sponsor account
|
||||
walletnudge.init({ dataDir: DATA_DIR, accounts, mailer, optedIn: updates.optedIn, site: 'https://instantadpay.com',
|
||||
message: async (to, subject, html) => { await messages.deliver(1, ADMIN_EMAIL || 'house@instantadpay.com', [to], subject, html, 'notice'); } });
|
||||
setTimeout(() => walletnudge.tick().catch(e => console.error('walletnudge', e.message)), 3 * 60 * 1000); // past the deploy overlap window
|
||||
@@ -2750,7 +2774,7 @@ const server = http.createServer(async (req, res) => {
|
||||
const r = await accounts.setUsername(e, un); if (r.error) return json(res, 400, r);
|
||||
console.log('admin username', e, un);
|
||||
}
|
||||
if (b.sponsorRef !== undefined) { const r = await accounts.setSponsorRef(e, String(b.sponsorRef || '').trim()); if (r.error) return json(res, 400, r); console.log('admin sponsor', e, String(b.sponsorRef || '').trim()); }
|
||||
if (b.sponsorRef !== undefined) { const r = await follow.setDeliberate(e, String(b.sponsorRef || '').trim(), 'admin', 'admin member card'); if (r.error) return json(res, 400, r); console.log('admin sponsor', e, String(b.sponsorRef || '').trim()); } // deliberate: follows to LinkSpin until bound
|
||||
if (b.address !== undefined) {
|
||||
const a = String(b.address || '').trim().toLowerCase();
|
||||
if (a && !/^0x[0-9a-f]{40}$/.test(a)) return json(res, 400, { error: 'That is not a wallet address.' });
|
||||
@@ -3094,6 +3118,43 @@ const server = http.createServer(async (req, res) => {
|
||||
const rows = Array.isArray(b.rows) ? b.rows.slice(0, 500) : [];
|
||||
return json(res, 200, Object.assign({ ok: true }, await lsinbound.receive(rows)));
|
||||
}
|
||||
// -- sponsor check between InstantAdPay and LinkSpin (2026-10-22, sponsorfollow.js). Partner side: LinkSpin reads our
|
||||
// facts and, on an admin's pick in ITS Sponsor check, asks us to apply a sponsor (refused when the member is bound here).
|
||||
if (p === '/api/partner/sponsor-facts' && req.method === 'POST') {
|
||||
const sg = await readLsSigned(req, 2e6); if (!sg.body) return json(res, sg.status, { error: sg.error });
|
||||
const emails = Array.isArray(sg.body.emails) ? sg.body.emails.slice(0, 5000) : null;
|
||||
return json(res, 200, { ok: true, proto: SF.PROTO, platform: 'instantadpay', rows: await follow.facts(emails), view: followStore.view() });
|
||||
}
|
||||
if (p === '/api/partner/sponsor-apply' && req.method === 'POST') {
|
||||
const sg = await readLsSigned(req, 64000); if (!sg.body) return json(res, sg.status, { error: sg.error });
|
||||
const b = sg.body; const r = await follow.adminApply(b.email, b.sponsorEmail || null, { note: String(b.note || 'Sponsor check on LinkSpin').slice(0, 120) });
|
||||
console.log('sponsor check (from LinkSpin)', b.email, '->', b.sponsorEmail || '(tank)', r.error || 'ok');
|
||||
return json(res, r.error ? 400 : 200, r);
|
||||
}
|
||||
if (p === '/api/admin/sponsor-check' && req.method === 'GET') {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
const mine = await follow.facts(); let peer = null, peerError = null;
|
||||
try { peer = await SF.peerPost(LS_BASE(), '/api/partner/sponsor-facts', { all: true }, 90000); } catch (e) { peerError = e.message; }
|
||||
const mm = peer ? SF.mismatches(mine, peer.rows || []) : { shared: 0, same: 0, rows: [] };
|
||||
return json(res, 200, Object.assign({ ok: true, at: Date.now(), here: 'instantadpay', peerError, follow: followStore.view(), peerFollow: peer ? peer.view : null }, mm), { 'Cache-Control': 'no-store' });
|
||||
}
|
||||
if (p === '/api/admin/sponsor-check/resolve' && req.method === 'POST') {
|
||||
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
|
||||
const b = await readBody(req); const email = String(b.email || '').trim().toLowerCase();
|
||||
if (!email) return json(res, 400, { error: 'Which member?' });
|
||||
let r;
|
||||
if (b.use === 'linkspin') { // LinkSpin's sponsor, applied HERE (refused when bound here)
|
||||
const peer = await SF.peerPost(LS_BASE(), '/api/partner/sponsor-facts', { emails: [email] }, 30000).catch(e => ({ error: e.message }));
|
||||
if (peer.error) return json(res, 502, { error: 'Could not read LinkSpin: ' + peer.error });
|
||||
const row = (peer.rows || [])[0]; if (!row) return json(res, 404, { error: email + ' has no LinkSpin account.' });
|
||||
r = await follow.adminApply(email, row.sponsorEmail || null, { note: "Sponsor check: used LinkSpin's sponsor" });
|
||||
} else if (b.use === 'instantadpay') { // our sponsor, applied ON LINKSPIN (LinkSpin refuses when bound there)
|
||||
const row = (await follow.facts([email]))[0]; if (!row) return json(res, 404, { error: email + ' has no InstantAdPay account.' });
|
||||
r = await SF.peerPost(LS_BASE(), '/api/partner/sponsor-apply', { email, sponsorEmail: row.sponsorEmail || null, note: "Sponsor check on InstantAdPay: used InstantAdPay's sponsor" }, 30000).catch(e => ({ error: e.message }));
|
||||
} else return json(res, 400, { error: 'use must be instantadpay or linkspin' });
|
||||
console.log('sponsor check resolve', email, b.use, r.error || 'ok');
|
||||
return json(res, r.error ? 400 : 200, r);
|
||||
}
|
||||
// -- help desk for LinkSpin (2026-10-16): LinkSpin has no desk of its own; its Help screen, /support page, private ticket
|
||||
// link and chat hand-off all proxy here, signed like the registry rows. LinkSpin runs the person-facing guards (sign-in,
|
||||
// honeypot, form age, icon check) and vouches for the email; this side only ever touches platform 'linkspin' tickets
|
||||
@@ -4823,7 +4884,7 @@ const server = http.createServer(async (req, res) => {
|
||||
return json(res, 200, { ok: true, signals: await fraud.get(b.email) });
|
||||
}
|
||||
if (b.flags !== undefined) { const f = b.flags === null ? (await fraud.clearFlags(b.email), []) : await fraud.addFlags(b.email, [].concat(b.flags)); return json(res, 200, { ok: true, flags: f }); }
|
||||
const r = await accounts.setSponsorRef(b.email, b.sponsorRef);
|
||||
const r = await follow.setDeliberate(b.email, b.sponsorRef, 'admin', 'admin members table'); // deliberate: follows to LinkSpin until bound
|
||||
return json(res, r.error ? 400 : 200, r);
|
||||
}
|
||||
if (p === '/api/admin/fraud' && req.method === 'GET') { // duplicate signals: shared browsers / IPs, flagged and suspended accounts
|
||||
|
||||
Reference in New Issue
Block a user