22import operator
33
44from eth_utils .curried import (
5+ apply_formatter_at_index ,
6+ apply_formatter_if ,
7+ apply_formatters_to_dict ,
58 apply_formatters_to_sequence ,
9+ apply_one_of_formatters ,
610 is_address ,
711 is_bytes ,
812 is_integer ,
1115 remove_0x_prefix ,
1216 text_if_str ,
1317 to_checksum_address ,
18+ to_list ,
1419)
1520from eth_utils .toolz import (
1621 complement ,
3136 to_hex ,
3237)
3338from web3 ._utils .formatters import (
34- apply_formatter_at_index ,
35- apply_formatter_if ,
3639 apply_formatter_to_array ,
37- apply_formatters_to_dict ,
38- apply_one_of_formatters ,
3940 hex_to_integer ,
4041 integer_to_hex ,
4142 is_array_of_dicts ,
@@ -128,14 +129,18 @@ def to_hexbytes(num_bytes, val, variable_length=False):
128129whisper_log_formatter = apply_formatters_to_dict (WHISPER_LOG_FORMATTERS )
129130
130131
132+ def apply_list_to_array_formatter (formatter ):
133+ return to_list (apply_formatter_to_array (formatter ))
134+
135+
131136LOG_ENTRY_FORMATTERS = {
132137 'blockHash' : apply_formatter_if (is_not_null , to_hexbytes (32 )),
133138 'blockNumber' : apply_formatter_if (is_not_null , to_integer_if_hex ),
134139 'transactionIndex' : apply_formatter_if (is_not_null , to_integer_if_hex ),
135140 'transactionHash' : apply_formatter_if (is_not_null , to_hexbytes (32 )),
136141 'logIndex' : to_integer_if_hex ,
137142 'address' : to_checksum_address ,
138- 'topics' : apply_formatter_to_array (to_hexbytes (32 )),
143+ 'topics' : apply_list_to_array_formatter (to_hexbytes (32 )),
139144 'data' : to_ascii_if_bytes ,
140145}
141146
@@ -152,7 +157,7 @@ def to_hexbytes(num_bytes, val, variable_length=False):
152157 'status' : to_integer_if_hex ,
153158 'gasUsed' : to_integer_if_hex ,
154159 '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 ),
156161 'logsBloom' : to_hexbytes (256 ),
157162}
158163
@@ -173,14 +178,14 @@ def to_hexbytes(num_bytes, val, variable_length=False):
173178 'number' : apply_formatter_if (is_not_null , to_integer_if_hex ),
174179 'parentHash' : apply_formatter_if (is_not_null , to_hexbytes (32 )),
175180 '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 )),
177182 'difficulty' : to_integer_if_hex ,
178183 'receiptsRoot' : to_hexbytes (32 ),
179184 'stateRoot' : to_hexbytes (32 ),
180185 'totalDifficulty' : to_integer_if_hex ,
181186 'transactions' : apply_one_of_formatters ((
182- (apply_formatter_to_array (transaction_formatter ), is_array_of_dicts ),
183- (apply_formatter_to_array (to_hexbytes (32 )), is_array_of_strings ),
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 ))),
184189 )),
185190 'transactionsRoot' : to_hexbytes (32 ),
186191}
@@ -192,17 +197,19 @@ def to_hexbytes(num_bytes, val, variable_length=False):
192197STORAGE_PROOF_FORMATTERS = {
193198 'key' : HexBytes ,
194199 'value' : HexBytes ,
195- 'proof' : apply_formatter_to_array (HexBytes ),
200+ 'proof' : apply_list_to_array_formatter (HexBytes ),
196201}
197202
198203ACCOUNT_PROOF_FORMATTERS = {
199204 'address' : to_checksum_address ,
200- 'accountProof' : apply_formatter_to_array (HexBytes ),
205+ 'accountProof' : apply_list_to_array_formatter (HexBytes ),
201206 'balance' : to_integer_if_hex ,
202207 'codeHash' : to_hexbytes (32 ),
203208 'nonce' : to_integer_if_hex ,
204209 '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+ )
206213}
207214
208215proof_formatter = apply_formatters_to_dict (ACCOUNT_PROOF_FORMATTERS )
@@ -258,8 +265,8 @@ def to_hexbytes(num_bytes, val, variable_length=False):
258265
259266
260267filter_result_formatter = apply_one_of_formatters ((
261- (apply_formatter_to_array (log_entry_formatter ), is_array_of_dicts ),
262- (apply_formatter_to_array (to_hexbytes (32 )), is_array_of_strings ),
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 ))),
263270))
264271
265272
@@ -305,8 +312,8 @@ def to_hexbytes(num_bytes, val, variable_length=False):
305312 block_number_formatter ,
306313 ]),
307314 'eth_estimateGas' : apply_one_of_formatters ((
308- (estimate_gas_without_block_id , is_length (1 )),
309- (estimate_gas_with_block_id , is_length (2 )),
315+ (is_length (1 ), estimate_gas_without_block_id ),
316+ (is_length (2 ), estimate_gas_with_block_id ),
310317 )),
311318 'eth_sendTransaction' : apply_formatter_at_index (transaction_param_formatter , 0 ),
312319 # personal
@@ -328,7 +335,7 @@ def to_hexbytes(num_bytes, val, variable_length=False):
328335 },
329336 result_formatters = {
330337 # Eth
331- 'eth_accounts' : apply_formatter_to_array (to_checksum_address ),
338+ 'eth_accounts' : apply_list_to_array_formatter (to_checksum_address ),
332339 'eth_blockNumber' : to_integer_if_hex ,
333340 'eth_chainId' : to_integer_if_hex ,
334341 'eth_coinbase' : to_checksum_address ,
@@ -374,12 +381,12 @@ def to_hexbytes(num_bytes, val, variable_length=False):
374381 'eth_syncing' : apply_formatter_if (is_not_false , syncing_formatter ),
375382 # personal
376383 '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 ),
378385 'personal_newAccount' : to_checksum_address ,
379386 'personal_signTypedData' : HexBytes ,
380387 'personal_sendTransaction' : to_hexbytes (32 ),
381388 # SHH
382- 'shh_getFilterMessages' : apply_formatter_to_array (whisper_log_formatter ),
389+ 'shh_getFilterMessages' : apply_list_to_array_formatter (whisper_log_formatter ),
383390 # Transaction Pool
384391 'txpool_content' : transaction_pool_content_formatter ,
385392 'txpool_inspect' : transaction_pool_inspect_formatter ,
0 commit comments