@@ -37,7 +37,7 @@ export class ConfigService {
37
37
// is executed across services (i.e. there is no guarantee that the config service will be the
38
38
// first to initialize). The `isReady` promise must be awaited on Relayer initialization.
39
39
private async initialize ( ) : Promise < void > {
40
- await this . validateChains ( this . chainsConfig ) ;
40
+ await this . validateChainIds ( this . chainsConfig ) ;
41
41
}
42
42
43
43
private loadNodeEnv ( ) : string {
@@ -185,28 +185,20 @@ export class ConfigService {
185
185
return this . ambsConfig . get ( amb ) ?. globalProperties [ key ] ;
186
186
}
187
187
188
- private async validateChains ( chainsConfig : Map < string , ChainConfig > ) : Promise < void > {
189
- const validateChainIdFromRPC = async ( rpc : string , expectedChainId : string ) : Promise < boolean > => {
190
- const provider = new JsonRpcProvider ( rpc , undefined , { staticNetwork : true } ) ;
191
- try {
192
- const network = await provider . getNetwork ( ) ;
193
- const actualChainId = network . chainId . toString ( ) ;
194
- return actualChainId === expectedChainId ;
195
- } catch ( error ) {
196
- return false ;
197
- }
198
- } ;
188
+ private async validateChainIds ( chainsConfig : Map < string , ChainConfig > ) : Promise < void > {
199
189
200
190
const validationPromises = [ ] ;
201
-
202
191
for ( const [ chainId , config ] of chainsConfig ) {
203
- const validationPromise = async ( ) => {
204
- const chainIdValidate = await validateChainIdFromRPC ( config . rpc , chainId ) ;
205
- if ( ! chainIdValidate ) {
206
- throw new Error ( `Error validating the Chain ID for chain ${ chainId } ` ) ;
192
+ const provider = new JsonRpcProvider ( config . rpc , undefined , { staticNetwork : true } ) ;
193
+ const validationPromise = provider . getNetwork ( ) . then (
194
+ ( network ) => {
195
+ const rpcChainId = network . chainId . toString ( ) ;
196
+ if ( rpcChainId !== chainId ) {
197
+ throw new Error ( `Error validating the chain ID of chain ${ chainId } : the RPC chain ID is ${ rpcChainId } .` )
198
+ }
207
199
}
208
- } ;
209
- validationPromises . push ( validationPromise ( ) ) ;
200
+ )
201
+ validationPromises . push ( validationPromise ) ;
210
202
}
211
203
212
204
await Promise . all ( validationPromises ) ;
0 commit comments