Skip to content

Commit 23da131

Browse files
author
Stuart Reed
committed
Replace collapse_if_tuple with get_normalized_abi_arg_type
1 parent c5f6576 commit 23da131

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

ens/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
to_normalized_address,
3030
)
3131
from eth_utils.abi import (
32-
collapse_if_tuple,
32+
get_normalized_abi_arg_type,
3333
)
3434
from hexbytes import (
3535
HexBytes,
@@ -298,7 +298,10 @@ def get_abi_output_types(abi: "ABIFunction") -> List[str]:
298298
return (
299299
[]
300300
if abi["type"] == "fallback"
301-
else [collapse_if_tuple(cast(Dict[str, Any], arg)) for arg in abi["outputs"]]
301+
else [
302+
get_normalized_abi_arg_type(cast(Dict[str, Any], arg))
303+
for arg in abi["outputs"]
304+
]
302305
)
303306

304307

web3/_utils/abi.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
to_tuple,
6666
)
6767
from eth_utils.abi import (
68-
collapse_if_tuple,
6968
get_abi_input_names,
69+
get_normalized_abi_arg_type,
7070
get_normalized_abi_inputs,
7171
)
7272
from eth_utils.toolz import (
@@ -120,14 +120,20 @@ def get_abi_input_types(abi: ABIFunction) -> List[str]:
120120
if "inputs" not in abi and (abi["type"] == "fallback" or abi["type"] == "receive"):
121121
return []
122122
else:
123-
return [collapse_if_tuple(cast(Dict[str, Any], arg)) for arg in abi["inputs"]]
123+
return [
124+
get_normalized_abi_arg_type(cast(Dict[str, Any], arg))
125+
for arg in abi["inputs"]
126+
]
124127

125128

126129
def get_abi_output_types(abi: ABIFunction) -> List[str]:
127130
if abi["type"] == "fallback":
128131
return []
129132
else:
130-
return [collapse_if_tuple(cast(Dict[str, Any], arg)) for arg in abi["outputs"]]
133+
return [
134+
get_normalized_abi_arg_type(cast(Dict[str, Any], arg))
135+
for arg in abi["outputs"]
136+
]
131137

132138

133139
def get_receive_func_abi(contract_abi: ABI) -> ABIFunction:
@@ -162,18 +168,6 @@ def exclude_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIComponent]:
162168
return [arg for arg in event_abi["inputs"] if arg["indexed"] is False]
163169

164170

165-
def get_normalized_abi_arg_type(
166-
abi_arg: Union[ABIComponent, ABIComponentIndexed]
167-
) -> str:
168-
"""
169-
Return the normalized type for the abi argument provided.
170-
In order to account for tuple argument types, this abstraction
171-
makes use of `collapse_if_tuple()` to collapse the appropriate component
172-
types within a tuple type, if present.
173-
"""
174-
return collapse_if_tuple(dict(abi_arg))
175-
176-
177171
def filter_by_argument_count(
178172
num_arguments: int, contract_abi: ABI
179173
) -> List[Union[ABIFunction, ABIEvent]]:
@@ -471,7 +465,7 @@ def get_aligned_abi_inputs(
471465
args = tuple(args[abi["name"]] for abi in input_abis)
472466

473467
return (
474-
tuple(collapse_if_tuple(abi) for abi in input_abis),
468+
tuple(get_normalized_abi_arg_type(abi) for abi in input_abis),
475469
type(args)(_align_abi_input(abi, arg) for abi, arg in zip(input_abis, args)),
476470
)
477471

@@ -625,7 +619,7 @@ def abi_to_signature(abi: Union[ABIFunction, ABIEvent]) -> str:
625619
function_signature = "{fn_name}({fn_input_types})".format(
626620
fn_name=abi["name"],
627621
fn_input_types=",".join(
628-
collapse_if_tuple(dict(arg))
622+
get_normalized_abi_arg_type(dict(arg))
629623
for arg in normalize_event_input_types(abi.get("inputs", []))
630624
),
631625
)
@@ -869,12 +863,10 @@ def named_tree(
869863

870864

871865
def _named_subtree(
872-
abi: Union[
873-
ABIComponent, ABIComponentIndexed, ABIFunction, ABIEvent, Dict[TypeStr, Any]
874-
],
866+
abi: Union[ABIComponent, ABIComponentIndexed],
875867
data: Tuple[Any, ...],
876868
) -> Union[Dict[str, Any], Tuple[Any, ...], List[Any]]:
877-
abi_type = parse(collapse_if_tuple(dict(abi)))
869+
abi_type = parse(get_normalized_abi_arg_type(abi))
878870

879871
if abi_type.is_array:
880872
item_type = abi_type.item_type.to_type_str()

0 commit comments

Comments
 (0)