Skip to content

Commit

Permalink
Abstract collapsing tuple abi arg types
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Jan 13, 2022
1 parent 882dbff commit c3d4254
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
9 changes: 9 additions & 0 deletions web3/_utils/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ def exclude_indexed_event_inputs(event_abi: ABIEvent) -> List[ABIEventParams]:
return [arg for arg in event_abi['inputs'] if arg['indexed'] is False]


def get_normalized_abi_arg_type(abi_arg: ABIEventParams) -> 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
13 changes: 7 additions & 6 deletions web3/_utils/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
to_hex,
to_tuple,
)
from eth_utils.abi import (
collapse_if_tuple,
)
from eth_utils.curried import (
apply_formatter_if,
)
Expand All @@ -58,6 +55,7 @@
exclude_indexed_event_inputs,
get_abi_input_names,
get_indexed_event_inputs,
get_normalized_abi_arg_type,
map_abi_data,
normalize_event_input_types,
)
Expand Down Expand Up @@ -196,7 +194,7 @@ def get_event_abi_types_for_decoding(event_inputs: Sequence[ABIEventParams]) ->
if input_abi['indexed'] and is_dynamic_sized_type(input_abi['type']):
yield 'bytes32'
else:
yield collapse_if_tuple(dict(input_abi))
yield get_normalized_abi_arg_type(input_abi)


@curry
Expand Down Expand Up @@ -433,9 +431,12 @@ def _build_argument_filters_from_event_abi(
key = item['name']
value: 'BaseArgumentFilter'
if item['indexed'] is True:
value = TopicArgumentFilter(abi_codec=abi_codec, arg_type=collapse_if_tuple(dict(item)))
value = TopicArgumentFilter(
abi_codec=abi_codec,
arg_type=get_normalized_abi_arg_type(item)
)
else:
value = DataArgumentFilter(arg_type=collapse_if_tuple(dict(item)))
value = DataArgumentFilter(arg_type=get_normalized_abi_arg_type(item))
yield key, value


Expand Down

0 comments on commit c3d4254

Please sign in to comment.