offchain-gas-oracle: add config check

This commit is contained in:
Karl Kempe 2022-09-15 01:53:25 +00:00
parent 517cfe91e3
commit 60436ae59f
1 changed files with 19 additions and 1 deletions

View File

@ -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<number>();
const rpcs = new Set<string>();
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;
}