@@ -26,6 +26,22 @@ const PREFIX_DEPLOY_ACCOUNT: Felt = Felt::from_raw([
26
26
3350261884043292318 ,
27
27
] ) ;
28
28
29
+ /// 2 ^ 128 + 1
30
+ const QUERY_VERSION_ONE : Felt = Felt :: from_raw ( [
31
+ 576460752142433776 ,
32
+ 18446744073709551584 ,
33
+ 17407 ,
34
+ 18446744073700081633 ,
35
+ ] ) ;
36
+
37
+ /// 2 ^ 128 + 3
38
+ const QUERY_VERSION_THREE : Felt = Felt :: from_raw ( [
39
+ 576460752142432688 ,
40
+ 18446744073709551584 ,
41
+ 17407 ,
42
+ 18446744073700081569 ,
43
+ ] ) ;
44
+
29
45
/// Cairo string for "STARKNET_CONTRACT_ADDRESS"
30
46
const PREFIX_CONTRACT_ADDRESS : Felt = Felt :: from_raw ( [
31
47
533439743893157637 ,
@@ -65,11 +81,13 @@ pub trait AccountFactory: Sized {
65
81
async fn sign_deployment_v1 (
66
82
& self ,
67
83
deployment : & RawAccountDeploymentV1 ,
84
+ query_only : bool ,
68
85
) -> Result < Vec < Felt > , Self :: SignError > ;
69
86
70
87
async fn sign_deployment_v3 (
71
88
& self ,
72
89
deployment : & RawAccountDeploymentV3 ,
90
+ query_only : bool ,
73
91
) -> Result < Vec < Felt > , Self :: SignError > ;
74
92
75
93
fn deploy_v1 ( & self , salt : Felt ) -> AccountDeploymentV1 < Self > {
@@ -404,7 +422,7 @@ where
404
422
} ,
405
423
} ;
406
424
let deploy = prepared
407
- . get_deploy_request ( )
425
+ . get_deploy_request ( true )
408
426
. await
409
427
. map_err ( AccountFactoryError :: Signing ) ?;
410
428
@@ -436,7 +454,7 @@ where
436
454
} ,
437
455
} ;
438
456
let deploy = prepared
439
- . get_deploy_request ( )
457
+ . get_deploy_request ( true )
440
458
. await
441
459
. map_err ( AccountFactoryError :: Signing ) ?;
442
460
@@ -637,7 +655,7 @@ where
637
655
} ,
638
656
} ;
639
657
let deploy = prepared
640
- . get_deploy_request ( )
658
+ . get_deploy_request ( true )
641
659
. await
642
660
. map_err ( AccountFactoryError :: Signing ) ?;
643
661
@@ -670,7 +688,7 @@ where
670
688
} ,
671
689
} ;
672
690
let deploy = prepared
673
- . get_deploy_request ( )
691
+ . get_deploy_request ( true )
674
692
. await
675
693
. map_err ( AccountFactoryError :: Signing ) ?;
676
694
@@ -760,13 +778,17 @@ where
760
778
)
761
779
}
762
780
763
- pub fn transaction_hash ( & self ) -> Felt {
781
+ pub fn transaction_hash ( & self , query_only : bool ) -> Felt {
764
782
let mut calldata_to_hash = vec ! [ self . factory. class_hash( ) , self . inner. salt] ;
765
783
calldata_to_hash. append ( & mut self . factory . calldata ( ) ) ;
766
784
767
785
compute_hash_on_elements ( & [
768
786
PREFIX_DEPLOY_ACCOUNT ,
769
- Felt :: ONE , // version
787
+ if query_only {
788
+ QUERY_VERSION_ONE
789
+ } else {
790
+ Felt :: ONE
791
+ } , // version
770
792
self . address ( ) ,
771
793
Felt :: ZERO , // entry_point_selector
772
794
compute_hash_on_elements ( & calldata_to_hash) ,
@@ -780,7 +802,7 @@ where
780
802
& self ,
781
803
) -> Result < DeployAccountTransactionResult , AccountFactoryError < F :: SignError > > {
782
804
let tx_request = self
783
- . get_deploy_request ( )
805
+ . get_deploy_request ( false )
784
806
. await
785
807
. map_err ( AccountFactoryError :: Signing ) ?;
786
808
self . factory
@@ -792,8 +814,12 @@ where
792
814
793
815
async fn get_deploy_request (
794
816
& self ,
817
+ query_only : bool ,
795
818
) -> Result < BroadcastedDeployAccountTransactionV1 , F :: SignError > {
796
- let signature = self . factory . sign_deployment_v1 ( & self . inner ) . await ?;
819
+ let signature = self
820
+ . factory
821
+ . sign_deployment_v1 ( & self . inner , query_only)
822
+ . await ?;
797
823
798
824
Ok ( BroadcastedDeployAccountTransactionV1 {
799
825
max_fee : self . inner . max_fee ,
@@ -802,8 +828,7 @@ where
802
828
contract_address_salt : self . inner . salt ,
803
829
constructor_calldata : self . factory . calldata ( ) ,
804
830
class_hash : self . factory . class_hash ( ) ,
805
- // TODO: make use of query version tx for estimating fees
806
- is_query : false ,
831
+ is_query : query_only,
807
832
} )
808
833
}
809
834
}
@@ -821,11 +846,15 @@ where
821
846
)
822
847
}
823
848
824
- pub fn transaction_hash ( & self ) -> Felt {
849
+ pub fn transaction_hash ( & self , query_only : bool ) -> Felt {
825
850
let mut hasher = PoseidonHasher :: new ( ) ;
826
851
827
852
hasher. update ( PREFIX_DEPLOY_ACCOUNT ) ;
828
- hasher. update ( Felt :: THREE ) ;
853
+ hasher. update ( if query_only {
854
+ QUERY_VERSION_THREE
855
+ } else {
856
+ Felt :: THREE
857
+ } ) ;
829
858
hasher. update ( self . address ( ) ) ;
830
859
831
860
hasher. update ( {
@@ -882,7 +911,7 @@ where
882
911
& self ,
883
912
) -> Result < DeployAccountTransactionResult , AccountFactoryError < F :: SignError > > {
884
913
let tx_request = self
885
- . get_deploy_request ( )
914
+ . get_deploy_request ( false )
886
915
. await
887
916
. map_err ( AccountFactoryError :: Signing ) ?;
888
917
self . factory
@@ -894,8 +923,12 @@ where
894
923
895
924
async fn get_deploy_request (
896
925
& self ,
926
+ query_only : bool ,
897
927
) -> Result < BroadcastedDeployAccountTransactionV3 , F :: SignError > {
898
- let signature = self . factory . sign_deployment_v3 ( & self . inner ) . await ?;
928
+ let signature = self
929
+ . factory
930
+ . sign_deployment_v3 ( & self . inner , query_only)
931
+ . await ?;
899
932
900
933
Ok ( BroadcastedDeployAccountTransactionV3 {
901
934
signature,
@@ -921,8 +954,7 @@ where
921
954
// Hard-coded L1 DA mode for nonce and fee
922
955
nonce_data_availability_mode : DataAvailabilityMode :: L1 ,
923
956
fee_data_availability_mode : DataAvailabilityMode :: L1 ,
924
- // TODO: make use of query version tx for estimating fees
925
- is_query : false ,
957
+ is_query : query_only,
926
958
} )
927
959
}
928
960
}
0 commit comments