@@ -64,7 +64,58 @@ def is_hexstr(value: Any) -> bool:
64
64
is_not_named_block = complement (is_named_block )
65
65
66
66
67
- TRANSACTION_KEY_MAPPINGS = {
67
+ # --- Request Mapping --- #
68
+
69
+ TRANSACTION_REQUEST_KEY_MAPPING = {
70
+ 'gasPrice' : 'gas_price' ,
71
+ 'maxFeePerGas' : 'max_fee_per_gas' ,
72
+ 'maxPriorityFeePerGas' : 'max_priority_fee_per_gas' ,
73
+ 'accessList' : 'access_list' ,
74
+ }
75
+ transaction_request_remapper = apply_key_map (TRANSACTION_REQUEST_KEY_MAPPING )
76
+
77
+
78
+ TRANSACTION_REQUEST_FORMATTERS = {
79
+ 'gas' : to_integer_if_hex ,
80
+ 'gasPrice' : to_integer_if_hex ,
81
+ 'value' : to_integer_if_hex ,
82
+ 'nonce' : to_integer_if_hex ,
83
+ 'maxFeePerGas' : to_integer_if_hex ,
84
+ 'maxPriorityFeePerGas' : to_integer_if_hex ,
85
+ 'accessList' : apply_formatter_to_array (
86
+ apply_key_map ({'storageKeys' : 'storage_keys' })
87
+ ),
88
+ }
89
+ transaction_request_formatter = apply_formatters_to_dict (TRANSACTION_REQUEST_FORMATTERS )
90
+
91
+ transaction_request_transformer = compose (
92
+ transaction_request_remapper ,
93
+ transaction_request_formatter ,
94
+ )
95
+
96
+
97
+ FILTER_REQUEST_KEY_MAPPING = {
98
+ 'fromBlock' : 'from_block' ,
99
+ 'toBlock' : 'to_block' ,
100
+ }
101
+ filter_request_remapper = apply_key_map (FILTER_REQUEST_KEY_MAPPING )
102
+
103
+
104
+ FILTER_REQUEST_FORMATTERS = {
105
+ 'fromBlock' : to_integer_if_hex ,
106
+ 'toBlock' : to_integer_if_hex ,
107
+ }
108
+ filter_request_formatter = apply_formatters_to_dict (FILTER_REQUEST_FORMATTERS )
109
+
110
+ filter_request_transformer = compose (
111
+ filter_request_remapper ,
112
+ filter_request_formatter ,
113
+ )
114
+
115
+
116
+ # --- Result Mapping --- #
117
+
118
+ TRANSACTION_RESULT_KEY_MAPPING = {
68
119
'access_list' : 'accessList' ,
69
120
'block_hash' : 'blockHash' ,
70
121
'block_number' : 'blockNumber' ,
@@ -74,20 +125,29 @@ def is_hexstr(value: Any) -> bool:
74
125
'transaction_hash' : 'transactionHash' ,
75
126
'transaction_index' : 'transactionIndex' ,
76
127
}
77
- transaction_key_remapper = apply_key_map (TRANSACTION_KEY_MAPPINGS )
128
+ transaction_result_remapper = apply_key_map (TRANSACTION_RESULT_KEY_MAPPING )
129
+
130
+
131
+ TRANSACTION_RESULT_FORMATTERS = {
132
+ 'to' : apply_formatter_if (partial (operator .eq , '' ), static_return (None )),
133
+ 'access_list' : apply_formatter_to_array (
134
+ apply_key_map ({'storage_keys' : 'storageKeys' }),
135
+ ),
136
+ }
137
+ transaction_result_formatter = apply_formatters_to_dict (TRANSACTION_RESULT_FORMATTERS )
78
138
79
139
80
- LOG_KEY_MAPPINGS = {
140
+ LOG_RESULT_KEY_MAPPING = {
81
141
'log_index' : 'logIndex' ,
82
142
'transaction_index' : 'transactionIndex' ,
83
143
'transaction_hash' : 'transactionHash' ,
84
144
'block_hash' : 'blockHash' ,
85
145
'block_number' : 'blockNumber' ,
86
146
}
87
- log_key_remapper = apply_key_map (LOG_KEY_MAPPINGS )
147
+ log_result_remapper = apply_key_map (LOG_RESULT_KEY_MAPPING )
88
148
89
149
90
- RECEIPT_KEY_MAPPINGS = {
150
+ RECEIPT_RESULT_KEY_MAPPING = {
91
151
'block_hash' : 'blockHash' ,
92
152
'block_number' : 'blockNumber' ,
93
153
'contract_address' : 'contractAddress' ,
@@ -97,10 +157,10 @@ def is_hexstr(value: Any) -> bool:
97
157
'transaction_hash' : 'transactionHash' ,
98
158
'transaction_index' : 'transactionIndex' ,
99
159
}
100
- receipt_key_remapper = apply_key_map (RECEIPT_KEY_MAPPINGS )
160
+ receipt_result_remapper = apply_key_map (RECEIPT_RESULT_KEY_MAPPING )
101
161
102
162
103
- BLOCK_KEY_MAPPINGS = {
163
+ BLOCK_RESULT_KEY_MAPPING = {
104
164
'gas_limit' : 'gasLimit' ,
105
165
'sha3_uncles' : 'sha3Uncles' ,
106
166
'transactions_root' : 'transactionsRoot' ,
@@ -113,55 +173,13 @@ def is_hexstr(value: Any) -> bool:
113
173
'gas_used' : 'gasUsed' ,
114
174
'base_fee_per_gas' : 'baseFeePerGas' ,
115
175
}
116
- block_key_remapper = apply_key_map (BLOCK_KEY_MAPPINGS )
117
-
118
-
119
- TRANSACTION_PARAMS_MAPPING = {
120
- 'gasPrice' : 'gas_price' ,
121
- 'maxFeePerGas' : 'max_fee_per_gas' ,
122
- 'maxPriorityFeePerGas' : 'max_priority_fee_per_gas' ,
123
- 'accessList' : 'access_list' ,
124
- }
125
- transaction_params_remapper = apply_key_map (TRANSACTION_PARAMS_MAPPING )
126
-
127
-
128
- REQUEST_TRANSACTION_FORMATTERS = {
129
- 'gas' : to_integer_if_hex ,
130
- 'gasPrice' : to_integer_if_hex ,
131
- 'value' : to_integer_if_hex ,
132
- 'nonce' : to_integer_if_hex ,
133
- 'maxFeePerGas' : to_integer_if_hex ,
134
- 'maxPriorityFeePerGas' : to_integer_if_hex ,
135
- }
136
- request_transaction_formatter = apply_formatters_to_dict (REQUEST_TRANSACTION_FORMATTERS )
137
-
138
-
139
- FILTER_PARAMS_MAPPINGS = {
140
- 'fromBlock' : 'from_block' ,
141
- 'toBlock' : 'to_block' ,
142
- }
143
- filter_params_remapper = apply_key_map (FILTER_PARAMS_MAPPINGS )
144
-
145
-
146
- FILTER_PARAMS_FORMATTERS = {
147
- 'fromBlock' : to_integer_if_hex ,
148
- 'toBlock' : to_integer_if_hex ,
149
- }
150
- filter_params_formatter = apply_formatters_to_dict (FILTER_PARAMS_FORMATTERS )
151
- filter_params_transformer = compose (filter_params_remapper , filter_params_formatter )
152
-
153
-
154
- RESPONSE_TRANSACTION_FORMATTERS = {
155
- 'to' : apply_formatter_if (partial (operator .eq , '' ), static_return (None )),
156
- }
157
- response_transaction_formatter = apply_formatters_to_dict (RESPONSE_TRANSACTION_FORMATTERS )
176
+ block_result_remapper = apply_key_map (BLOCK_RESULT_KEY_MAPPING )
158
177
159
178
160
- RECEIPT_FORMATTERS = {
161
- 'logs' : apply_formatter_to_array (log_key_remapper ),
179
+ RECEIPT_RESULT_FORMATTERS = {
180
+ 'logs' : apply_formatter_to_array (log_result_remapper ),
162
181
}
163
- receipt_formatter = apply_formatters_to_dict (RECEIPT_FORMATTERS )
164
- transaction_params_transformer = compose (transaction_params_remapper , request_transaction_formatter )
182
+ receipt_result_formatter = apply_formatters_to_dict (RECEIPT_RESULT_FORMATTERS )
165
183
166
184
167
185
ethereum_tester_middleware = construct_formatting_middleware (
@@ -191,19 +209,19 @@ def is_hexstr(value: Any) -> bool:
191
209
to_integer_if_hex ,
192
210
),
193
211
RPCEndpoint ('eth_newFilter' ): apply_formatters_to_args (
194
- filter_params_transformer ,
212
+ filter_request_transformer ,
195
213
),
196
214
RPCEndpoint ('eth_getLogs' ): apply_formatters_to_args (
197
- filter_params_transformer ,
215
+ filter_request_transformer ,
198
216
),
199
217
RPCEndpoint ('eth_sendTransaction' ): apply_formatters_to_args (
200
- transaction_params_transformer ,
218
+ transaction_request_transformer ,
201
219
),
202
220
RPCEndpoint ('eth_estimateGas' ): apply_formatters_to_args (
203
- transaction_params_transformer ,
221
+ transaction_request_transformer ,
204
222
),
205
223
RPCEndpoint ('eth_call' ): apply_formatters_to_args (
206
- transaction_params_transformer ,
224
+ transaction_request_transformer ,
207
225
apply_formatter_if (is_not_named_block , to_integer_if_hex ),
208
226
),
209
227
RPCEndpoint ('eth_uninstallFilter' ): apply_formatters_to_args (hex_to_integer ),
@@ -219,49 +237,49 @@ def is_hexstr(value: Any) -> bool:
219
237
RPCEndpoint ('evm_revert' ): apply_formatters_to_args (hex_to_integer ),
220
238
# Personal
221
239
RPCEndpoint ('personal_sendTransaction' ): apply_formatters_to_args (
222
- transaction_params_transformer ,
240
+ transaction_request_transformer ,
223
241
identity ,
224
242
),
225
243
},
226
244
result_formatters = {
227
245
RPCEndpoint ('eth_getBlockByHash' ): apply_formatter_if (
228
246
is_dict ,
229
- block_key_remapper ,
247
+ block_result_remapper ,
230
248
),
231
249
RPCEndpoint ('eth_getBlockByNumber' ): apply_formatter_if (
232
250
is_dict ,
233
- block_key_remapper ,
251
+ block_result_remapper ,
234
252
),
235
253
RPCEndpoint ('eth_getBlockTransactionCountByHash' ): apply_formatter_if (
236
254
is_dict ,
237
- transaction_key_remapper ,
255
+ transaction_result_remapper ,
238
256
),
239
257
RPCEndpoint ('eth_getBlockTransactionCountByNumber' ): apply_formatter_if (
240
258
is_dict ,
241
- transaction_key_remapper ,
259
+ transaction_result_remapper ,
242
260
),
243
261
RPCEndpoint ('eth_getTransactionByHash' ): apply_formatter_if (
244
262
is_dict ,
245
- compose (transaction_key_remapper , response_transaction_formatter ),
263
+ compose (transaction_result_remapper , transaction_result_formatter ),
246
264
),
247
265
RPCEndpoint ('eth_getTransactionReceipt' ): apply_formatter_if (
248
266
is_dict ,
249
- compose (receipt_key_remapper , receipt_formatter ),
267
+ compose (receipt_result_remapper , receipt_result_formatter ),
250
268
),
251
269
RPCEndpoint ('eth_newFilter' ): integer_to_hex ,
252
270
RPCEndpoint ('eth_newBlockFilter' ): integer_to_hex ,
253
271
RPCEndpoint ('eth_newPendingTransactionFilter' ): integer_to_hex ,
254
272
RPCEndpoint ('eth_getLogs' ): apply_formatter_if (
255
273
is_array_of_dicts ,
256
- apply_formatter_to_array (log_key_remapper ),
274
+ apply_formatter_to_array (log_result_remapper ),
257
275
),
258
276
RPCEndpoint ('eth_getFilterChanges' ): apply_formatter_if (
259
277
is_array_of_dicts ,
260
- apply_formatter_to_array (log_key_remapper ),
278
+ apply_formatter_to_array (log_result_remapper ),
261
279
),
262
280
RPCEndpoint ('eth_getFilterLogs' ): apply_formatter_if (
263
281
is_array_of_dicts ,
264
- apply_formatter_to_array (log_key_remapper ),
282
+ apply_formatter_to_array (log_result_remapper ),
265
283
),
266
284
# EVM
267
285
RPCEndpoint ('evm_snapshot' ): integer_to_hex ,
0 commit comments