Skip to content

Commit

Permalink
refactor(blockifier): add getter for tx_hash to transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
meship-starkware committed Sep 3, 2024
1 parent 5c782b6 commit 53e4b84
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
20 changes: 19 additions & 1 deletion crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<starknet_api::executable_transaction::Transaction> for AccountTransaction {
type Error = TransactionExecutionError;

Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions crates/blockifier/src/transaction/transaction_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 53e4b84

Please sign in to comment.