Skip to content

Commit

Permalink
chore(blockifier): consider slightly different implementation of acco…
Browse files Browse the repository at this point in the history
…unt tx getters
  • Loading branch information
avivg-starkware committed Nov 17, 2024
1 parent fae60a0 commit 22d25b7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 48 deletions.
46 changes: 8 additions & 38 deletions crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,10 @@ pub struct AccountTransaction {
only_query: bool,
}

macro_rules! implement_tx_getter_calls {
($(($field:ident, $field_type:ty)),*) => {
$(pub fn $field(&self) -> $field_type {
self.tx.$field()
})*
};
}

macro_rules! implement_account_tx_inner_getters {
($(($field:ident, $field_type:ty)),*) => {
$(pub fn $field(&self) -> $field_type {
match &self.tx {
// TODO(AvivG): Consider moving some of the logic to the Transaction enum.
Transaction::Declare(tx) => tx.tx.$field().clone(),
Transaction::DeployAccount(tx) => tx.tx.$field().clone(),
Transaction::Invoke(tx) => tx.tx.$field().clone(),
}
self.tx.$field()
})*
};
}
Expand Down Expand Up @@ -138,12 +125,7 @@ impl From<InvokeTransaction> for AccountTransaction {

impl HasRelatedFeeType for AccountTransaction {
fn version(&self) -> TransactionVersion {
// TODO(AvivG): Consider moving some of the logic to the Transaction enum.
match &self.tx {
Transaction::Declare(tx) => tx.tx.version(),
Transaction::DeployAccount(tx) => tx.tx.version(),
Transaction::Invoke(tx) => tx.tx.version(),
}
self.tx.version()
}

fn is_l1_handler(&self) -> bool {
Expand All @@ -157,11 +139,13 @@ impl AccountTransaction {
(nonce, Nonce),
(nonce_data_availability_mode, DataAvailabilityMode),
(fee_data_availability_mode, DataAvailabilityMode),
(paymaster_data, PaymasterData)
(paymaster_data, PaymasterData),
(sender_address, ContractAddress),
(tx_hash, TransactionHash),
(resource_bounds, ValidResourceBounds),
(tip, Tip)
);

implement_tx_getter_calls!((resource_bounds, ValidResourceBounds), (tip, Tip));

pub fn new(tx: starknet_api::executable_transaction::AccountTransaction) -> Self {
AccountTransaction { tx, only_query: false }
}
Expand All @@ -170,10 +154,6 @@ impl AccountTransaction {
AccountTransaction { tx, only_query: true }
}

pub fn sender_address(&self) -> ContractAddress {
self.tx.sender_address()
}

pub fn class_hash(&self) -> Option<ClassHash> {
match &self.tx {
Transaction::Declare(tx) => Some(tx.tx.class_hash()),
Expand Down Expand Up @@ -237,17 +217,7 @@ impl AccountTransaction {
}

pub fn signature_length(&self) -> usize {
let signature = match &self.tx {
Transaction::Declare(tx) => tx.signature(),
Transaction::DeployAccount(tx) => tx.signature(),
Transaction::Invoke(tx) => tx.signature(),
};

signature.0.len()
}

pub fn tx_hash(&self) -> TransactionHash {
self.tx.tx_hash()
self.signature().0.len()
}

pub fn enforce_fee(&self) -> bool {
Expand Down
27 changes: 17 additions & 10 deletions crates/starknet_api/src/executable_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ pub enum AccountTransaction {
}

impl AccountTransaction {
implement_account_tx_inner_getters!((resource_bounds, ValidResourceBounds), (tip, Tip));
implement_account_tx_inner_getters!(
(signature, TransactionSignature),
(nonce, Nonce),
(resource_bounds, ValidResourceBounds),
(tip, Tip),
(nonce_data_availability_mode, DataAvailabilityMode),
(fee_data_availability_mode, DataAvailabilityMode),
(paymaster_data, PaymasterData),
(version, TransactionVersion)
);

pub fn contract_address(&self) -> ContractAddress {
match self {
Expand All @@ -74,14 +83,6 @@ impl AccountTransaction {
self.contract_address()
}

pub fn nonce(&self) -> Nonce {
match self {
AccountTransaction::Declare(tx_data) => tx_data.tx.nonce(),
AccountTransaction::DeployAccount(tx_data) => tx_data.tx.nonce(),
AccountTransaction::Invoke(tx_data) => tx_data.tx.nonce(),
}
}

pub fn tx_hash(&self) -> TransactionHash {
match self {
AccountTransaction::Declare(tx_data) => tx_data.tx_hash,
Expand Down Expand Up @@ -151,8 +152,14 @@ impl DeclareTransaction {
(nonce, Nonce),
(sender_address, ContractAddress),
(signature, TransactionSignature),
(version, TransactionVersion)
(version, TransactionVersion),
(resource_bounds, ValidResourceBounds),
(tip, Tip),
(nonce_data_availability_mode, DataAvailabilityMode),
(fee_data_availability_mode, DataAvailabilityMode),
(paymaster_data, PaymasterData)
);
implement_getter_calls!((tx_hash, TransactionHash));

pub fn create(
declare_tx: crate::transaction::DeclareTransaction,
Expand Down

0 comments on commit 22d25b7

Please sign in to comment.