diff --git a/crates/gateway/src/gateway.rs b/crates/gateway/src/gateway.rs index 2edcbbad58..562a7a8ef0 100644 --- a/crates/gateway/src/gateway.rs +++ b/crates/gateway/src/gateway.rs @@ -20,7 +20,6 @@ use crate::rpc_state_reader::RpcStateReaderFactory; use crate::state_reader::StateReaderFactory; use crate::stateful_transaction_validator::StatefulTransactionValidator; use crate::stateless_transaction_validator::StatelessTransactionValidator; -use crate::utils::external_tx_to_thin_tx; #[cfg(test)] #[path = "gateway_test.rs"] @@ -143,8 +142,7 @@ fn process_tx( // TODO(Arni): Add the Sierra and the Casm to the mempool input. Ok(MempoolInput { - tx: (&external_tx_to_thin_tx(&tx, validate_info.tx_hash, validate_info.sender_address)) - .into(), + tx: tx.new_from_rpc_tx(validate_info.tx_hash, validate_info.sender_address), account: Account { sender_address: validate_info.sender_address, state: AccountState { nonce: validate_info.account_nonce }, diff --git a/crates/gateway/src/utils.rs b/crates/gateway/src/utils.rs index 27d3f1fabd..8678112b08 100644 --- a/crates/gateway/src/utils.rs +++ b/crates/gateway/src/utils.rs @@ -6,6 +6,8 @@ use blockifier::transaction::transactions::{ InvokeTransaction as BlockifierInvokeTransaction, }; use starknet_api::core::{calculate_contract_address, ChainId, ClassHash, ContractAddress}; +use starknet_api::data_availability::DataAvailabilityMode; +use starknet_api::executable_transaction::{InvokeTransaction, Transaction}; use starknet_api::rpc_transaction::{ RpcDeclareTransaction, RpcDeployAccountTransaction, @@ -13,33 +15,23 @@ use starknet_api::rpc_transaction::{ RpcTransaction, }; use starknet_api::transaction::{ + AccountDeploymentData, + Calldata, DeclareTransaction, DeclareTransactionV3, DeployAccountTransaction, DeployAccountTransactionV3, - InvokeTransaction, InvokeTransactionV3, + PaymasterData, + ResourceBoundsMapping, TransactionHash, TransactionHasher, + TransactionSignature, }; -use starknet_mempool_types::mempool_types::ThinTransaction; use tracing::error; use crate::errors::{GatewaySpecError, StatefulTransactionValidatorResult}; -pub fn external_tx_to_thin_tx( - external_tx: &RpcTransaction, - tx_hash: TransactionHash, - sender_address: ContractAddress, -) -> ThinTransaction { - ThinTransaction { - tip: *external_tx.tip(), - nonce: *external_tx.nonce(), - sender_address, - tx_hash, - } -} - pub fn external_tx_to_account_tx( external_tx: &RpcTransaction, // FIXME(yael 15/4/24): calculate class_info inside the function once compilation code is ready @@ -114,7 +106,7 @@ pub fn external_tx_to_account_tx( Ok(AccountTransaction::DeployAccount(deploy_account_tx)) } RpcTransaction::Invoke(RpcInvokeTransaction::V3(tx)) => { - let invoke_tx = InvokeTransaction::V3(InvokeTransactionV3 { + let invoke_tx = starknet_api::transaction::InvokeTransaction::V3(InvokeTransactionV3 { resource_bounds: tx.resource_bounds.clone().into(), tip: tx.tip, signature: tx.signature.clone(), @@ -147,7 +139,7 @@ pub fn get_sender_address(tx: &AccountTransaction) -> ContractAddress { }, AccountTransaction::DeployAccount(tx) => tx.contract_address, AccountTransaction::Invoke(tx) => match &tx.tx { - InvokeTransaction::V3(tx) => tx.sender_address, + starknet_api::transaction::InvokeTransaction::V3(tx) => tx.sender_address, _ => panic!("Unsupported transaction version"), }, } diff --git a/crates/starknet_api/src/rpc_transaction.rs b/crates/starknet_api/src/rpc_transaction.rs index b5a34a5e60..1dc989ce1e 100644 --- a/crates/starknet_api/src/rpc_transaction.rs +++ b/crates/starknet_api/src/rpc_transaction.rs @@ -15,6 +15,7 @@ use crate::core::{ Nonce, }; use crate::data_availability::DataAvailabilityMode; +use crate::executable_transaction::Transaction; use crate::state::EntryPoint; use crate::transaction::{ AccountDeploymentData, @@ -24,6 +25,7 @@ use crate::transaction::{ Resource, ResourceBounds, Tip, + TransactionHash, TransactionSignature, }; use crate::StarknetApiError; @@ -82,6 +84,31 @@ impl RpcTransaction { RpcTransaction::Invoke(RpcInvokeTransaction::V3(tx)) => Ok(tx.sender_address), } } + + // TODO(Arni): Update the function to support all transaction types. + pub fn new_from_rpc_tx( + &self, + tx_hash: TransactionHash, + sender_address: ContractAddress, + ) -> Transaction { + Transaction::Invoke(crate::executable_transaction::InvokeTransaction { + tx: crate::transaction::InvokeTransaction::V3( + crate::transaction::InvokeTransactionV3 { + sender_address, + tip: *self.tip(), + nonce: *self.nonce(), + resource_bounds: crate::transaction::ResourceBoundsMapping::default(), + signature: TransactionSignature::default(), + calldata: Calldata::default(), + nonce_data_availability_mode: DataAvailabilityMode::L1, + fee_data_availability_mode: DataAvailabilityMode::L1, + paymaster_data: PaymasterData::default(), + account_deployment_data: AccountDeploymentData::default(), + }, + ), + tx_hash, + }) + } } /// A RPC declare transaction.