Skip to content

Commit

Permalink
Import from eth-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
reedsa committed Apr 22, 2024
1 parent d43c10e commit 28864b9
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 54 deletions.
4 changes: 3 additions & 1 deletion ens/base_ens.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
from eth_typing import (
ChecksumAddress,
)
from eth_utils.abi import (
get_abi_output_types,
)
from hexbytes import (
HexBytes,
)

from .utils import (
address_to_reverse_domain,
get_abi_output_types,
is_valid_name,
label_to_hash,
normalize_name,
Expand Down
17 changes: 0 additions & 17 deletions ens/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
Any,
Callable,
Collection,
Dict,
List,
Optional,
Sequence,
Tuple,
Expand All @@ -29,9 +27,6 @@
to_bytes,
to_normalized_address,
)
from eth_utils.abi import (
collapse_if_tuple,
)
from hexbytes import (
HexBytes,
)
Expand Down Expand Up @@ -69,9 +64,6 @@
Middleware,
RPCEndpoint,
)
from eth_typing import (
ABIFunction,
)


def Web3() -> Type["_Web3"]:
Expand Down Expand Up @@ -287,15 +279,6 @@ def is_valid_ens_name(ens_name: str) -> bool:
return True


# borrowed from similar method at `web3._utils.abi` due to circular dependency
def get_abi_output_types(abi: "ABIFunction") -> List[str]:
return (
[]
if abi["type"] == "fallback"
else [collapse_if_tuple(cast(Dict[str, Any], arg)) for arg in abi["outputs"]]
)


# -- async -- #


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import json
import pytest

from web3._utils.abi import (
from eth_utils.abi import (
get_abi_input_types,
)

from web3._utils.function_identifiers import (
FallbackFn,
ReceiveFn,
Expand Down
32 changes: 4 additions & 28 deletions web3/_utils/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
to_tuple,
)
from eth_utils.abi import (
collapse_if_tuple,
get_normalized_abi_arg_type,
)
from eth_utils.toolz import (
curry,
Expand Down Expand Up @@ -114,20 +114,6 @@ def filter_by_name(name: str, contract_abi: ABI) -> List[Union[ABIFunction, ABIE
]


def get_abi_input_types(abi: ABIFunction) -> List[str]:
if "inputs" not in abi and (abi["type"] == "fallback" or abi["type"] == "receive"):
return []
else:
return [collapse_if_tuple(cast(Dict[str, Any], arg)) for arg in abi["inputs"]]


def get_abi_output_types(abi: ABIFunction) -> List[str]:
if abi["type"] == "fallback":
return []
else:
return [collapse_if_tuple(cast(Dict[str, Any], arg)) for arg in abi["outputs"]]


def get_receive_func_abi(contract_abi: ABI) -> ABIFunction:
receive_abis = filter_by_type("receive", contract_abi)
if receive_abis:
Expand Down Expand Up @@ -160,16 +146,6 @@ def exclude_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIEventParam]:
return [arg for arg in event_abi["inputs"] if arg["indexed"] is False]


def get_normalized_abi_arg_type(abi_arg: ABIEventParam) -> str:
"""
Return the normalized type for the abi argument provided.
In order to account for tuple argument types, this abstraction
makes use of `collapse_if_tuple()` to collapse the appropriate component
types within a tuple type, if present.
"""
return collapse_if_tuple(dict(abi_arg))


def filter_by_argument_count(
num_arguments: int, contract_abi: ABI
) -> List[Union[ABIFunction, ABIEvent]]:
Expand Down Expand Up @@ -530,7 +506,7 @@ def get_aligned_abi_inputs(
return (
# typed dict cannot be used w/ a normal Dict
# https://github.com/python/mypy/issues/4976
tuple(collapse_if_tuple(abi) for abi in input_abis), # type: ignore
tuple(get_normalized_abi_arg_type(abi) for abi in input_abis), # type: ignore
type(args)(_align_abi_input(abi, arg) for abi, arg in zip(input_abis, args)),
)

Expand Down Expand Up @@ -684,7 +660,7 @@ def abi_to_signature(abi: Union[ABIFunction, ABIEvent]) -> str:
function_signature = "{fn_name}({fn_input_types})".format(
fn_name=abi["name"],
fn_input_types=",".join(
collapse_if_tuple(dict(arg))
get_normalized_abi_arg_type(dict(arg))
for arg in normalize_event_input_types(abi.get("inputs", []))
),
)
Expand Down Expand Up @@ -927,7 +903,7 @@ def _named_subtree(
abi: Union[ABIFunctionParam, ABIFunction, ABIEvent, Dict[TypeStr, Any]],
data: Tuple[Any, ...],
) -> Union[Dict[str, Any], Tuple[Any, ...], List[Any]]:
abi_type = parse(collapse_if_tuple(dict(abi)))
abi_type = parse(get_normalized_abi_arg_type(dict(abi)))

if abi_type.is_array:
item_type = abi_type.item_type.to_type_str()
Expand Down
4 changes: 3 additions & 1 deletion web3/_utils/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
is_list_like,
is_text,
)
from eth_utils.abi import (
get_abi_input_types,
)
from eth_utils.toolz import (
pipe,
)
Expand All @@ -49,7 +52,6 @@
filter_by_encodability,
filter_by_name,
filter_by_type,
get_abi_input_types,
get_aligned_abi_inputs,
get_fallback_func_abi,
get_receive_func_abi,
Expand Down
4 changes: 3 additions & 1 deletion web3/contract/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
ABIFunction,
ChecksumAddress,
)
from eth_utils.abi import (
get_abi_output_types,
)
from hexbytes import (
HexBytes,
)

from web3._utils.abi import (
filter_by_type,
get_abi_output_types,
map_abi_data,
named_tree,
recursive_dict_to_namedtuple,
Expand Down
4 changes: 2 additions & 2 deletions web3/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
)

# from eth_utils import ( # NOQA
# collapse_if_tuple,
# event_abi_to_log_topic,
# event_signature_to_log_topic,
# function_abi_to_4byte_selector,
Expand All @@ -35,11 +34,11 @@
# get_event_log_topics,
# get_function_abi,
# get_function_info,
# get_normalized_abi_arg_type,
# )

# __all__ = [
# "async_handle_offchain_lookup",
# "collapse_if_tuple",
# "encode_abi",
# "event_abi_to_log_topic",
# "event_signature_to_log_topic",
Expand All @@ -55,6 +54,7 @@
# "get_event_log_topics",
# "get_function_abi",
# "get_function_info",
# "get_normalized_abi_arg_type",
# "handle_offchain_lookup",
# "SimpleCache",
# ]
3 changes: 0 additions & 3 deletions web3/utils/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@
abi_ens_resolver,
abi_string_to_text,
)
from web3.providers import (
BaseProvider,
)
from web3.providers.rpc import (
HTTPProvider,
)
Expand Down

0 comments on commit 28864b9

Please sign in to comment.