diff --git a/main.js b/main.js index 99f134ba..ef55147b 100644 --- a/main.js +++ b/main.js @@ -1333,7 +1333,11 @@ async function fetchOpenSearch(href) { // build. The last discovered list is cached to disk and tried first next launch. let electrumPool = null; let lastElectrumRefresh = 0; -const electrumFile = () => path.join(app.getPath("userData"), "electrum-servers.json"); +// Per-network cache files. Chipnet keeps the historical names so existing +// profiles are not invalidated; any other network gets its own files. +let resolverNetworkId = "chipnet"; +const netSuffix = () => (resolverNetworkId === "chipnet" ? "" : `.${resolverNetworkId}`); +const electrumFile = () => path.join(app.getPath("userData"), `electrum-servers${netSuffix()}.json`); const serverKey = (s) => (typeof s === "string" ? s : s && s.url); function mergeServers(preferred, rest) { const seen = new Set(), out = []; @@ -1344,10 +1348,14 @@ function mergeServers(preferred, rest) { return out; } async function initElectrumPool() { - const { CHIPNET_ELECTRUM } = await getResolver(); + const R = await getResolver(); + // The resolver's network table decides the seed pool (BNS_NETWORK env; + // chipnet unless set). Older resolver builds only export CHIPNET_ELECTRUM. + resolverNetworkId = R.NETWORK?.id || "chipnet"; + const seed = R.ELECTRUM || R.CHIPNET_ELECTRUM; let saved = []; try { if (fs.existsSync(electrumFile())) saved = JSON.parse(fs.readFileSync(electrumFile(), "utf8")); } catch {} - electrumPool = mergeServers(saved, CHIPNET_ELECTRUM); // discovered first, seed always kept + electrumPool = mergeServers(saved, seed); // discovered first, seed always kept } async function refreshElectrumPool() { try { @@ -1390,8 +1398,11 @@ const INDEX_TTL = 45_000; // Both are optional; if neither exists, ensureIndex() does what it always did // and the user sees the same cold-start experience as before this change. const SNAPSHOT_BUNDLED = path.join(RES_DIR, "bns-name-snapshot.json"); -const SIA_SNAPSHOT_URL = "https://s3.silentmode.st:8600/bns/name-list.json"; -function snapshotUserPath() { return path.join(app.getPath("userData"), "bns-name-snapshot.json"); } +// The published snapshot's location is part of the network table; the constant +// below is only the fallback for a resolver build that predates the table. +const SIA_SNAPSHOT_URL_FALLBACK = "https://s3.silentmode.st:8600/bns/name-list.json"; +async function siaSnapshotUrl() { try { return (await getResolver()).NETWORK?.nameListUrl || SIA_SNAPSHOT_URL_FALLBACK; } catch { return SIA_SNAPSHOT_URL_FALLBACK; } } +function snapshotUserPath() { return path.join(app.getPath("userData"), `bns-name-snapshot${netSuffix()}.json`); } function readSnapshotFrom(p) { try { @@ -1547,7 +1558,7 @@ function stopBnsPolling() { if (pollTimer) { clearInterval(pollTimer); pollTimer // authoritative catch-up. async function refreshSnapshotFromSia() { try { - const res = await fetch(SIA_SNAPSHOT_URL, { redirect: "follow" }); + const res = await fetch((await siaSnapshotUrl()), { redirect: "follow" }); if (!res.ok) return; const body = await res.text(); const parsed = JSON.parse(body);