From a5eda93daf0f7b6c36358e82d663044a5eab47a9 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/transactions.rs | 36 ++++++++++++------- crates/gateway/src/utils.rs | 2 +- .../src/executable_transaction.rs | 18 ++++++++++ 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/crates/blockifier/src/transaction/transactions.rs b/crates/blockifier/src/transaction/transactions.rs index d8b78ef94dd..7dbb2cc2242 100644 --- a/crates/blockifier/src/transaction/transactions.rs +++ b/crates/blockifier/src/transaction/transactions.rs @@ -398,8 +398,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, } @@ -409,21 +408,34 @@ 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!( (calldata, Calldata), + (nonce, Nonce), (signature, TransactionSignature), - (sender_address, ContractAddress) + (sender_address, ContractAddress), + (tx_hash, TransactionHash), + (version, TransactionVersion) ); + + pub fn tx(&self) -> &starknet_api::transaction::InvokeTransaction { + self.tx.tx() + } } impl Executable for InvokeTransaction { @@ -434,7 +446,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(_) => { @@ -472,15 +484,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_hash(), + version: self.version(), + signature: self.signature(), + nonce: self.nonce(), + sender_address: self.sender_address(), only_query: self.only_query, }; - match &self.tx { + match &self.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 1f50a9a6cd5..bd4c6b34a54 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_hash(), - AccountTransaction::Invoke(tx) => tx.tx_hash, + AccountTransaction::Invoke(tx) => tx.tx_hash(), } } diff --git a/crates/starknet_api/src/executable_transaction.rs b/crates/starknet_api/src/executable_transaction.rs index 2eb976b4a5e..6bbe8a421a0 100644 --- a/crates/starknet_api/src/executable_transaction.rs +++ b/crates/starknet_api/src/executable_transaction.rs @@ -112,6 +112,24 @@ pub struct InvokeTransaction { pub tx_hash: TransactionHash, } +impl InvokeTransaction { + implement_inner_tx_getter_calls!( + (calldata, Calldata), + (nonce, Nonce), + (signature, TransactionSignature), + (sender_address, ContractAddress), + (version, TransactionVersion) + ); + + pub fn tx(&self) -> &crate::transaction::InvokeTransaction { + &self.tx + } + + pub fn tx_hash(&self) -> TransactionHash { + self.tx_hash + } +} + #[derive(Clone, Debug, Eq, PartialEq)] pub struct ClassInfo { // TODO: use compiled contract class.