Re-enable the HTTP support in Eth1Monitor

This reverts commit 6fddff524c.
This commit is contained in:
Zahary Karadjov 2022-01-15 09:11:17 +02:00 committed by zah
parent af614b6a85
commit ebde027262
2 changed files with 16 additions and 42 deletions

View File

@ -253,42 +253,16 @@ template finalizedDepositsMerkleizer(m: Eth1Monitor): auto =
m.depositsChain.finalizedDepositsMerkleizer
proc fixupWeb3Urls*(web3Url: var string) =
## Converts HTTP and HTTPS Infura URLs to their WebSocket equivalents
## because we are missing a functional HTTPS client.
let normalizedUrl = toLowerAscii(web3Url)
var pos = 0
var normalizedUrl = toLowerAscii(web3Url)
if not (normalizedUrl.startsWith("https://") or
normalizedUrl.startsWith("http://") or
normalizedUrl.startsWith("wss://") or
normalizedUrl.startsWith("ws://")):
normalizedUrl = "ws://" & normalizedUrl
warn "The Web3 URL does not specify a protocol. Assuming a WebSocket server", web3Url
template skip(x: string): bool {.dirty.} =
if normalizedUrl.len - pos >= x.len and
normalizedUrl.toOpenArray(pos, pos + x.len - 1) == x:
pos += x.len
true
else:
false
if not (skip("https://") or skip("http://")):
if not (skip("ws://") or skip("wss://")):
web3Url = "ws://" & web3Url
warn "The Web3 URL does not specify a protocol. Assuming a WebSocket server", web3Url
return
block infuraRewrite:
var pos = pos
let network = if skip("mainnet"): mainnet
elif skip("goerli"): goerli
else: break
if not skip(".infura.io/v3/"):
break
template infuraKey: string = normalizedUrl.substr(pos)
web3Url = "wss://" & $network & ".infura.io/ws/v3/" & infuraKey
return
block gethRewrite:
web3Url = "ws://" & normalizedUrl.substr(pos)
warn "Only WebSocket web3 providers are supported. Rewriting URL", web3Url
# We do this at the end in order to allow the warning above to print the original value
web3Url = normalizedUrl
template toGaugeValue(x: Quantity): int64 =
toGaugeValue(distinctBase x)

View File

@ -36,16 +36,16 @@ suite "Eth1 monitor":
check:
mainnetWssUrl == "wss://mainnet.infura.io/ws/v3/6224f3c792cc443fafb64e70a98f871e"
mainnetHttpUrl == mainnetWssUrl
mainnetHttpsUrl == mainnetWssUrl
mainnetHttpUrl == "http://mainnet.infura.io/v3/6224f3c792cc443fafb64e70a98f871e"
mainnetHttpsUrl == "https://mainnet.infura.io/v3/6224f3c792cc443fafb64e70a98f871e"
goerliWssUrl == "wss://goerli.infura.io/ws/v3/6224f3c792cc443fafb64e70a98f871e"
goerliHttpUrl == goerliWssUrl
goerliHttpsUrl == goerliWssUrl
goerliHttpUrl == "http://goerli.infura.io/v3/6224f3c792cc443fafb64e70a98f871e"
goerliHttpsUrl == "https://goerli.infura.io/v3/6224f3c792cc443fafb64e70a98f871e"
gethHttpUrl == gethWsUrl
gethHttpsUrl == gethWsUrl
unspecifiedProtocolUrl == gethWsUrl
gethHttpUrl == "http://localhost:8545"
gethHttpsUrl == "https://localhost:8545"
unspecifiedProtocolUrl == "ws://localhost:8545"
gethWsUrl == "ws://localhost:8545"