Skip to content

Commit c3d4254

Browse files
committed
Abstract collapsing tuple abi arg types
1 parent 882dbff commit c3d4254

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

web3/_utils/abi.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ def exclude_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIEventParams]:
154154
return [arg for arg in event_abi['inputs'] if arg['indexed'] is False]
155155

156156

157+
def get_normalized_abi_arg_type(abi_arg: ABIEventParams) -> str:
158+
"""
159+
Return the normalized type for the abi argument provided. In order to account for tuple argument
160+
types, this abstraction makes use of `collapse_if_tuple()` to collapse the appropriate component
161+
types within a tuple type, if present.
162+
"""
163+
return collapse_if_tuple(dict(abi_arg))
164+
165+
157166
def filter_by_argument_count(
158167
num_arguments: int, contract_abi: ABI
159168
) -> List[Union[ABIFunction, ABIEvent]]:

web3/_utils/events.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
to_hex,
4040
to_tuple,
4141
)
42-
from eth_utils.abi import (
43-
collapse_if_tuple,
44-
)
4542
from eth_utils.curried import (
4643
apply_formatter_if,
4744
)
@@ -58,6 +55,7 @@
5855
exclude_indexed_event_inputs,
5956
get_abi_input_names,
6057
get_indexed_event_inputs,
58+
get_normalized_abi_arg_type,
6159
map_abi_data,
6260
normalize_event_input_types,
6361
)
@@ -196,7 +194,7 @@ def get_event_abi_types_for_decoding(event_inputs: Sequence[ABIEventParams]) ->
196194
if input_abi['indexed'] and is_dynamic_sized_type(input_abi['type']):
197195
yield 'bytes32'
198196
else:
199-
yield collapse_if_tuple(dict(input_abi))
197+
yield get_normalized_abi_arg_type(input_abi)
200198

201199

202200
@curry
@@ -433,9 +431,12 @@ def _build_argument_filters_from_event_abi(
433431
key = item['name']
434432
value: 'BaseArgumentFilter'
435433
if item['indexed'] is True:
436-
value = TopicArgumentFilter(abi_codec=abi_codec, arg_type=collapse_if_tuple(dict(item)))
434+
value = TopicArgumentFilter(
435+
abi_codec=abi_codec,
436+
arg_type=get_normalized_abi_arg_type(item)
437+
)
437438
else:
438-
value = DataArgumentFilter(arg_type=collapse_if_tuple(dict(item)))
439+
value = DataArgumentFilter(arg_type=get_normalized_abi_arg_type(item))
439440
yield key, value
440441

441442

0 commit comments

Comments
 (0)