// 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)`);