Skip to content

Commit

Permalink
Make sure all ensip15 flags are passed on
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Jun 23, 2023
1 parent 8df1fc2 commit 3087fb2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
19 changes: 11 additions & 8 deletions ens/async_ens.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async def setup_address(

resolver: "AsyncContract" = await self._set_resolver(name, transact=transact)
return await resolver.functions.setAddr(
raw_name_to_hash(name), address
raw_name_to_hash(name, ensip15=self.ensip15_normalization), address
).transact(transact)

async def name(self, address: ChecksumAddress) -> Optional[str]:
Expand Down Expand Up @@ -269,7 +269,7 @@ async def owner(self, name: str) -> ChecksumAddress:
:return: owner address
:rtype: str
"""
node = raw_name_to_hash(name)
node = raw_name_to_hash(name, ensip15=self.ensip15_normalization)
return await self.ens.caller.owner(node)

async def setup_owner(
Expand Down Expand Up @@ -352,7 +352,7 @@ async def get_text(self, name: str, key: str) -> str:
the "0x59d1d43c" interface id
:raises ResolverNotFound: If no resolver is found for the provided name
"""
node = raw_name_to_hash(name)
node = raw_name_to_hash(name, ensip15=self.ensip15_normalization)
normal_name = normalize_name(name, ensip15=self.ensip15_normalization)

r = await self.resolver(normal_name)
Expand Down Expand Up @@ -394,7 +394,7 @@ async def set_text(
transact = {}

owner = await self.owner(name)
node = raw_name_to_hash(name)
node = raw_name_to_hash(name, ensip15=self.ensip15_normalization)
normal_name = normalize_name(name, ensip15=self.ensip15_normalization)

transaction_dict = merge({"from": owner}, transact)
Expand Down Expand Up @@ -454,7 +454,7 @@ async def _set_resolver(
transact = deepcopy(transact)
if is_none_or_zero_address(resolver_addr):
resolver_addr = await self.address("resolver.eth")
namehash = raw_name_to_hash(name)
namehash = raw_name_to_hash(name, ensip15=self.ensip15_normalization)
if await self.ens.caller.resolver(namehash) != resolver_addr:
await self.ens.functions.setResolver( # type: ignore
namehash, resolver_addr
Expand All @@ -472,7 +472,7 @@ async def _resolve(
if not resolver:
return None

node = self.namehash(normal_name)
node = self.namehash(normal_name, ensip15=self.ensip15_normalization)

# handle extended resolver case
if await _async_resolver_supports_interface(
Expand All @@ -482,7 +482,8 @@ async def _resolve(

calldata = resolver.encodeABI(*contract_func_with_args)
contract_call_result = await resolver.caller.resolve(
ens_encode_name(normal_name), calldata
ens_encode_name(normal_name, ensip15=self.ensip15_normalization),
calldata,
)
result = self._decode_ensip10_resolve_data(
contract_call_result, resolver, fn_name
Expand Down Expand Up @@ -540,7 +541,9 @@ async def _claim_ownership(
transact["from"] = old_owner or owner
for label in reversed(unowned):
await self.ens.functions.setSubnodeOwner( # type: ignore
raw_name_to_hash(owned), label_to_hash(label), owner
raw_name_to_hash(owned, ensip15=self.ensip15_normalization),
label_to_hash(label, ensip15=self.ensip15_normalization),
owner,
).transact(transact)
owned = f"{label}.{owned}"

Expand Down
4 changes: 2 additions & 2 deletions ens/base_ens.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def strict_bytes_type_checking(self, strict_bytes_type_check: bool) -> None:

@staticmethod
@wraps(label_to_hash)
def labelhash(label: str) -> HexBytes:
return label_to_hash(label)
def labelhash(label: str, ensip15: bool = False) -> HexBytes:
return label_to_hash(label, ensip15=ensip15)

@staticmethod
@wraps(raw_name_to_hash)
Expand Down
29 changes: 15 additions & 14 deletions ens/ens.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ def setup_address(
transact["from"] = owner

resolver: "Contract" = self._set_resolver(name, transact=transact)
return resolver.functions.setAddr(raw_name_to_hash(name), address).transact(
transact
)
return resolver.functions.setAddr(
raw_name_to_hash(name, ensip15=self.ensip15_normalization), address
).transact(transact)

def name(self, address: ChecksumAddress) -> Optional[str]:
"""
Expand Down Expand Up @@ -265,7 +265,7 @@ def owner(self, name: str) -> ChecksumAddress:
:return: owner address
:rtype: str
"""
node = raw_name_to_hash(name)
node = raw_name_to_hash(name, ensip15=self.ensip15_normalization)
return self.ens.caller.owner(node)

def setup_owner(
Expand Down Expand Up @@ -345,10 +345,9 @@ def get_text(self, name: str, key: str) -> str:
the "0x59d1d43c" interface id
:raises ResolverNotFound: If no resolver is found for the provided name
"""
node = raw_name_to_hash(name)
normal_name = normalize_name(name, ensip15=self.ensip15_normalization)
node = raw_name_to_hash(name, ensip15=self.ensip15_normalization)

r = self.resolver(normal_name)
r = self.resolver(name)
if r:
if _resolver_supports_interface(r, GET_TEXT_INTERFACE_ID):
return r.caller.text(node, key)
Expand Down Expand Up @@ -387,12 +386,11 @@ def set_text(
transact = {}

owner = self.owner(name)
node = raw_name_to_hash(name)
normal_name = normalize_name(name, ensip15=self.ensip15_normalization)
node = raw_name_to_hash(name, ensip15=self.ensip15_normalization)

transaction_dict = merge({"from": owner}, transact)

r = self.resolver(normal_name)
r = self.resolver(name)
if r:
if _resolver_supports_interface(r, GET_TEXT_INTERFACE_ID):
return r.functions.setText(node, key, value).transact(transaction_dict)
Expand Down Expand Up @@ -443,7 +441,7 @@ def _set_resolver(
transact = deepcopy(transact)
if is_none_or_zero_address(resolver_addr):
resolver_addr = self.address("resolver.eth")
namehash = raw_name_to_hash(name)
namehash = raw_name_to_hash(name, ensip15=self.ensip15_normalization)
if self.ens.caller.resolver(namehash) != resolver_addr:
self.ens.functions.setResolver(namehash, resolver_addr).transact(transact)
return cast("Contract", self._resolver_contract(address=resolver_addr))
Expand All @@ -457,15 +455,16 @@ def _resolve(
if not resolver:
return None

node = self.namehash(normal_name)
node = self.namehash(normal_name, ensip15=self.ensip15_normalization)

# handle extended resolver case
if _resolver_supports_interface(resolver, EXTENDED_RESOLVER_INTERFACE_ID):
contract_func_with_args = (fn_name, [node])

calldata = resolver.encodeABI(*contract_func_with_args)
contract_call_result = resolver.caller.resolve(
ens_encode_name(normal_name), calldata
ens_encode_name(normal_name, ensip15=self.ensip15_normalization),
calldata,
)
result = self._decode_ensip10_resolve_data(
contract_call_result, resolver, fn_name
Expand Down Expand Up @@ -523,7 +522,9 @@ def _claim_ownership(
transact["from"] = old_owner or owner
for label in reversed(unowned):
self.ens.functions.setSubnodeOwner(
raw_name_to_hash(owned), label_to_hash(label), owner
raw_name_to_hash(owned, ensip15=self.ensip15_normalization),
label_to_hash(label, ensip15=self.ensip15_normalization),
owner,
).transact(transact)
owned = f"{label}.{owned}"

Expand Down
1 change: 1 addition & 0 deletions ens/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def normal_name_to_hash(name: str) -> HexBytes:
if not is_empty_name(name):
labels = name.split(".")
for label in reversed(labels):
# name is already normalized, ensip15 flag not needed
labelhash = label_to_hash(label)
assert isinstance(labelhash, bytes)
assert isinstance(node, bytes)
Expand Down

0 comments on commit 3087fb2

Please sign in to comment.