Add support for HTTPS Web3 providers
This commit is contained in:
parent
2d986c5346
commit
88c623e250
|
@ -214,3 +214,13 @@
|
|||
url = https://github.com/status-im/nim-ssz-serialization.git
|
||||
ignore = untracked
|
||||
branch = master
|
||||
[submodule "vendor/nim-websock"]
|
||||
path = vendor/nim-websock
|
||||
url = https://github.com/status-im/nim-websock.git
|
||||
ignore = untracked
|
||||
branch = master
|
||||
[submodule "vendor/nim-zlib"]
|
||||
path = vendor/nim-zlib
|
||||
url = https://github.com/status-im/nim-zlib.git
|
||||
ignore = untracked
|
||||
branch = master
|
||||
|
|
|
@ -243,43 +243,15 @@ 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
|
||||
|
||||
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
|
||||
if not (normalizedUrl.startsWith("https://") or
|
||||
normalizedUrl.startsWith("http://") or
|
||||
normalizedUrl.startsWith("wss://") or
|
||||
normalizedUrl.startsWith("ws://")):
|
||||
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
|
||||
|
||||
template toGaugeValue(x: Quantity): int64 =
|
||||
toGaugeValue(distinctBase x)
|
||||
|
||||
|
|
|
@ -1340,7 +1340,8 @@ proc handleValidatorExitCommand(config: BeaconNodeConf) {.async.} =
|
|||
let rpcClient = newRpcHttpClient()
|
||||
|
||||
try:
|
||||
await connect(rpcClient, config.rpcUrlForExit.hostname, port)
|
||||
await connect(rpcClient, config.rpcUrlForExit.hostname, port,
|
||||
secure = config.rpcUrlForExit.scheme in ["https", "wss"])
|
||||
except CatchableError as err:
|
||||
fatal "Failed to connect to the beacon node RPC service", err = err.msg
|
||||
quit 1
|
||||
|
|
|
@ -36,15 +36,15 @@ 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"
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 7a9d118929483c38f67df81514011414e229cd66
|
||||
Subproject commit c455198d4fd3f56cb064b15f80c3a036907fde37
|
|
@ -0,0 +1 @@
|
|||
Subproject commit a697e3585d583ab6b91a159ea7d023461002c927
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 6bbc67d09e624d69052d62b2353878f491186942
|
Loading…
Reference in New Issue