From e18369d9594b5bf53c13042cbe7e2ab6ded40f92 Mon Sep 17 00:00:00 2001 From: meship-starkware Date: Tue, 3 Sep 2024 13:17:04 +0300 Subject: [PATCH] refactor(blockifier): add getter for tx_hash to transaction --- .../src/transaction/account_transaction.rs | 25 ++++++++++++++++++- .../src/transaction/transaction_execution.rs | 7 ++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index 28cd17aa68..ef28f69c17 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -2,13 +2,14 @@ use std::sync::Arc; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use starknet_api::calldata; -use starknet_api::core::{ContractAddress, EntryPointSelector}; +use starknet_api::core::{ContractAddress, EntryPointSelector, Nonce}; use starknet_api::deprecated_contract_class::EntryPointType; use starknet_api::transaction::{ Calldata, Fee, ResourceBounds, TransactionHash, + TransactionSignature, TransactionVersion, }; use starknet_types_core::felt::Felt; @@ -77,6 +78,18 @@ pub enum AccountTransaction { Invoke(InvokeTransaction), } +macro_rules! implement_account_tx_inner_getters { + ($(($field:ident, $field_type:ty)),*) => { + $(pub fn $field(&self) -> $field_type { + match self { + Self::Declare(tx) => tx.tx.$field().clone(), + Self::DeployAccount(tx) => tx.tx.$field().clone(), + Self::Invoke(tx) => tx.tx.$field().clone(), + } + })* + }; +} + impl TryFrom for AccountTransaction { type Error = TransactionExecutionError; @@ -115,6 +128,16 @@ impl HasRelatedFeeType for AccountTransaction { } impl AccountTransaction { + implement_account_tx_inner_getters!((signature, TransactionSignature), (nonce, Nonce)); + + pub fn sender_address(&self) -> ContractAddress { + match self { + Self::Declare(tx) => tx.tx.sender_address(), + Self::DeployAccount(tx) => tx.tx.contract_address(), + Self::Invoke(tx) => tx.tx.sender_address(), + } + } + // TODO(nir, 01/11/2023): Consider instantiating CommonAccountFields in AccountTransaction. pub fn tx_type(&self) -> TransactionType { match self { diff --git a/crates/blockifier/src/transaction/transaction_execution.rs b/crates/blockifier/src/transaction/transaction_execution.rs index f11915267b..bece1ca8b5 100644 --- a/crates/blockifier/src/transaction/transaction_execution.rs +++ b/crates/blockifier/src/transaction/transaction_execution.rs @@ -97,6 +97,13 @@ impl Transaction { _ => unimplemented!(), } } + + pub fn tx_hash(tx: &Transaction) -> TransactionHash { + match tx { + Transaction::AccountTransaction(tx) => tx.tx_hash(), + Transaction::L1HandlerTransaction(tx) => tx.tx_hash, + } + } } impl TransactionInfoCreator for Transaction {