Skip to content

Commit

Permalink
refactor: take out non-RPC logic from try...catch context
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Sep 25, 2023
1 parent 795d0e4 commit 6404e6b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions ape_tenderly/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,19 @@ def connect(self):
self._web3 = Web3(HTTPProvider(self.uri))

try:
# Any chain that *began* as PoA needs the middleware for pre-merge blocks
ethereum_goerli = 5
optimism = (10, 420)
polygon = (137, 80001)

if self._web3.eth.chain_id in (ethereum_goerli, *optimism, *polygon):
self._web3.middleware_onion.inject(geth_poa_middleware, layer=0)

self._web3.eth.set_gas_price_strategy(rpc_gas_price_strategy)
chain_id = self._web3.eth.chain_id
except Exception as err:
raise ProviderError(f"Failed to connect to Tenderly Gateway.\n{repr(err)}") from err

# Any chain that *began* as PoA needs the middleware for pre-merge blocks
ethereum_goerli = 5
optimism = (10, 420)
polygon = (137, 80001)

if chain_id in (ethereum_goerli, *optimism, *polygon):
self._web3.middleware_onion.inject(geth_poa_middleware, layer=0)

self._web3.eth.set_gas_price_strategy(rpc_gas_price_strategy)

def disconnect(self):
self._web3 = None

0 comments on commit 6404e6b

Please sign in to comment.