Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add default public RPC endpoints for default configured networks #1866

Merged
merged 14 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions scripts/update_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"gnosis": {
"mainnet": 100,
},
"optimism": {
"mainnet": 10,
"goerli": 420,
"sepolia": 11155420,
},
"polygon": {
"mainnet": 137,
"mumbai": 80001,
Expand Down Expand Up @@ -76,9 +81,7 @@ def fetch_chain(chain_id: int) -> Chain:

logger.info(f"GET {url}")
r = requests.get(url)

if r.status_code != 200:
raise Exception(f"Failed to fetch {url}")
r.raise_for_status()

chain = Chain.model_validate_json(r.text)

Expand Down
17 changes: 16 additions & 1 deletion src/ape_geth/chains.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is auto-generated by scripts/update_rpc.py
# 2024-01-16 20:09:17.902267
# 2024-01-17 20:19:55.820921
# Do not edit this file directly.
from typing import Dict, List

Expand Down Expand Up @@ -57,6 +57,21 @@
"https://gnosis.publicnode.com",
],
},
"optimism": {
"mainnet": [
"https://mainnet.optimism.io",
"https://optimism.publicnode.com",
"https://optimism.gateway.tenderly.co",
],
"goerli": [
"https://goerli.optimism.io",
"https://optimism-goerli.publicnode.com",
"https://optimism-goerli.gateway.tenderly.co",
],
"sepolia": [
"https://sepolia.optimism.io",
],
},
"polygon": {
"mainnet": [
"https://polygon-rpc.com/",
Expand Down
21 changes: 20 additions & 1 deletion src/ape_geth/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,23 @@ def build_command(self) -> List[str]:

# NOTE: The default behavior of EthereumNodeBehavior assumes geth.
class Geth(EthereumNodeProvider):
pass
@property
def uri(self) -> str:
uri = super().uri
ecosystem = self.network.ecosystem.name
network = self.network.name

# If we didn't find one in config, look for a public RPC.
if not uri or uri == DEFAULT_SETTINGS["uri"]:
mikeshultz marked this conversation as resolved.
Show resolved Hide resolved
# Do not override explicit configuration
if hasattr(self.config, ecosystem):
antazoey marked this conversation as resolved.
Show resolved Hide resolved
# Shape of this is odd. Pydantic model containing dicts
antazoey marked this conversation as resolved.
Show resolved Hide resolved
if network_config := self.config[ecosystem].get(network):
if "uri" in network_config:
return network_config["uri"]

# Use public RPC if available
if ecosystem in PUBLIC_CHAIN_RPCS and network in PUBLIC_CHAIN_RPCS[ecosystem]:
uri = random.choice(PUBLIC_CHAIN_RPCS[ecosystem][network])

return uri
Loading