@@ -5,11 +5,12 @@ use starknet::providers::sequencer::models::{
55} ;
66
77use crate :: block:: { FinalityStatus , GasPrices , Header , SealedBlock , SealedBlockWithStatus } ;
8- use crate :: da:: L1DataAvailabilityMode ;
8+ use crate :: da:: { DataAvailabilityMode , L1DataAvailabilityMode } ;
99use crate :: state:: StateUpdates ;
10- use crate :: transaction:: TxWithHash ;
10+ use crate :: transaction:: { InvokeTx , InvokeTxV1 , InvokeTxV3 , Tx , TxWithHash } ;
1111use crate :: version:: ProtocolVersion ;
1212use crate :: ContractAddress ;
13+ use crate :: Felt ;
1314
1415impl From < FgwBlock > for SealedBlockWithStatus {
1516 fn from ( value : FgwBlock ) -> Self {
@@ -109,8 +110,37 @@ impl From<ResourcePrice> for GasPrices {
109110 }
110111}
111112
112- impl From < InvokeFunctionTransaction > for TxWithHash {
113- fn from ( value : InvokeFunctionTransaction ) -> Self {
114- todo ! ( )
113+ impl TryFrom < InvokeFunctionTransaction > for TxWithHash {
114+ type Error = ( ) ;
115+
116+ fn try_from ( value : InvokeFunctionTransaction ) -> Result < Self , Self :: Error > {
117+ let tx = if value. version == Felt :: ONE {
118+ InvokeTx :: V1 ( InvokeTxV1 {
119+ chain_id : Default :: default ( ) ,
120+ sender_address : value. sender_address . into ( ) ,
121+ nonce : value. nonce . unwrap_or_default ( ) ,
122+ calldata : value. calldata ,
123+ signature : value. signature ,
124+ max_fee : value. max_fee . and_then ( |f| f. to_u128 ( ) ) . unwrap_or_default ( ) ,
125+ } )
126+ } else if value. version == Felt :: THREE {
127+ InvokeTx :: V3 ( InvokeTxV3 {
128+ chain_id : Default :: default ( ) ,
129+ sender_address : value. sender_address . into ( ) ,
130+ nonce : value. nonce . unwrap_or_default ( ) ,
131+ calldata : value. calldata ,
132+ signature : value. signature ,
133+ resource_bounds : Default :: default ( ) ,
134+ tip : value. tip . unwrap_or_default ( ) ,
135+ paymaster_data : value. paymaster_data . unwrap_or_default ( ) ,
136+ account_deployment_data : value. account_deployment_data . unwrap_or_default ( ) ,
137+ nonce_data_availability_mode : DataAvailabilityMode :: L1 ,
138+ fee_data_availability_mode : DataAvailabilityMode :: L1 ,
139+ } )
140+ } else {
141+ panic ! ( "Unsupported invoke transaction version" )
142+ } ;
143+
144+ Ok ( TxWithHash { hash : value. transaction_hash . into ( ) , transaction : Tx :: Invoke ( tx) } )
115145 }
116146}
0 commit comments