From 080cf703f1b00797206ee2df05e99435c2520ee1 Mon Sep 17 00:00:00 2001 From: martbost Date: Thu, 15 Oct 2026 08:02:15 -0500 Subject: [PATCH] Engine activation: rotate RPC providers, re-read the chain after any error before calling it a failure; seed sends the missed notice to members activated during the 403 run Co-Authored-By: Claude Opus 5.5 --- carry.js | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/carry.js b/carry.js index d068f72..56c0b02 100644 --- a/carry.js +++ b/carry.js @@ -34,11 +34,12 @@ function keyHex() { return /^0x[0-9a-fA-F]{64}$/.test(k) ? k : null; } function engineReady() { return !!(ethers && keyHex()); } -function signer() { +function signer(i) { const c = X.chain.getConfig(); const urls = (c.rpcs && c.rpcs.length) ? c.rpcs : [c.rpc]; - const p = new ethers.JsonRpcProvider(urls[0], Number(c.chainId), { staticNetwork: true }); + const p = new ethers.JsonRpcProvider(urls[(i || 0) % urls.length], Number(c.chainId), { staticNetwork: true }); return new ethers.Wallet(keyHex(), p); } +const sleep = ms => new Promise(r => setTimeout(r, ms)); // ---- notices: email + on-site inbox, sent as the company account ---- async function tell(email, subject, text) { @@ -137,18 +138,27 @@ async function ensureOnChain(acct, depth) { } if (!sponsorId) sponsorId = Number((X.siteConfig && X.siteConfig().defaultSponsorId) || 1) || 1; try { if (sponsorId > await X.chain.memberCount()) sponsorId = 0; } catch (e) {} // first member on a fresh contract: no catch position exists yet - try { - const w = signer(); const ctr = new ethers.Contract(X.chain.getConfig().contract, ABI, w); - const tx = await ctr.activateFor(acct.address, sponsorId, { gasLimit: 160000n }); - await tx.wait(1); - const id = await X.chain.memberIdByAccount(acct.address); - logEvent({ type: 'activated', email: acct.email, id, sponsorId, tx: tx.hash }); - await tell(acct.email, X.seeding ? 'Your LinkSpin payouts are switched on' : 'We set up your LinkSpin position so you would not miss a payout', - (X.seeding ? 'Your wallet was already on file with the network, so we switched on your LinkSpin payouts for you, at no cost to you. Your position on the LinkSpin contract is active for your wallet ' + acct.address.slice(0, 6) + '…' + acct.address.slice(-4) + ', bound to your own sponsor, and your team is already placed under you. When anyone in your line buys a LinkSpin package, your share lands in this wallet in the same transaction, and you will be notified.' - : 'Someone in your line was about to buy on LinkSpin, so the network activated your position on the LinkSpin contract for your wallet ' + acct.address.slice(0, 6) + '…' + acct.address.slice(-4) + ', bound to your own sponsor. Nothing was charged and nothing else was touched. Your share of that purchase lands in this wallet in the same transaction.') - + '\n\nSee your line: https://' + (X.host || 'linkspin.co') + '/my'); - return id; - } catch (e) { logEvent({ type: 'activateFailed', email: acct.email, error: String(e.shortMessage || e.message).slice(0, 160) }); return 0; } + // send with provider rotation; after ANY error re-read the chain first (2026-10-15 seed: six activations + // mined while a 403 on the follow-up read logged them as failures and skipped their notices) + let id = 0, txHash = null, lastErr = null; + for (let attempt = 0; attempt < 3 && !id; attempt++) { + try { + const w = signer(attempt); const ctr = new ethers.Contract(X.chain.getConfig().contract, ABI, w); + const tx = await ctr.activateFor(acct.address, sponsorId, { gasLimit: 160000n }); txHash = tx.hash; + await tx.wait(1); + } catch (e) { lastErr = e; } + for (let k = 0; k < 4 && !id; k++) { try { id = Number(await X.chain.memberIdByAccount(acct.address)) || 0; } catch (e) {} if (!id) await sleep(3000); } + } + if (!id) { logEvent({ type: 'activateFailed', email: acct.email, error: String((lastErr && (lastErr.shortMessage || lastErr.message)) || 'not on-chain after send').slice(0, 160) }); return 0; } + logEvent({ type: 'activated', email: acct.email, id, sponsorId, tx: txHash }); + await noticeActivated(acct); + return id; +} +async function noticeActivated(acct) { + await tell(acct.email, X.seeding ? 'Your LinkSpin payouts are switched on' : 'We set up your LinkSpin position so you would not miss a payout', + (X.seeding ? 'Your wallet was already on file with the network, so we switched on your LinkSpin payouts for you, at no cost to you. Your position on the LinkSpin contract is active for your wallet ' + acct.address.slice(0, 6) + '…' + acct.address.slice(-4) + ', bound to your own sponsor, and your team is already placed under you. When anyone in your line buys a LinkSpin package, your share lands in this wallet in the same transaction, and you will be notified.' + : 'Someone in your line was about to buy on LinkSpin, so the network activated your position on the LinkSpin contract for your wallet ' + acct.address.slice(0, 6) + '…' + acct.address.slice(-4) + ', bound to your own sponsor. Nothing was charged and nothing else was touched. Your share of that purchase lands in this wallet in the same transaction.') + + '\n\nSee your line: https://' + (X.host || 'linkspin.co') + '/my'); } // pre-seed: activate every account with a wallet, sponsors before their downline @@ -159,7 +169,17 @@ async function seedAll(limit) { try { for (const a of withWallet) { if (limit && done + failed >= limit) break; - try { if (await X.chain.memberIdByAccount(a.address)) { already++; continue; } } catch (e) {} + try { + if (await X.chain.memberIdByAccount(a.address)) { + already++; + // activated by us but logged as a failure (the 403 read), so the notice never went: send it now, once + const lg = state().log || []; const me = norm(a.email); + if (lg.some(e => e.type === 'activateFailed' && norm(e.email) === me) && !lg.some(e => (e.type === 'activated' || e.type === 'noticeLate') && norm(e.email) === me)) { + await noticeActivated(a); logEvent({ type: 'noticeLate', email: a.email }); + } + continue; + } + } catch (e) {} const id = await ensureOnChain(a, 0); if (id) done++; else failed++; } } finally { X.seeding = false; }