101
101
BlockIdentifier ,
102
102
Formatters ,
103
103
RPCEndpoint ,
104
+ SimulateV1Payload ,
104
105
StateOverrideParams ,
105
106
TReturn ,
106
107
TxParams ,
@@ -309,7 +310,32 @@ def storage_key_to_hexstr(value: Union[bytes, int, str]) -> HexStr:
309
310
310
311
receipt_formatter = type_aware_apply_formatters_to_dict (RECEIPT_FORMATTERS )
311
312
312
- BLOCK_FORMATTERS = {
313
+ BLOCK_REQUEST_FORMATTERS = {
314
+ "baseFeePerGas" : to_hex_if_integer ,
315
+ "extraData" : to_hex_if_bytes ,
316
+ "gasLimit" : to_hex_if_integer ,
317
+ "gasUsed" : to_hex_if_integer ,
318
+ "size" : to_hex_if_integer ,
319
+ "timestamp" : to_hex_if_integer ,
320
+ "hash" : to_hex_if_bytes ,
321
+ "logsBloom" : to_hex_if_bytes ,
322
+ "miner" : to_checksum_address ,
323
+ "mixHash" : to_hex_if_bytes ,
324
+ "nonce" : to_hex_if_bytes ,
325
+ "number" : to_hex_if_integer ,
326
+ "parentHash" : to_hex_if_bytes ,
327
+ "sha3Uncles" : to_hex_if_bytes ,
328
+ "difficulty" : to_hex_if_integer ,
329
+ "receiptsRoot" : to_hex_if_bytes ,
330
+ "stateRoot" : to_hex_if_bytes ,
331
+ "totalDifficulty" : to_hex_if_integer ,
332
+ "transactionsRoot" : to_hex_if_bytes ,
333
+ "withdrawalsRoot" : to_hex_if_bytes ,
334
+ "parentBeaconBlockRoot" : to_hex_if_bytes ,
335
+ }
336
+ block_request_formatter = type_aware_apply_formatters_to_dict (BLOCK_REQUEST_FORMATTERS )
337
+
338
+ BLOCK_RESULT_FORMATTERS = {
313
339
"baseFeePerGas" : to_integer_if_hex ,
314
340
"extraData" : apply_formatter_if (is_not_null , to_hexbytes (32 , variable_length = True )),
315
341
"gasLimit" : to_integer_if_hex ,
@@ -349,9 +375,7 @@ def storage_key_to_hexstr(value: Union[bytes, int, str]) -> HexStr:
349
375
"excessBlobGas" : to_integer_if_hex ,
350
376
"parentBeaconBlockRoot" : apply_formatter_if (is_not_null , to_hexbytes (32 )),
351
377
}
352
-
353
-
354
- block_formatter = type_aware_apply_formatters_to_dict (BLOCK_FORMATTERS )
378
+ block_result_formatter = type_aware_apply_formatters_to_dict (BLOCK_RESULT_FORMATTERS )
355
379
356
380
357
381
SYNCING_FORMATTERS = {
@@ -442,6 +466,22 @@ def storage_key_to_hexstr(value: Union[bytes, int, str]) -> HexStr:
442
466
)
443
467
)
444
468
469
+ TRANSACTION_REQUEST_FORMATTER = {
470
+ "from" : to_checksum_address ,
471
+ "to" : apply_formatter_if (is_address , to_checksum_address ),
472
+ "gas" : to_hex_if_integer ,
473
+ "gasPrice" : to_hex_if_integer ,
474
+ "value" : to_hex_if_integer ,
475
+ "data" : to_hex_if_bytes ,
476
+ "nonce" : to_hex_if_integer ,
477
+ "maxFeePerGas" : to_hex_if_integer ,
478
+ "maxPriorityFeePerGas" : to_hex_if_integer ,
479
+ "chainId" : to_hex_if_integer ,
480
+ }
481
+ transaction_request_formatter = type_aware_apply_formatters_to_dict (
482
+ TRANSACTION_REQUEST_FORMATTER
483
+ )
484
+
445
485
ACCESS_LIST_REQUEST_FORMATTER = type_aware_apply_formatters_to_dict (
446
486
{
447
487
"accessList" : apply_formatter_if (
@@ -472,11 +512,15 @@ def storage_key_to_hexstr(value: Union[bytes, int, str]) -> HexStr:
472
512
]
473
513
)
474
514
475
- CALL_OVERRIDE_FORMATTERS = {
515
+ STATE_OVERRIDE_FORMATTERS = {
476
516
"balance" : to_hex_if_integer ,
477
517
"nonce" : to_hex_if_integer ,
478
518
"code" : to_hex_if_bytes ,
479
519
}
520
+ state_override_formatter = type_aware_apply_formatters_to_dict (
521
+ STATE_OVERRIDE_FORMATTERS
522
+ )
523
+
480
524
call_with_override : Callable [
481
525
[Tuple [TxParams , BlockIdentifier , StateOverrideParams ]],
482
526
Tuple [Dict [str , Any ], int , Dict [str , Any ]],
@@ -486,29 +530,24 @@ def storage_key_to_hexstr(value: Union[bytes, int, str]) -> HexStr:
486
530
to_hex_if_integer ,
487
531
lambda val : type_aware_apply_formatters_to_dict_keys_and_values (
488
532
to_checksum_address ,
489
- type_aware_apply_formatters_to_dict ( CALL_OVERRIDE_FORMATTERS ) ,
533
+ state_override_formatter ,
490
534
val ,
491
535
),
492
536
]
493
537
)
494
538
495
539
496
- estimate_gas_without_block_id : Callable [[Dict [str , Any ]], Dict [str , Any ]]
497
- estimate_gas_without_block_id = apply_formatter_at_index (transaction_param_formatter , 0 )
540
+ estimate_gas_without_block_id : Callable [
541
+ [Dict [str , Any ]], Dict [str , Any ]
542
+ ] = apply_formatter_at_index (transaction_param_formatter , 0 )
498
543
estimate_gas_with_block_id : Callable [
499
544
[Tuple [Dict [str , Any ], BlockIdentifier ]], Tuple [Dict [str , Any ], int ]
500
- ]
501
- estimate_gas_with_block_id = apply_formatters_to_sequence (
545
+ ] = apply_formatters_to_sequence (
502
546
[
503
547
transaction_param_formatter ,
504
548
to_hex_if_integer ,
505
549
]
506
550
)
507
- ESTIMATE_GAS_OVERRIDE_FORMATTERS = {
508
- "balance" : to_hex_if_integer ,
509
- "nonce" : to_hex_if_integer ,
510
- "code" : to_hex_if_bytes ,
511
- }
512
551
estimate_gas_with_override : Callable [
513
552
[Tuple [Dict [str , Any ], BlockIdentifier , StateOverrideParams ]],
514
553
Tuple [Dict [str , Any ], int , Dict [str , Any ]],
@@ -518,12 +557,71 @@ def storage_key_to_hexstr(value: Union[bytes, int, str]) -> HexStr:
518
557
to_hex_if_integer ,
519
558
lambda val : type_aware_apply_formatters_to_dict_keys_and_values (
520
559
to_checksum_address ,
521
- type_aware_apply_formatters_to_dict ( ESTIMATE_GAS_OVERRIDE_FORMATTERS ) ,
560
+ state_override_formatter ,
522
561
val ,
523
562
),
524
563
]
525
564
)
526
565
566
+ # -- eth_simulateV1 -- #
567
+
568
+ block_state_calls_formatter : Callable [
569
+ [Dict [str , Any ]], Dict [str , Any ]
570
+ ] = apply_formatter_to_array (
571
+ apply_formatters_to_dict (
572
+ {
573
+ "blockOverrides" : block_request_formatter ,
574
+ "stateOverrides" : (
575
+ lambda val : type_aware_apply_formatters_to_dict_keys_and_values (
576
+ to_checksum_address ,
577
+ state_override_formatter ,
578
+ val ,
579
+ )
580
+ ),
581
+ "calls" : apply_formatter_to_array (transaction_request_formatter ),
582
+ },
583
+ ),
584
+ )
585
+
586
+ simulate_v1_request_formatter : Callable [
587
+ [Tuple [Dict [str , Any ], bool , bool ], BlockIdentifier ],
588
+ Tuple [SimulateV1Payload , BlockIdentifier ],
589
+ ] = apply_formatters_to_sequence (
590
+ [
591
+ # payload
592
+ apply_formatters_to_dict (
593
+ {
594
+ "blockStateCalls" : block_state_calls_formatter ,
595
+ },
596
+ ),
597
+ # block_identifier
598
+ to_hex_if_integer ,
599
+ ]
600
+ )
601
+
602
+ block_result_formatters_copy = BLOCK_RESULT_FORMATTERS .copy ()
603
+ block_result_formatters_copy .update (
604
+ {
605
+ "calls" : apply_list_to_array_formatter (
606
+ type_aware_apply_formatters_to_dict (
607
+ {
608
+ "returnData" : HexBytes ,
609
+ "logs" : apply_list_to_array_formatter (log_entry_formatter ),
610
+ "gasUsed" : to_integer_if_hex ,
611
+ "status" : to_integer_if_hex ,
612
+ }
613
+ )
614
+ )
615
+ }
616
+ )
617
+ simulate_v1_result_formatter = apply_formatter_if (
618
+ is_not_null ,
619
+ apply_list_to_array_formatter (
620
+ type_aware_apply_formatters_to_dict (block_result_formatters_copy )
621
+ ),
622
+ )
623
+
624
+
527
625
SIGNED_TX_FORMATTER = {
528
626
"raw" : HexBytes ,
529
627
"tx" : transaction_result_formatter ,
@@ -587,6 +685,7 @@ def storage_key_to_hexstr(value: Union[bytes, int, str]) -> HexStr:
587
685
(is_length (3 ), call_with_override ),
588
686
)
589
687
),
688
+ RPC .eth_simulateV1 : simulate_v1_request_formatter ,
590
689
RPC .eth_createAccessList : apply_formatter_at_index (transaction_param_formatter , 0 ),
591
690
RPC .eth_estimateGas : apply_one_of_formatters (
592
691
(
@@ -610,6 +709,7 @@ def storage_key_to_hexstr(value: Union[bytes, int, str]) -> HexStr:
610
709
}
611
710
612
711
# --- Result Formatters --- #
712
+
613
713
# -- debug -- #
614
714
DEBUG_CALLTRACE_LOG_ENTRY_FORMATTERS = apply_formatter_if (
615
715
is_not_null ,
@@ -795,11 +895,11 @@ def subscription_formatter(value: Any) -> Union[HexBytes, HexStr, Dict[str, Any]
795
895
# handle dict subscription responses
796
896
if either_set_is_a_subset (
797
897
result_key_set ,
798
- set (BLOCK_FORMATTERS .keys ()),
898
+ set (BLOCK_RESULT_FORMATTERS .keys ()),
799
899
percentage = 90 ,
800
900
):
801
901
# block format, newHeads
802
- result_formatter = block_formatter
902
+ result_formatter = block_result_formatter
803
903
804
904
elif either_set_is_a_subset (
805
905
result_key_set , set (LOG_ENTRY_FORMATTERS .keys ()), percentage = 75
@@ -846,8 +946,8 @@ def subscription_formatter(value: Any) -> Union[HexBytes, HexStr, Dict[str, Any]
846
946
RPC .eth_maxPriorityFeePerGas : to_integer_if_hex ,
847
947
RPC .eth_gasPrice : to_integer_if_hex ,
848
948
RPC .eth_getBalance : to_integer_if_hex ,
849
- RPC .eth_getBlockByHash : apply_formatter_if (is_not_null , block_formatter ),
850
- RPC .eth_getBlockByNumber : apply_formatter_if (is_not_null , block_formatter ),
949
+ RPC .eth_getBlockByHash : apply_formatter_if (is_not_null , block_result_formatter ),
950
+ RPC .eth_getBlockByNumber : apply_formatter_if (is_not_null , block_result_formatter ),
851
951
RPC .eth_getBlockReceipts : apply_formatter_to_array (receipt_formatter ),
852
952
RPC .eth_getBlockTransactionCountByHash : to_integer_if_hex ,
853
953
RPC .eth_getBlockTransactionCountByNumber : to_integer_if_hex ,
@@ -887,6 +987,7 @@ def subscription_formatter(value: Any) -> Union[HexBytes, HexStr, Dict[str, Any]
887
987
RPC .eth_sign : HexBytes ,
888
988
RPC .eth_signTransaction : apply_formatter_if (is_not_null , signed_tx_formatter ),
889
989
RPC .eth_signTypedData : HexBytes ,
990
+ RPC .eth_simulateV1 : simulate_v1_result_formatter ,
890
991
RPC .eth_syncing : apply_formatter_if (is_not_false , syncing_formatter ),
891
992
# Transaction Pool
892
993
RPC .txpool_content : transaction_pool_content_formatter ,
0 commit comments