73
73
)
74
74
from eth_utils .toolz import (
75
75
curry ,
76
- partial ,
77
76
pipe ,
78
77
)
79
78
@@ -115,21 +114,21 @@ def receive_func_abi_exists(contract_abi: ABI) -> Sequence[ABIReceive]:
115
114
return filter_abi_by_type ("receive" , contract_abi )
116
115
117
116
118
- def get_indexed_event_inputs (event_abi : ABIEvent ) -> Sequence [ABIComponentIndexed ]:
117
+ def get_indexed_event_inputs (event_abi : ABIEvent ) -> List [ABIComponentIndexed ]:
119
118
return [arg for arg in event_abi ["inputs" ] if arg ["indexed" ] is True ]
120
119
121
120
122
- def exclude_indexed_event_inputs (event_abi : ABIEvent ) -> Sequence [ABIComponentIndexed ]:
121
+ def exclude_indexed_event_inputs (event_abi : ABIEvent ) -> List [ABIComponentIndexed ]:
123
122
return [arg for arg in event_abi ["inputs" ] if arg ["indexed" ] is False ]
124
123
125
124
126
- def filter_by_types (types : Collection [str ], contract_abi : ABI ) -> Sequence [ABIElement ]:
125
+ def filter_by_types (types : Collection [str ], contract_abi : ABI ) -> List [ABIElement ]:
127
126
return [abi_element for abi_element in contract_abi if abi_element ["type" ] in types ]
128
127
129
128
130
129
def filter_by_argument_name (
131
130
argument_names : Collection [str ], contract_abi : ABI
132
- ) -> Sequence [ABIElement ]:
131
+ ) -> List [ABIElement ]:
133
132
"""
134
133
Return a list of each ``ABIElement`` which contains arguments matching provided
135
134
names.
@@ -186,7 +185,7 @@ def get_name_from_abi_element_identifier(
186
185
187
186
def get_abi_element_signature (
188
187
abi_element_identifier : ABIElementIdentifier ,
189
- abi_element_argument_types : Optional [Sequence [str ]] = None ,
188
+ abi_element_argument_types : Optional [Iterable [str ]] = None ,
190
189
) -> str :
191
190
element_name = get_name_from_abi_element_identifier (abi_element_identifier )
192
191
argument_types = "," .join (abi_element_argument_types or [])
@@ -585,9 +584,9 @@ def normalize_event_input_types(
585
584
586
585
@curry
587
586
def map_abi_data (
588
- normalizers : Sequence [Callable [[TypeStr , Any ], Tuple [TypeStr , Any ]]],
589
- types : Sequence [TypeStr ],
590
- data : Sequence [Any ],
587
+ normalizers : Iterable [Callable [[TypeStr , Any ], Tuple [TypeStr , Any ]]],
588
+ types : Iterable [TypeStr ],
589
+ data : Iterable [Any ],
591
590
) -> Any :
592
591
"""
593
592
Applies normalizers to your data, in the context of the relevant types.
@@ -611,17 +610,21 @@ def normalizer(datatype, data):
611
610
2. Recursively mapping each of the normalizers to the data
612
611
3. Stripping the types back out of the tree
613
612
"""
614
- pipeline = itertools .chain (
615
- [abi_data_tree (types )],
616
- map (data_tree_map , normalizers ),
617
- [partial (recursive_map , strip_abi_type )],
613
+ return pipe (
614
+ data ,
615
+ # 1. Decorating the data tree with types
616
+ abi_data_tree (types ),
617
+ # 2. Recursively mapping each of the normalizers to the data
618
+ * map (data_tree_map , normalizers ),
619
+ # 3. Stripping the types back out of the tree
620
+ strip_abi_types ,
618
621
)
619
622
620
- return pipe (data , * pipeline )
621
-
622
623
623
624
@curry
624
- def abi_data_tree (types : Sequence [TypeStr ], data : Sequence [Any ]) -> List [Any ]:
625
+ def abi_data_tree (
626
+ types : Iterable [TypeStr ], data : Iterable [Any ]
627
+ ) -> List ["ABITypedData" ]:
625
628
"""
626
629
Decorate the data tree with pairs of (type, data). The pair tuple is actually an
627
630
ABITypedData, but can be accessed as a tuple.
@@ -631,10 +634,7 @@ def abi_data_tree(types: Sequence[TypeStr], data: Sequence[Any]) -> List[Any]:
631
634
>>> abi_data_tree(types=["bool[2]", "uint"], data=[[True, False], 0])
632
635
[("bool[2]", [("bool", True), ("bool", False)]), ("uint256", 0)]
633
636
"""
634
- return [
635
- abi_sub_tree (data_type , data_value )
636
- for data_type , data_value in zip (types , data )
637
- ]
637
+ return list (map (abi_sub_tree , types , data ))
638
638
639
639
640
640
@curry
@@ -723,6 +723,10 @@ def strip_abi_type(elements: Any) -> Any:
723
723
return elements
724
724
725
725
726
+ def strip_abi_types (elements : Any ) -> Any :
727
+ return recursive_map (strip_abi_type , elements )
728
+
729
+
726
730
def build_non_strict_registry () -> ABIRegistry :
727
731
# We make a copy here just to make sure that eth-abi's default registry is not
728
732
# affected by our custom encoder subclasses
0 commit comments