From decc9f81c09326730a8f9869588405c0db63a0e6 Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Tue, 23 Jul 2024 14:57:45 +0300 Subject: [PATCH] chore: refactor invoke as wrapper --- .../src/transaction/account_transaction.rs | 2 +- .../src/transaction/transactions.rs | 29 +++++++++++-------- crates/gateway/src/utils.rs | 2 +- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index c9c3da780b..13175168c1 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -75,7 +75,7 @@ impl HasRelatedFeeType for AccountTransaction { match self { Self::Declare(tx) => tx.tx.version(), Self::DeployAccount(tx) => tx.tx.tx.version(), - Self::Invoke(tx) => match tx.tx { + Self::Invoke(tx) => match tx.tx.tx { starknet_api::transaction::InvokeTransaction::V0(_) => TransactionVersion::ZERO, starknet_api::transaction::InvokeTransaction::V1(_) => TransactionVersion::ONE, starknet_api::transaction::InvokeTransaction::V3(_) => TransactionVersion::THREE, diff --git a/crates/blockifier/src/transaction/transactions.rs b/crates/blockifier/src/transaction/transactions.rs index 72aa5ea01d..95e08a30c7 100644 --- a/crates/blockifier/src/transaction/transactions.rs +++ b/crates/blockifier/src/transaction/transactions.rs @@ -403,8 +403,7 @@ impl TransactionInfoCreator for DeployAccountTransaction { #[derive(Debug, Clone)] pub struct InvokeTransaction { - pub tx: starknet_api::transaction::InvokeTransaction, - pub tx_hash: TransactionHash, + pub tx: starknet_api::executable_transaction::InvokeTransaction, // Indicates the presence of the only_query bit in the version. pub only_query: bool, } @@ -414,17 +413,23 @@ impl InvokeTransaction { invoke_tx: starknet_api::transaction::InvokeTransaction, tx_hash: TransactionHash, ) -> Self { - Self { tx: invoke_tx, tx_hash, only_query: false } + Self { + tx: starknet_api::executable_transaction::InvokeTransaction { tx: invoke_tx, tx_hash }, + only_query: false, + } } pub fn new_for_query( invoke_tx: starknet_api::transaction::InvokeTransaction, tx_hash: TransactionHash, ) -> Self { - Self { tx: invoke_tx, tx_hash, only_query: true } + Self { + tx: starknet_api::executable_transaction::InvokeTransaction { tx: invoke_tx, tx_hash }, + only_query: true, + } } - implement_inner_tx_getter_calls!( + implement_wrapped_inner_tx_getter_calls!( (calldata, Calldata), (signature, TransactionSignature), (sender_address, ContractAddress) @@ -439,7 +444,7 @@ impl Executable for InvokeTransaction { context: &mut EntryPointExecutionContext, remaining_gas: &mut u64, ) -> TransactionExecutionResult> { - let entry_point_selector = match &self.tx { + let entry_point_selector = match &self.tx.tx { starknet_api::transaction::InvokeTransaction::V0(tx) => tx.entry_point_selector, starknet_api::transaction::InvokeTransaction::V1(_) | starknet_api::transaction::InvokeTransaction::V3(_) => { @@ -477,15 +482,15 @@ impl Executable for InvokeTransaction { impl TransactionInfoCreator for InvokeTransaction { fn create_tx_info(&self) -> TransactionInfo { let common_fields = CommonAccountFields { - transaction_hash: self.tx_hash, - version: self.tx.version(), - signature: self.tx.signature(), - nonce: self.tx.nonce(), - sender_address: self.tx.sender_address(), + transaction_hash: self.tx.tx_hash, + version: self.tx.tx.version(), + signature: self.tx.tx.signature(), + nonce: self.tx.tx.nonce(), + sender_address: self.tx.tx.sender_address(), only_query: self.only_query, }; - match &self.tx { + match &self.tx.tx { starknet_api::transaction::InvokeTransaction::V0(tx) => { TransactionInfo::Deprecated(DeprecatedTransactionInfo { common_fields, diff --git a/crates/gateway/src/utils.rs b/crates/gateway/src/utils.rs index 5cb7fb3b99..41dd4e2cac 100644 --- a/crates/gateway/src/utils.rs +++ b/crates/gateway/src/utils.rs @@ -163,6 +163,6 @@ pub fn get_tx_hash(tx: &AccountTransaction) -> TransactionHash { match tx { AccountTransaction::Declare(tx) => tx.tx_hash, AccountTransaction::DeployAccount(tx) => tx.tx.tx_hash, - AccountTransaction::Invoke(tx) => tx.tx_hash, + AccountTransaction::Invoke(tx) => tx.tx.tx_hash, } }