def construct_event_data_set( event_abi: ABIEvent, abi_codec: ABICodec, arguments: Optional[Union[Sequence[Any], Dict[str, Any]]] = None ) -> List[List[Optional[HexStr]]]: if arguments is None: arguments = {} if isinstance(arguments, (list, tuple)): if len(arguments) != len(event_abi['inputs']): raise ValueError( "When passing an argument list, the number of arguments must " "match the event constructor." ) arguments = { arg['name']: [arg_value] for arg, arg_value in zip(event_abi['inputs'], arguments) } normalized_args = { key: value if is_list_like(value) else [value] # type ignored b/c at this point arguments is always a dict for key, value in arguments.items() # type: ignore } non_indexed_args = exclude_indexed_event_inputs(event_abi) zipped_abi_and_args = [ (arg, normalized_args.get(arg['name'], [None])) for arg in non_indexed_args ] encoded_args = [ [ None if option is None else encode_hex(abi_codec.encode_single(arg['type'], option)) for option in arg_options] for arg, arg_options in zipped_abi_and_args ] data = [ list(permutation) if any(value is not None for value in permutation) else [] for permutation in itertools.product(*encoded_args) ] return data
def construct_event_topic_set( event_abi: ABIEvent, abi_codec: ABICodec, arguments: Optional[Union[Sequence[Any], Dict[str, Any]]] = None ) -> List[HexStr]: if arguments is None: arguments = {} if isinstance(arguments, (list, tuple)): if len(arguments) != len(event_abi['inputs']): raise ValueError( "When passing an argument list, the number of arguments must " "match the event constructor." ) arguments = { arg['name']: [arg_value] for arg, arg_value in zip(event_abi['inputs'], arguments) } normalized_args = { key: value if is_list_like(value) else [value] # type ignored b/c arguments is always a dict at this point for key, value in arguments.items() # type: ignore } # typed dict cannot be used w/ a normal Dict # https://github.com/python/mypy/issues/4976 event_topic = encode_hex(event_abi_to_log_topic(event_abi)) # type: ignore indexed_args = get_indexed_event_inputs(event_abi) zipped_abi_and_args = [ (arg, normalized_args.get(arg['name'], [None])) for arg in indexed_args ] encoded_args = [ [ None if option is None else encode_hex(abi_codec.encode_single(arg['type'], option)) for option in arg_options] for arg, arg_options in zipped_abi_and_args ] topics = list(normalize_topic_list([event_topic] + encoded_args)) # type: ignore return topics