New public page /who-gets-paid: live upgrade payment path for any position
Marty: let anyone enter a position and watch who the contract pays when it upgrades, so members can simulate helping someone. chain.paymentPath reads the buyer and up to 16 matrix uplines live from the contract (not the snapshot) and stops where _payUpline stops (root #1, empty, 16). GET /api/public/payment-path is rate-limited like the member lookup, cached 60 s. The page walks the rule from the buyer upward, one generation per step; the real next upgrade is labelled, higher levels are what-ifs, and any passed-over upline gets a "what if they did?" to give them the missing level or direct and re-run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -859,4 +859,29 @@ async function getIncome(id) {
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { startIndexer, getPayoutsPublic, verifyMember, memberLookup, memberPublic, getIncome, getOwnerUpgradeNeeds, getOrgRouting, getOrgShare, getCoachingScan, getMatrixTree, isInTeam, nextOpenPosition, depthFrom, memberIdByAccount, liveDirects, balanceOf, CONTRACT };
|
||||
// Live upgrade payment path for /who-gets-paid (Marty, 2026-09-26): the buyer plus up to 16
|
||||
// matrix uplines, read straight from the contract (not the snapshot, so a level or direct that
|
||||
// changed a minute ago is already reflected). Mirrors _payUpline's walk: it starts at the
|
||||
// buyer's matrix parent and stops at the root (#1), an empty upline, or 16 steps.
|
||||
const ROOT_ID = 1;
|
||||
async function paymentPath(id) {
|
||||
const pick = m => ({ id: m.id, level: m.level, tier: m.tier, directCount: m.directCount, uplineId: m.uplineId, referrerId: m.referrerId });
|
||||
const b = await fetchMember(id);
|
||||
if (!b) return { found: false };
|
||||
const buyer = pick(Object.assign({ id }, b));
|
||||
const uplines = [];
|
||||
let cur = b.uplineId, stopped = null;
|
||||
for (let i = 0; i < 16; i++) {
|
||||
if (!cur) { stopped = 'empty'; break; }
|
||||
if (cur === ROOT_ID) { stopped = 'root'; break; }
|
||||
const m = await fetchMember(cur);
|
||||
if (!m) { stopped = 'empty'; break; }
|
||||
uplines.push(pick(Object.assign({ id: cur }, m)));
|
||||
cur = m.uplineId;
|
||||
}
|
||||
if (!stopped) stopped = 'max';
|
||||
await fetchCosts().catch(() => {});
|
||||
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 };
|
||||
|
||||
Reference in New Issue
Block a user