From 0254f933be8879978c1fbbee1d68e2619d1b6cc0 Mon Sep 17 00:00:00 2001
From: martbost
Date: Sat, 14 Nov 2026 12:53:19 -0600
Subject: [PATCH] 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
---
chain.js | 58 +++++++++++++++++-
private/who-gets-paid.html | 2 +-
public/chat.js | 2 +
public/contract.html | 4 +-
public/disclaimer.html | 4 +-
public/fast-start.html | 2 +-
public/flyers.html | 2 +-
public/generation-pay.html | 2 +-
public/how-pay-works.html | 4 +-
public/index.html | 4 +-
public/join.html | 4 +-
public/lookup.html | 60 +++++++++++++++++++
public/lookup.js | 83 ++++++++++++++++++++++++++
public/my.html | 4 +-
public/privacy.html | 4 +-
public/refunds.html | 4 +-
public/replays.html | 4 +-
public/start.html | 4 +-
public/suite-brand.html | 2 +-
public/suite-copy.html | 2 +-
public/suite-email.html | 2 +-
public/suite-founder.html | 2 +-
public/suite-funnel.html | 2 +-
public/suite-grants.html | 2 +-
public/suite-intel.html | 2 +-
public/suite-leader.html | 2 +-
public/suite-page.html | 2 +-
public/suite-split.html | 2 +-
public/suite-traffic.html | 2 +-
public/suite-video.html | 2 +-
public/suite-voice.html | 2 +-
public/suite.html | 2 +-
public/tools.html | 2 +-
public/training.html | 4 +-
public/weekly-rhythm.html | 2 +-
qa/fixtures/lookup-index.json | 7 +++
qa/harness-server.js | 11 ++++
qa/lookup-e2e.mjs | 108 ++++++++++++++++++++++++++++++++++
qa/lookup-unit.mjs | 62 +++++++++++++++++++
server.js | 48 ++++++++++++++-
40 files changed, 478 insertions(+), 45 deletions(-)
create mode 100644 public/lookup.html
create mode 100644 public/lookup.js
create mode 100644 qa/fixtures/lookup-index.json
create mode 100644 qa/lookup-e2e.mjs
create mode 100644 qa/lookup-unit.mjs
diff --git a/chain.js b/chain.js
index 4c43969..1aaabc9 100644
--- a/chain.js
+++ b/chain.js
@@ -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 };
diff --git a/private/who-gets-paid.html b/private/who-gets-paid.html
index e0a4d9f..aa70daf 100644
--- a/private/who-gets-paid.html
+++ b/private/who-gets-paid.html
@@ -105,7 +105,7 @@ if (u.level > levelIndex && u.directCount >= 2) { Every row also needs 2 directs. The amount is set by the buyer's tier; Standard is exactly half of Premium. The search follows the matrix (where each member was placed), not the sponsor line. Can the contract change? See the security review →
-
+