|
22 | 22 | )
|
23 | 23 | from eth_abi.grammar import (
|
24 | 24 | ABIType,
|
| 25 | + TupleType, |
25 | 26 | parse,
|
26 | 27 | )
|
27 | 28 | from eth_abi.registry import (
|
@@ -669,11 +670,27 @@ def abi_sub_tree(abi_type: Optional[Union[TypeStr, ABIType]], data_value: Any) -
|
669 | 670 | if isinstance(abi_type, TypeStr):
|
670 | 671 | abi_type = parse(abi_type)
|
671 | 672 |
|
| 673 | + # In the two special cases below, we rebuild the given data structures with |
| 674 | + # annotated items |
672 | 675 | if abi_type.is_array:
|
673 |
| - it = abi_type.item_type |
674 |
| - return ABITypedData([abi_type.to_type_str(), [abi_sub_tree(it, i) for i in data_value]]) |
675 |
| - else: |
676 |
| - return ABITypedData([abi_type.to_type_str(), data_value]) |
| 676 | + # If type is array, determine item type and annotate all |
| 677 | + # items in iterable with that type |
| 678 | + item_type_str = abi_type.item_type.to_type_str() |
| 679 | + data_value = type(data_value)( |
| 680 | + abi_sub_tree(item_type_str, i) for i in data_value |
| 681 | + ) |
| 682 | + elif isinstance(abi_type, TupleType): |
| 683 | + # Otherwise, if type is tuple, determine component types and annotate |
| 684 | + # items in iterable respectively with those types |
| 685 | + data_value = type(data_value)( |
| 686 | + abi_sub_tree(comp_type.to_type_str(), i) |
| 687 | + for comp_type, i in zip(abi_type.components, data_value) |
| 688 | + ) |
| 689 | + |
| 690 | + return ABITypedData([ |
| 691 | + abi_type.to_type_str(), |
| 692 | + data_value, |
| 693 | + ]) |
677 | 694 |
|
678 | 695 |
|
679 | 696 | def strip_abi_type(elements):
|
|
0 commit comments