@@ -248,16 +248,42 @@ template finalizedDepositsMerkleizer(m: Eth1Monitor): auto =
248248 m.depositsChain.finalizedDepositsMerkleizer
249249
250250proc fixupWeb3Urls * (web3Url: var string ) =
251- var normalizedUrl = toLowerAscii (web3Url)
252- if not (normalizedUrl.startsWith (" https://" ) or
253- normalizedUrl.startsWith (" http://" ) or
254- normalizedUrl.startsWith (" wss://" ) or
255- normalizedUrl.startsWith (" ws://" )):
256- normalizedUrl = " ws://" & normalizedUrl
257- warn " The Web3 URL does not specify a protocol. Assuming a WebSocket server" , web3Url
258-
259- # We do this at the end in order to allow the warning above to print the original value
260- web3Url = normalizedUrl
251+ # # Converts HTTP and HTTPS Infura URLs to their WebSocket equivalents
252+ # # because we are missing a functional HTTPS client.
253+ let normalizedUrl = toLowerAscii (web3Url)
254+ var pos = 0
255+
256+ template skip (x: string ): bool {.dirty .} =
257+ if normalizedUrl.len - pos >= x.len and
258+ normalizedUrl.toOpenArray (pos, pos + x.len - 1 ) == x:
259+ pos += x.len
260+ true
261+ else :
262+ false
263+
264+ if not (skip (" https://" ) or skip (" http://" )):
265+ if not (skip (" ws://" ) or skip (" wss://" )):
266+ web3Url = " ws://" & web3Url
267+ warn " The Web3 URL does not specify a protocol. Assuming a WebSocket server" , web3Url
268+ return
269+
270+ block infuraRewrite:
271+ var pos = pos
272+ let network = if skip (" mainnet" ): mainnet
273+ elif skip (" goerli" ): goerli
274+ else : break
275+
276+ if not skip (" .infura.io/v3/" ):
277+ break
278+
279+ template infuraKey : string = normalizedUrl.substr (pos)
280+
281+ web3Url = " wss://" & $ network & " .infura.io/ws/v3/" & infuraKey
282+ return
283+
284+ block gethRewrite:
285+ web3Url = " ws://" & normalizedUrl.substr (pos)
286+ warn " Only WebSocket web3 providers are supported. Rewriting URL" , web3Url
261287
262288template toGaugeValue (x: Quantity ): int64 =
263289 toGaugeValue (distinctBase x)
0 commit comments