Every client hard-coded the chipnet beacons, address prefix and electrum servers on its own: resolver, registrar config, wallets, gateway, indexer, mirror scripts, the browser bundle and the mobile Java. A mainnet launch would have meant finding all of them and hoping none was missed. The table now lives in resolver-web.js, the one file every client already shares, so it stays a single-file drop-in. BNS_NETWORK selects the record; unset means chipnet, so nothing changes today: the live index resolves the same 60 names and 20 TLDs, the 67 offline tests pass, and the dashboard, market and studio load the same values through BNS.NETWORK. The mainnet record carries the verified public servers, the prefix and its own Sia bucket, but its beacons, start height and operator address are deliberately null: requireBeacons() refuses to scan until they are pinned in the order ROADMAP-MAINNET.md §6 requires. Bns.java reads a generated BnsNetwork.java so the phone cannot drift from the desktop clients. NETWORK-CONFIG.md records what reads the table and what a launch still pins.
61 lines
3.1 KiB
JavaScript
61 lines
3.1 KiB
JavaScript
// Generate the mobile resolver's network constants from the ONE network table
|
|
// in src/lib/resolver-web.js, so Bns.java can never drift from the JS clients.
|
|
//
|
|
// node src/generate-network-constants.mjs [--network chipnet|mainnet] [outfile]
|
|
//
|
|
// Default outfile: AriadneResolver/mobile/app/src/com/silentmode/ariadne/BnsNetwork.java
|
|
// The Java side dials raw-TLS electrum on port 50002 for public Fulcrums (and
|
|
// wss for our own indexers), so the server list is re-expressed in that form.
|
|
import { writeFileSync, mkdirSync } from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
import path from "node:path";
|
|
import { NETWORKS, DEFAULT_NETWORK_ID } from "./lib/resolver-web.js";
|
|
|
|
const args = process.argv.slice(2);
|
|
const netArg = args.includes("--network") ? args[args.indexOf("--network") + 1] : DEFAULT_NETWORK_ID;
|
|
const net = NETWORKS[netArg];
|
|
if (!net) { console.error(`unknown network ${netArg}`); process.exit(1); }
|
|
const OUT = args.filter((a, i) => !a.startsWith("--") && args[i - 1] !== "--network")[0] || fileURLToPath(
|
|
new URL("../../AriadneResolver/mobile/app/src/com/silentmode/ariadne/BnsNetwork.java", import.meta.url),
|
|
);
|
|
|
|
// wss:// entries (our indexers) stay as they are, with the pinned ip; public
|
|
// Fulcrums are dialled over raw TLS on the conventional 50002 port.
|
|
const javaServer = (s) => {
|
|
const u = new URL(s.url);
|
|
const isIndexer = net.beaconOnly.test(s.url);
|
|
const token = isIndexer ? `${s.url}${s.ip ? "|" + s.ip : ""}` : `${u.hostname}:${u.port === "50004" ? "50002" : u.port}`;
|
|
return ` "${token}",`;
|
|
};
|
|
const q = (v) => (v == null ? "null" : JSON.stringify(v));
|
|
|
|
const java = `package com.silentmode.ariadne;
|
|
|
|
// GENERATED by Argus/src/generate-network-constants.mjs from the network table
|
|
// in Argus/src/lib/resolver-web.js — do not edit; regenerate.
|
|
// node src/generate-network-constants.mjs --network ${net.id}
|
|
public final class BnsNetwork {
|
|
private BnsNetwork() {}
|
|
|
|
public static final String ID = ${q(net.id)};
|
|
public static final String LABEL = ${q(net.label)};
|
|
public static final String ADDRESS_PREFIX = ${q(net.prefix)};
|
|
// electrum scripthash of the name beacon (null while unpinned)
|
|
public static final String BEACON_SCRIPTHASH = ${q(net.beaconScripthash)};
|
|
// electrum scripthash of the TLD-certificate beacon
|
|
public static final String TLD_BEACON_SCRIPTHASH = ${q(net.tldBeaconScripthash)};
|
|
// Our own indexers first ("wss://host[|ip]"), then public electrum as
|
|
// "host:port" (raw TLS). Same token format as the on-chain \`el\` record.
|
|
public static final String[] SERVERS = {
|
|
${net.electrum.map(javaServer).join("\n")}
|
|
};
|
|
public static final String ELECTRUM_LIST_NAME = ${q(net.electrumListName)};
|
|
public static final String HOSTING_BUCKET = ${q(net.hostingBucket)};
|
|
public static final String NAME_LIST_URL = ${q(net.nameListUrl)};
|
|
public static final String CDN_INDEX_URL = ${q(net.cdnIndexUrl)};
|
|
public static final String EXPLORER_TX = ${q(net.explorerTx)};
|
|
}
|
|
`;
|
|
mkdirSync(path.dirname(OUT), { recursive: true });
|
|
writeFileSync(OUT, java);
|
|
console.log(`wrote ${OUT} for ${net.id} (${net.electrum.length} servers)`);
|