@@ -83,7 +83,14 @@ def data_dict(self) -> dict:
83
83
84
84
Nested structs instances are also converted to dict form.
85
85
"""
86
- return {k : v .data_dict () if isinstance (v , EIP712Struct ) else v for k , v in self .values .items ()}
86
+ return {
87
+ k : v .data_dict ()
88
+ if isinstance (v , EIP712Struct )
89
+ else [e .data_dict () for e in v ]
90
+ if isinstance (v , list ) and len (v ) and isinstance (v [0 ], EIP712Struct )
91
+ else v
92
+ for k , v in self .values .items ()
93
+ }
87
94
88
95
@classmethod
89
96
def encode_type (cls , resolve : bool = True ) -> str :
@@ -95,7 +102,7 @@ def encode_type(cls, resolve: bool = True) -> str:
95
102
struct_sig = f"{ cls .type_name } ({ ',' .join (member_sigs )} )"
96
103
97
104
if resolve :
98
- reference_structs : set [EIP712Struct ] = set ()
105
+ reference_structs : list [EIP712Struct ] = []
99
106
cls .gather_reference_structs (reference_structs )
100
107
sorted_structs = sorted ((s for s in reference_structs if s != cls ), key = lambda s : s .type_name )
101
108
for struct in sorted_structs :
@@ -104,15 +111,17 @@ def encode_type(cls, resolve: bool = True) -> str:
104
111
return struct_sig
105
112
106
113
@classmethod
107
- def gather_reference_structs (cls , struct_set : set [EIP712Struct ]) -> None :
114
+ def gather_reference_structs (cls , struct_lst : list [EIP712Struct ]) -> None :
108
115
"""Finds reference structs defined in this struct type, and inserts them into the given set."""
109
- structs : list [EIP712Struct ] = [
110
- m [1 ] for m in cls .get_members () if isinstance (m [1 ], type ) and issubclass (m [1 ], EIP712Struct )
116
+ structs = [m [1 ] for m in cls .get_members () if isinstance (m [1 ], type ) and issubclass (m [1 ], EIP712Struct )] + [
117
+ m [1 ].member_type
118
+ for m in cls .get_members ()
119
+ if isinstance (m [1 ], Array ) and hasattr (m [1 ].member_type , "encode_type" )
111
120
]
112
121
for struct in structs :
113
- if struct not in struct_set :
114
- struct_set . add (struct )
115
- struct .gather_reference_structs (struct_set )
122
+ if struct not in struct_lst :
123
+ struct_lst . append (struct ) # type: ignore[arg-type]
124
+ struct .gather_reference_structs (struct_lst ) # type: ignore[union-attr]
116
125
117
126
@classmethod
118
127
def type_hash (cls ) -> bytes :
@@ -159,7 +168,7 @@ def to_message(self, domain: EIP712Struct | None = None) -> dict:
159
168
:returns: This struct + the domain in dict form, structured as specified for EIP712 messages.
160
169
"""
161
170
domain = self ._assert_domain (domain )
162
- structs = { domain , self }
171
+ structs = [ domain , self ]
163
172
self .gather_reference_structs (structs )
164
173
165
174
# Build type dictionary
0 commit comments