Find a Member: public lookup at /lookup (Marty 2026-11-14)

One box: member ID or wallet address -> member ID, wallet (short, full on
hover + Copy), level and tier, join date, sponsor ID (clickable), direct
referral count, Polygonscan link, public dashboard link. Chain facts only,
never names or emails. RM Circle only; nothing from any other site.

- chain.lookupPublic: served from the indexed state (zero RPC); only a
  position or wallet the index has not seen yet falls back to one eth_call
  (memberId(address) 0x39106821, verified live: 0x7c7D...d3c2 -> 7230)
- /api/public/lookup: own 12/min per-IP limiter, 3-minute answer cache
  (negative answers too), global budget of 60 RPC fallbacks per minute
- page lookup.html + lookup.js (no inline script), ?q= deep links, /find alias
- "Find a Member" in every site footer; chat.js?v=20261114a
- chatbot: canned answer in chat.js + FACT line and Site pages entry in the
  AI system prompt
- tests: qa/lookup-unit.mjs (25), qa/lookup-e2e.mjs (51, desktop + phone,
  CSP, no-email, rate limit) against qa/harness-server.js LOOKUP_SEED

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-14 12:53:19 -06:00
parent 2549f116aa
commit 0254f933be
40 changed files with 478 additions and 45 deletions
+57 -1
View File
@@ -792,6 +792,60 @@ function memberIdByAccount(address) {
return null;
}
// --- Public "Find a member" lookup (/lookup). Index first, RPC only on a miss.
// The indexed state already holds every position's account, sponsor, tier, level,
// direct count and join time (daily snapshot + the one-minute log tail), so a normal
// lookup costs ZERO RPC calls. Only a position or wallet the index has not seen yet
// (joined since the last tick, or index still cold) falls back to one eth_call.
// Returns chain facts only: never emails, names or any other off-chain data.
const SEL_MEMBER_ID = '0x39106821'; // memberId(address) -> uint48 (keccak-256 of the signature)
let acctMap = null, acctMapN = -1, acctMapAt = 0;
function idForAccountIndexed(a) {
if (!state || !state.members) return null;
const n = Object.keys(state.members).length;
if (!acctMap || n !== acctMapN || Date.now() - acctMapAt > 300000) {
acctMap = new Map();
for (const [id, m] of Object.entries(state.members)) if (m && m.account) acctMap.set(String(m.account).toLowerCase(), Number(id));
acctMapN = n; acctMapAt = Date.now();
}
return acctMap.get(a) || null;
}
function lookupShape(id, m, source) {
const lvl = m.level || 1, tier = m.tier === 2 ? 2 : (m.tier || 1);
return {
found: true, id: Number(id), account: String(m.account).toLowerCase(),
level: lvl, levelName: levelName(lvl), tier, tierName: tierName(tier),
joinedAt: m.joinedAt || null,
sponsorId: m.referrerId && Number(m.referrerId) !== Number(id) ? Number(m.referrerId) : null,
directCount: m.directCount || 0,
source, indexedAt: state && state.updatedAt ? state.updatedAt : null
};
}
function parseLookupQuery(raw) {
const s = String(raw == null ? '' : raw).trim().replace(/^#/, '');
if (/^\d{1,15}$/.test(s)) { const id = Number(s); if (id >= 1 && id <= 281474976710655) return { kind: 'id', id }; return { error: 'That member ID is out of range.' }; }
if (/^0x[0-9a-fA-F]{40}$/.test(s)) return { kind: 'address', address: s.toLowerCase() };
return { error: 'Enter a member ID (like 21) or a full wallet address (0x followed by 40 characters).' };
}
async function lookupPublic(raw, opts = {}) {
const q = parseLookupQuery(raw);
if (q.error) return { error: q.error };
const allowRpc = opts.allowRpc !== false;
let id = q.kind === 'id' ? q.id : idForAccountIndexed(q.address);
if (!id && q.kind === 'address') {
if (!allowRpc) return { found: false, query: q.address, busy: true };
const r = await ethCall(SEL_MEMBER_ID + q.address.slice(2).padStart(64, '0'));
id = wInt(r, 0) || 0;
if (!id) return { found: false, query: q.address };
}
const m = state && state.members ? state.members[id] : null;
if (m && m.account && !m.preIndexed) return lookupShape(id, m, 'index');
if (!allowRpc) return { found: false, query: String(id), busy: true };
const live = await fetchMember(id);
if (!live) return { found: false, query: String(id) };
return lookupShape(id, live, 'chain');
}
// Company-rotation pick: breadth-first (matrix order, left→right) first
// position under `rootId` that still needs directs — the "next open team
// position" for the public rotation when publicRotationMode==='chain'.
@@ -902,4 +956,6 @@ async function paymentPath(id) {
return { found: true, buyer, uplines, stopped, costs: costs ? { up: costs.up } : null, at: Date.now() };
}
module.exports = { paymentPath, startIndexer, getPayoutsPublic, verifyMember, memberLookup, memberPublic, getIncome, getOwnerUpgradeNeeds, getOrgRouting, getOrgShare, getCoachingScan, getMatrixTree, isInTeam, nextOpenPosition, depthFrom, memberIdByAccount, liveDirects, balanceOf, CONTRACT };
// QA only: seed the in-memory index without starting the RPC indexer (qa/lookup-*.mjs, harness).
const __test = { setState(s) { state = s; acctMap = null; } };
module.exports = { __test, lookupPublic, parseLookupQuery, paymentPath, startIndexer, getPayoutsPublic, verifyMember, memberLookup, memberPublic, getIncome, getOwnerUpgradeNeeds, getOrgRouting, getOrgShare, getCoachingScan, getMatrixTree, isInTeam, nextOpenPosition, depthFrom, memberIdByAccount, liveDirects, balanceOf, CONTRACT };