diff --git a/offchain-gas-oracle/src/config.ts b/offchain-gas-oracle/src/config.ts index 650f285..81d5a2e 100644 --- a/offchain-gas-oracle/src/config.ts +++ b/offchain-gas-oracle/src/config.ts @@ -16,5 +16,23 @@ export interface Config { } export function readConfig(configPath: string): Config { - return JSON.parse(fs.readFileSync(configPath, "utf8")); + const config: Config = JSON.parse(fs.readFileSync(configPath, "utf8")); + // check that there are no duplicate chainIds or rpcs + const chainIds = new Set(); + const rpcs = new Set(); + for (const oracleConfig of config.oracles) { + // chainId + const chainId = oracleConfig.chainId; + if (chainIds.has(chainId)) { + throw new Error("duplicate chainId found"); + } + chainIds.add(chainId); + // rpc + const rpc = oracleConfig.rpc; + if (rpcs.has(rpc)) { + throw new Error("duplicate rpc found"); + } + rpcs.add(rpc); + } + return config; }