15
15
remove_0x_prefix ,
16
16
text_if_str ,
17
17
to_checksum_address ,
18
+ to_list ,
18
19
)
19
20
from eth_utils .toolz import (
20
21
complement ,
@@ -128,14 +129,18 @@ def to_hexbytes(num_bytes, val, variable_length=False):
128
129
whisper_log_formatter = apply_formatters_to_dict (WHISPER_LOG_FORMATTERS )
129
130
130
131
132
+ def apply_list_to_array_formatter (formatter ):
133
+ return to_list (apply_formatter_to_array (formatter ))
134
+
135
+
131
136
LOG_ENTRY_FORMATTERS = {
132
137
'blockHash' : apply_formatter_if (is_not_null , to_hexbytes (32 )),
133
138
'blockNumber' : apply_formatter_if (is_not_null , to_integer_if_hex ),
134
139
'transactionIndex' : apply_formatter_if (is_not_null , to_integer_if_hex ),
135
140
'transactionHash' : apply_formatter_if (is_not_null , to_hexbytes (32 )),
136
141
'logIndex' : to_integer_if_hex ,
137
142
'address' : to_checksum_address ,
138
- 'topics' : apply_formatter_to_array (to_hexbytes (32 )),
143
+ 'topics' : apply_list_to_array_formatter (to_hexbytes (32 )),
139
144
'data' : to_ascii_if_bytes ,
140
145
}
141
146
@@ -152,7 +157,7 @@ def to_hexbytes(num_bytes, val, variable_length=False):
152
157
'status' : to_integer_if_hex ,
153
158
'gasUsed' : to_integer_if_hex ,
154
159
'contractAddress' : apply_formatter_if (is_not_null , to_checksum_address ),
155
- 'logs' : apply_formatter_to_array (log_entry_formatter ),
160
+ 'logs' : apply_list_to_array_formatter (log_entry_formatter ),
156
161
'logsBloom' : to_hexbytes (256 ),
157
162
}
158
163
@@ -173,14 +178,14 @@ def to_hexbytes(num_bytes, val, variable_length=False):
173
178
'number' : apply_formatter_if (is_not_null , to_integer_if_hex ),
174
179
'parentHash' : apply_formatter_if (is_not_null , to_hexbytes (32 )),
175
180
'sha3Uncles' : apply_formatter_if (is_not_null , to_hexbytes (32 )),
176
- 'uncles' : apply_formatter_to_array (to_hexbytes (32 )),
181
+ 'uncles' : apply_list_to_array_formatter (to_hexbytes (32 )),
177
182
'difficulty' : to_integer_if_hex ,
178
183
'receiptsRoot' : to_hexbytes (32 ),
179
184
'stateRoot' : to_hexbytes (32 ),
180
185
'totalDifficulty' : to_integer_if_hex ,
181
186
'transactions' : apply_one_of_formatters ((
182
- (is_array_of_dicts , apply_formatter_to_array (transaction_formatter )),
183
- (is_array_of_strings , apply_formatter_to_array (to_hexbytes (32 ))),
187
+ (is_array_of_dicts , apply_list_to_array_formatter (transaction_formatter )),
188
+ (is_array_of_strings , apply_list_to_array_formatter (to_hexbytes (32 ))),
184
189
)),
185
190
'transactionsRoot' : to_hexbytes (32 ),
186
191
}
@@ -192,17 +197,19 @@ def to_hexbytes(num_bytes, val, variable_length=False):
192
197
STORAGE_PROOF_FORMATTERS = {
193
198
'key' : HexBytes ,
194
199
'value' : HexBytes ,
195
- 'proof' : apply_formatter_to_array (HexBytes ),
200
+ 'proof' : apply_list_to_array_formatter (HexBytes ),
196
201
}
197
202
198
203
ACCOUNT_PROOF_FORMATTERS = {
199
204
'address' : to_checksum_address ,
200
- 'accountProof' : apply_formatter_to_array (HexBytes ),
205
+ 'accountProof' : apply_list_to_array_formatter (HexBytes ),
201
206
'balance' : to_integer_if_hex ,
202
207
'codeHash' : to_hexbytes (32 ),
203
208
'nonce' : to_integer_if_hex ,
204
209
'storageHash' : to_hexbytes (32 ),
205
- 'storageProof' : apply_formatter_to_array (apply_formatters_to_dict (STORAGE_PROOF_FORMATTERS ))
210
+ 'storageProof' : apply_list_to_array_formatter (
211
+ apply_formatters_to_dict (STORAGE_PROOF_FORMATTERS )
212
+ )
206
213
}
207
214
208
215
proof_formatter = apply_formatters_to_dict (ACCOUNT_PROOF_FORMATTERS )
@@ -258,8 +265,8 @@ def to_hexbytes(num_bytes, val, variable_length=False):
258
265
259
266
260
267
filter_result_formatter = apply_one_of_formatters ((
261
- (is_array_of_dicts , apply_formatter_to_array (log_entry_formatter )),
262
- (is_array_of_strings , apply_formatter_to_array (to_hexbytes (32 ))),
268
+ (is_array_of_dicts , apply_list_to_array_formatter (log_entry_formatter )),
269
+ (is_array_of_strings , apply_list_to_array_formatter (to_hexbytes (32 ))),
263
270
))
264
271
265
272
@@ -328,7 +335,7 @@ def to_hexbytes(num_bytes, val, variable_length=False):
328
335
},
329
336
result_formatters = {
330
337
# Eth
331
- 'eth_accounts' : apply_formatter_to_array (to_checksum_address ),
338
+ 'eth_accounts' : apply_list_to_array_formatter (to_checksum_address ),
332
339
'eth_blockNumber' : to_integer_if_hex ,
333
340
'eth_chainId' : to_integer_if_hex ,
334
341
'eth_coinbase' : to_checksum_address ,
@@ -374,12 +381,12 @@ def to_hexbytes(num_bytes, val, variable_length=False):
374
381
'eth_syncing' : apply_formatter_if (is_not_false , syncing_formatter ),
375
382
# personal
376
383
'personal_importRawKey' : to_checksum_address ,
377
- 'personal_listAccounts' : apply_formatter_to_array (to_checksum_address ),
384
+ 'personal_listAccounts' : apply_list_to_array_formatter (to_checksum_address ),
378
385
'personal_newAccount' : to_checksum_address ,
379
386
'personal_signTypedData' : HexBytes ,
380
387
'personal_sendTransaction' : to_hexbytes (32 ),
381
388
# SHH
382
- 'shh_getFilterMessages' : apply_formatter_to_array (whisper_log_formatter ),
389
+ 'shh_getFilterMessages' : apply_list_to_array_formatter (whisper_log_formatter ),
383
390
# Transaction Pool
384
391
'txpool_content' : transaction_pool_content_formatter ,
385
392
'txpool_inspect' : transaction_pool_inspect_formatter ,
0 commit comments