@@ -3,21 +3,22 @@ use pathfinder_common::{ContractAddress, ContractNonce};
3
3
use serde:: ser:: Error ;
4
4
5
5
use super :: serialize:: SerializeStruct ;
6
+ use super :: FeeEstimate ;
6
7
use crate :: RpcVersion ;
7
8
8
9
#[ derive( Debug ) ]
9
- pub struct TransactionTrace < ' a > {
10
- pub trace : & ' a pathfinder_executor:: types:: TransactionTrace ,
10
+ pub struct TransactionTrace {
11
+ pub trace : pathfinder_executor:: types:: TransactionTrace ,
11
12
pub include_state_diff : bool ,
12
13
}
13
14
14
- impl crate :: dto:: serialize:: SerializeForVersion for TransactionTrace < ' _ > {
15
+ impl crate :: dto:: serialize:: SerializeForVersion for TransactionTrace {
15
16
fn serialize (
16
17
& self ,
17
18
serializer : super :: serialize:: Serializer ,
18
19
) -> Result < super :: serialize:: Ok , super :: serialize:: Error > {
19
20
let mut serializer = serializer. serialize_struct ( ) ?;
20
- match self . trace {
21
+ match & self . trace {
21
22
pathfinder_executor:: types:: TransactionTrace :: Declare ( trace) => {
22
23
serializer. serialize_field ( "type" , & "DECLARE" ) ?;
23
24
if let Some ( fee_transfer_invocation) = & trace. fee_transfer_invocation {
@@ -120,7 +121,7 @@ impl crate::dto::serialize::SerializeForVersion for TransactionTrace<'_> {
120
121
}
121
122
122
123
#[ derive( Debug ) ]
123
- struct FunctionInvocation < ' a > ( & ' a pathfinder_executor:: types:: FunctionInvocation ) ;
124
+ pub ( crate ) struct FunctionInvocation < ' a > ( & ' a pathfinder_executor:: types:: FunctionInvocation ) ;
124
125
125
126
impl crate :: dto:: serialize:: SerializeForVersion for FunctionInvocation < ' _ > {
126
127
fn serialize (
@@ -519,3 +520,159 @@ impl crate::dto::serialize::SerializeForVersion for ExecuteInvocation<'_> {
519
520
}
520
521
}
521
522
}
523
+
524
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
525
+ pub enum CallType {
526
+ Call ,
527
+ _LibraryCall,
528
+ Delegate ,
529
+ }
530
+
531
+ impl From < pathfinder_executor:: types:: CallType > for CallType {
532
+ fn from ( value : pathfinder_executor:: types:: CallType ) -> Self {
533
+ use pathfinder_executor:: types:: CallType :: * ;
534
+ match value {
535
+ Call => Self :: Call ,
536
+ Delegate => Self :: Delegate ,
537
+ }
538
+ }
539
+ }
540
+
541
+ impl crate :: dto:: serialize:: SerializeForVersion for CallType {
542
+ fn serialize (
543
+ & self ,
544
+ serializer : super :: serialize:: Serializer ,
545
+ ) -> Result < super :: serialize:: Ok , super :: serialize:: Error > {
546
+ match self {
547
+ CallType :: Call => serializer. serialize_str ( "CALL" ) ,
548
+ CallType :: _LibraryCall => serializer. serialize_str ( "LIBRARY_CALL" ) ,
549
+ CallType :: Delegate => serializer. serialize_str ( "DELEGATE" ) ,
550
+ }
551
+ }
552
+ }
553
+
554
+ #[ derive( Debug , Eq , PartialEq ) ]
555
+ pub struct SimulationFlags ( pub Vec < SimulationFlag > ) ;
556
+
557
+ #[ derive( Debug , Eq , PartialEq ) ]
558
+ pub enum SimulationFlag {
559
+ SkipFeeCharge ,
560
+ SkipValidate ,
561
+ }
562
+
563
+ impl crate :: dto:: DeserializeForVersion for SimulationFlag {
564
+ fn deserialize ( value : crate :: dto:: Value ) -> Result < Self , serde_json:: Error > {
565
+ let value: String = value. deserialize_serde ( ) ?;
566
+ match value. as_str ( ) {
567
+ "SKIP_FEE_CHARGE" => Ok ( Self :: SkipFeeCharge ) ,
568
+ "SKIP_VALIDATE" => Ok ( Self :: SkipValidate ) ,
569
+ _ => Err ( serde_json:: Error :: custom ( "Invalid simulation flag" ) ) ,
570
+ }
571
+ }
572
+ }
573
+
574
+ impl crate :: dto:: DeserializeForVersion for SimulationFlags {
575
+ fn deserialize ( value : crate :: dto:: Value ) -> Result < Self , serde_json:: Error > {
576
+ let array = value. deserialize_array ( SimulationFlag :: deserialize) ?;
577
+ Ok ( Self ( array) )
578
+ }
579
+ }
580
+
581
+ pub ( crate ) struct SimulatedTransaction ( pub pathfinder_executor:: types:: TransactionSimulation ) ;
582
+
583
+ impl crate :: dto:: serialize:: SerializeForVersion for SimulatedTransaction {
584
+ fn serialize (
585
+ & self ,
586
+ serializer : super :: serialize:: Serializer ,
587
+ ) -> Result < super :: serialize:: Ok , super :: serialize:: Error > {
588
+ let mut serializer = serializer. serialize_struct ( ) ?;
589
+ serializer. serialize_field ( "fee_estimation" , & FeeEstimate ( & self . 0 . fee_estimation ) ) ?;
590
+ serializer. serialize_field (
591
+ "transaction_trace" ,
592
+ & TransactionTrace {
593
+ trace : self . 0 . trace . clone ( ) ,
594
+ include_state_diff : false ,
595
+ } ,
596
+ ) ?;
597
+ serializer. end ( )
598
+ }
599
+ }
600
+
601
+ #[ cfg( test) ]
602
+ mod tests {
603
+
604
+ use pathfinder_common:: macro_prelude:: * ;
605
+ use pathfinder_common:: {
606
+ felt,
607
+ BlockHeader ,
608
+ BlockId ,
609
+ CallParam ,
610
+ ClassHash ,
611
+ ContractAddress ,
612
+ EntryPoint ,
613
+ StarknetVersion ,
614
+ StorageAddress ,
615
+ StorageValue ,
616
+ TransactionVersion ,
617
+ } ;
618
+ use pathfinder_crypto:: Felt ;
619
+ use pathfinder_storage:: Storage ;
620
+ use starknet_gateway_test_fixtures:: class_definitions:: {
621
+ DUMMY_ACCOUNT_CLASS_HASH ,
622
+ ERC20_CONTRACT_DEFINITION_CLASS_HASH ,
623
+ } ;
624
+
625
+ use crate :: context:: RpcContext ;
626
+ use crate :: dto:: serialize:: { SerializeForVersion , Serializer } ;
627
+ use crate :: dto:: {
628
+ CallType ,
629
+ ComputationResources ,
630
+ ExecutionResources ,
631
+ FeeEstimate ,
632
+ FunctionInvocation ,
633
+ SimulatedTransaction ,
634
+ TransactionTrace ,
635
+ } ;
636
+ use crate :: method:: call:: FunctionCall ;
637
+ use crate :: method:: get_state_update:: types:: { DeployedContract , Nonce , StateDiff } ;
638
+ use crate :: method:: simulate_transactions:: tests:: fixtures;
639
+ use crate :: types:: request:: {
640
+ BroadcastedDeclareTransaction ,
641
+ BroadcastedDeclareTransactionV1 ,
642
+ BroadcastedTransaction ,
643
+ } ;
644
+ use crate :: types:: ContractClass ;
645
+ use crate :: RpcVersion ;
646
+
647
+ pub ( crate ) async fn setup_storage_with_starknet_version (
648
+ version : StarknetVersion ,
649
+ ) -> (
650
+ Storage ,
651
+ BlockHeader ,
652
+ ContractAddress ,
653
+ ContractAddress ,
654
+ StorageValue ,
655
+ ) {
656
+ let test_storage_key = StorageAddress :: from_name ( b"my_storage_var" ) ;
657
+ let test_storage_value = storage_value ! ( "0x09" ) ;
658
+
659
+ // set test storage variable
660
+ let ( storage, last_block_header, account_contract_address, universal_deployer_address) =
661
+ crate :: test_setup:: test_storage ( version, |state_update| {
662
+ state_update. with_storage_update (
663
+ fixtures:: DEPLOYED_CONTRACT_ADDRESS ,
664
+ test_storage_key,
665
+ test_storage_value,
666
+ )
667
+ } )
668
+ . await ;
669
+
670
+ (
671
+ storage,
672
+ last_block_header,
673
+ account_contract_address,
674
+ universal_deployer_address,
675
+ test_storage_value,
676
+ )
677
+ }
678
+ }
0 commit comments