(network: string)
| 12 | }; |
| 13 | |
| 14 | const resolveHost = async (network: string): Promise<string> => { |
| 15 | if (MAINNET_HOSTS[network]) return MAINNET_HOSTS[network]; |
| 16 | |
| 17 | // Fall back to dfx.json for local-replica style networks. |
| 18 | const dfxJsonPath = join(ROOT_PATH, 'dfx.json'); |
| 19 | const raw = await readFile(dfxJsonPath, 'utf8').catch(() => null); |
| 20 | if (!raw) { |
| 21 | throw new Error(`Unknown network '${network}' and dfx.json not found at ${dfxJsonPath}.`); |
| 22 | } |
| 23 | const dfxJson = JSON.parse(raw) as { |
| 24 | networks?: Record<string, { providers?: string[]; bind?: string }>; |
| 25 | }; |
| 26 | const cfg = dfxJson.networks?.[network]; |
| 27 | if (!cfg) { |
| 28 | throw new Error(`Network '${network}' is not defined in dfx.json.`); |
| 29 | } |
| 30 | if (cfg.providers && cfg.providers.length > 0) return cfg.providers[0]; |
| 31 | if (cfg.bind) return cfg.bind.startsWith('http') ? cfg.bind : `http://${cfg.bind}`; |
| 32 | throw new Error(`Network '${network}' has no providers or bind URL configured.`); |
| 33 | }; |
| 34 | |
| 35 | export const createStationActor = async ( |
| 36 | canisterId: string, |
no test coverage detected