From 53e4b844e1bcf40314f3aaf2c1089ccd44e7e15a 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 | 20 ++++++++++++++++++- .../src/transaction/transaction_execution.rs | 7 +++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index 28cd17aa68..b6010c22ba 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,11 @@ impl HasRelatedFeeType for AccountTransaction { } impl AccountTransaction { + implement_account_tx_inner_getters!( + (signature, TransactionSignature), + (nonce, Nonce) + ); + // 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 {