Skip to content

Commit

Permalink
Add address resolver to Eth class
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Sep 10, 2020
1 parent a604046 commit d5349a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
10 changes: 0 additions & 10 deletions ens/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,3 @@ def assert_signer_in_modifier_kwargs(modifier_kwargs: Any) -> ChecksumAddress:

def is_none_or_zero_address(addr: Union[Address, ChecksumAddress, HexAddress]) -> bool:
return not addr or addr == EMPTY_ADDR_HEX


def is_valid_domain(domain: str) -> bool:
split_domain = domain.split('.')
if len(split_domain) == 1:
return False
for name in split_domain:
if not is_valid_name(name):
return False
return True
12 changes: 0 additions & 12 deletions web3/_utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
valmap,
)

from ens.utils import (
is_valid_domain,
)
from web3._utils.abi import (
abi_to_signature,
filter_by_type,
Expand Down Expand Up @@ -155,19 +152,10 @@ def validate_abi_value(abi_type: TypeStr, value: Any) -> None:
)


def is_non_address_string(value: str) -> bool:
return (is_string(value) and not is_bytes(value) and not
is_checksum_address(value) and not is_hex_address(value))


def validate_address(value: Any) -> None:
"""
Helper function for validating an address
"""
if is_non_address_string(value):
if not is_valid_domain(value):
raise InvalidAddress("Address needs to be a full domain name including a TLD", value)
return
if is_bytes(value):
if not is_binary_address(value):
raise InvalidAddress("Address must be 20 bytes when input type is bytes", value)
Expand Down
13 changes: 11 additions & 2 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
LogFilter,
TransactionFilter,
)
from web3._utils.normalizers import (
abi_ens_resolver,
)
from web3._utils.rpc_abi import (
RPC,
)
Expand Down Expand Up @@ -211,9 +214,15 @@ def block_identifier_munger(
block_identifier = self.defaultBlock
return [*args, block_identifier]

def address_resolver_munger(self, account, block_identifier=None):
resolved_addr = abi_ens_resolver(self.web3, 'address', account)[1]
if block_identifier is None:
block_identifier = self.defaultBlock
return [resolved_addr, block_identifier]

getBalance: Method[Callable[..., Wei]] = Method(
RPC.eth_getBalance,
mungers=[block_identifier_munger]
mungers=[address_resolver_munger],
)

getStorageAt: Method[
Expand All @@ -235,7 +244,7 @@ def block_identifier_munger(

getCode: Method[Callable[..., HexBytes]] = Method(
RPC.eth_getCode,
mungers=[block_identifier_munger]
mungers=[address_resolver_munger]
)

def getBlock(
Expand Down

0 comments on commit d5349a4

Please sign in to comment.