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

Detect ENS registry's address for correct network #1396

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b515ffb
Detect ENS registry's address for correct network
filips123 Jul 22, 2019
c47d0ee
Add UnknownNetwork exception
filips123 Jul 22, 2019
2c281f5
Throw UnknownNetwork exception if network is not known
filips123 Jul 22, 2019
2f6b39c
Fix lint and docs & Convert version to int
filips123 Jul 22, 2019
e1577e8
Merge branch 'master' of https://github.com/ethereum/web3.py into pat…
filips123 Jul 29, 2019
c197aa9
Use checksum addresses
filips123 Aug 5, 2019
a0577b3
Merge branch 'master' of https://github.com/ethereum/web3.py into pat…
filips123 Aug 5, 2019
3bb257d
Merge branch 'patch-1' of https://github.com/filips123/web3.py into p…
filips123 Aug 5, 2019
d07adaf
Add Geth PoA middleware
filips123 Aug 7, 2019
8c98d59
Use dict instead of function
filips123 Aug 7, 2019
1e5230f
Move constants to correct file
filips123 Aug 8, 2019
d851a4d
Use default address only if custom is not provided & Except StaleBloc…
filips123 Sep 28, 2019
c14ec20
Add net_version to skipped methods for stalecheck
filips123 Sep 29, 2019
0f32519
Merge branch 'master' of https://github.com/ethereum/web3.py into pat…
filips123 Sep 29, 2019
22f9fd4
Merge branch 'master' of https://github.com/ethereum/web3.py into pat…
filips123 Dec 14, 2019
d2fdb69
Split addresses into multiple lines
filips123 Dec 14, 2019
2b20062
Merge branch 'master' of https://github.com/ethereum/web3.py into pat…
filips123 Feb 3, 2020
04faa02
Remove old import
filips123 Feb 3, 2020
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
2 changes: 1 addition & 1 deletion ens/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

REVERSE_REGISTRAR_DOMAIN = 'addr.reverse'

ENS_MAINNET_ADDR = ChecksumAddress(HexAddress(HexStr('0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e')))
ENS_PUBLIC_ADDR = ChecksumAddress(HexAddress(HexStr('0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e')))
5 changes: 3 additions & 2 deletions ens/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from ens import abis
from ens.constants import (
EMPTY_ADDR_HEX,
ENS_MAINNET_ADDR,
ENS_PUBLIC_ADDR,
REVERSE_REGISTRAR_DOMAIN,
)
from ens.exceptions import (
Expand Down Expand Up @@ -83,10 +83,11 @@ def __init__(
:type provider: instance of `web3.providers.base.BaseProvider`
:param hex-string addr: the address of the ENS registry on-chain. If not provided,
ENS.py will default to the mainnet ENS registry address.
:raises UnknownNetwork: if network is unknown
"""
self.web3 = init_web3(provider)

ens_addr = addr if addr else ENS_MAINNET_ADDR
ens_addr = addr if addr else ENS_PUBLIC_ADDR
self.ens = self.web3.eth.contract(abi=abis.ENS, address=ens_addr)
self._resolverContract = self.web3.eth.contract(abi=abis.RESOLVER)

Expand Down
8 changes: 8 additions & 0 deletions ens/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,20 @@ def init_web3(provider: 'BaseProvider'=cast('BaseProvider', default)) -> '_Web3'

def customize_web3(w3: '_Web3') -> '_Web3':
from web3.middleware import make_stalecheck_middleware
from web3.middleware import geth_poa_middleware

w3.middleware_onion.remove('name_to_address')

w3.middleware_onion.add(
make_stalecheck_middleware(ACCEPTABLE_STALE_HOURS * 3600),
name='stalecheck',
)

w3.middleware_onion.inject(
geth_poa_middleware,
layer=0,
)

return w3


Expand Down
1 change: 1 addition & 0 deletions web3/middleware/stalecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

SKIP_STALECHECK_FOR_METHODS = set([
'eth_getBlockByNumber',
'net_version',
])


Expand Down