offchain-gas-oracle: add config check
This commit is contained in:
parent
517cfe91e3
commit
60436ae59f
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue