From efaf13affb486504b1d9e4f737dc51ee967d0a9f Mon Sep 17 00:00:00 2001 From: Felipe Selmo Date: Thu, 13 Jan 2022 14:51:29 -0700 Subject: [PATCH] Abstract collapsing tuple abi arg types --- web3/_utils/abi.py | 9 +++++++++ web3/_utils/events.py | 13 +++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/web3/_utils/abi.py b/web3/_utils/abi.py index 7fbdc9968b..876ba9e9a4 100644 --- a/web3/_utils/abi.py +++ b/web3/_utils/abi.py @@ -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 the tuple type. + """ + return collapse_if_tuple(dict(abi_arg)) + + def filter_by_argument_count( num_arguments: int, contract_abi: ABI ) -> List[Union[ABIFunction, ABIEvent]]: diff --git a/web3/_utils/events.py b/web3/_utils/events.py index 5ad79bfde8..9cfe6fb685 100644 --- a/web3/_utils/events.py +++ b/web3/_utils/events.py @@ -39,9 +39,6 @@ to_hex, to_tuple, ) -from eth_utils.abi import ( - collapse_if_tuple, -) from eth_utils.curried import ( apply_formatter_if, ) @@ -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, ) @@ -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 @@ -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