diff --git a/crates/blockifier/src/blockifier/stateful_validator_test.rs b/crates/blockifier/src/blockifier/stateful_validator_test.rs index dc1fd08cc3..de72c664e5 100644 --- a/crates/blockifier/src/blockifier/stateful_validator_test.rs +++ b/crates/blockifier/src/blockifier/stateful_validator_test.rs @@ -63,7 +63,7 @@ fn test_transaction_validator( ..transaction_args }); if let AccountTransaction::DeployAccount(deploy_tx) = &tx { - fund_account(chain_info, deploy_tx.contract_address, BALANCE, &mut state.state); + fund_account(chain_info, deploy_tx.contract_address(), BALANCE, &mut state.state); } // Test the stateful validator. diff --git a/crates/blockifier/src/concurrency/versioned_state_test.rs b/crates/blockifier/src/concurrency/versioned_state_test.rs index 79cac9ee12..a453153421 100644 --- a/crates/blockifier/src/concurrency/versioned_state_test.rs +++ b/crates/blockifier/src/concurrency/versioned_state_test.rs @@ -246,7 +246,7 @@ fn test_run_parallel_txs(max_resource_bounds: ResourceBoundsMapping) { }; let nonce_manager = &mut NonceManager::default(); let deploy_account_tx_2 = deploy_account_tx(deploy_tx_args, nonce_manager); - let account_address = deploy_account_tx_2.contract_address; + let account_address = deploy_account_tx_2.contract_address(); let account_tx_2 = AccountTransaction::DeployAccount(deploy_account_tx_2); let tx_context = block_context.to_tx_context(&account_tx_2); let fee_type = tx_context.tx_info.fee_type(); diff --git a/crates/blockifier/src/execution/stack_trace_test.rs b/crates/blockifier/src/execution/stack_trace_test.rs index 6aa7523507..73f6c887be 100644 --- a/crates/blockifier/src/execution/stack_trace_test.rs +++ b/crates/blockifier/src/execution/stack_trace_test.rs @@ -491,7 +491,7 @@ fn test_validate_trace( // Deploy account uses the actual address as the sender address. match &account_tx { AccountTransaction::DeployAccount(tx) => { - sender_address = tx.contract_address; + sender_address = tx.contract_address(); } _ => panic!("Expected DeployAccountTransaction type"), } @@ -558,7 +558,7 @@ fn test_account_ctor_frame_stack_trace( // Fund the account so it can afford the deployment. let deploy_address = match &deploy_account_tx { - AccountTransaction::DeployAccount(deploy_tx) => deploy_tx.contract_address, + AccountTransaction::DeployAccount(deploy_tx) => deploy_tx.contract_address(), _ => unreachable!("deploy_account_tx is a DeployAccount"), }; fund_account(chain_info, deploy_address, BALANCE * 2, &mut state.state); diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index 3f48297d15..4054c028d2 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -599,7 +599,7 @@ fn test_fail_deploy_account( let fee_token_address = chain_info.fee_token_address(&deploy_account_tx.fee_type()); let deploy_address = match &deploy_account_tx { - AccountTransaction::DeployAccount(deploy_tx) => deploy_tx.contract_address, + AccountTransaction::DeployAccount(deploy_tx) => deploy_tx.contract_address(), _ => unreachable!("deploy_account_tx is a DeployAccount"), }; fund_account(chain_info, deploy_address, BALANCE * 2, &mut state.state); diff --git a/crates/blockifier/src/transaction/test_utils.rs b/crates/blockifier/src/transaction/test_utils.rs index d6b1724e3a..72d400157f 100644 --- a/crates/blockifier/src/transaction/test_utils.rs +++ b/crates/blockifier/src/transaction/test_utils.rs @@ -109,7 +109,7 @@ pub fn deploy_and_fund_account( ) -> (AccountTransaction, ContractAddress) { // Deploy an account contract. let deploy_account_tx = deploy_account_tx(deploy_tx_args, nonce_manager); - let account_address = deploy_account_tx.contract_address; + let account_address = deploy_account_tx.contract_address(); let account_tx = AccountTransaction::DeployAccount(deploy_account_tx); // Update the balance of the about-to-be deployed account contract in the erc20 contract, so it diff --git a/crates/blockifier/src/transaction/transactions.rs b/crates/blockifier/src/transaction/transactions.rs index 262acbb657..947182cd88 100644 --- a/crates/blockifier/src/transaction/transactions.rs +++ b/crates/blockifier/src/transaction/transactions.rs @@ -309,9 +309,7 @@ impl TransactionInfoCreator for DeclareTransaction { } #[derive(Debug, Clone)] pub struct DeployAccountTransaction { - pub tx: starknet_api::transaction::DeployAccountTransaction, - pub tx_hash: TransactionHash, - pub contract_address: ContractAddress, + pub tx: starknet_api::executable_transaction::DeployAccountTransaction, // Indicates the presence of the only_query bit in the version. pub only_query: bool, } @@ -322,7 +320,14 @@ impl DeployAccountTransaction { tx_hash: TransactionHash, contract_address: ContractAddress, ) -> Self { - Self { tx: deploy_account_tx, tx_hash, contract_address, only_query: false } + Self { + tx: starknet_api::executable_transaction::DeployAccountTransaction { + tx: deploy_account_tx, + tx_hash, + contract_address, + }, + only_query: false, + } } pub fn new_for_query( @@ -330,24 +335,29 @@ impl DeployAccountTransaction { tx_hash: TransactionHash, contract_address: ContractAddress, ) -> Self { - Self { tx: deploy_account_tx, tx_hash, contract_address, only_query: true } + Self { + tx: starknet_api::executable_transaction::DeployAccountTransaction { + tx: deploy_account_tx, + tx_hash, + contract_address, + }, + only_query: true, + } } implement_inner_tx_getter_calls!( (class_hash, ClassHash), (constructor_calldata, Calldata), + (contract_address, ContractAddress), (contract_address_salt, ContractAddressSalt), (nonce, Nonce), (signature, TransactionSignature), + (tx_hash, TransactionHash), (version, TransactionVersion) ); pub fn tx(&self) -> &starknet_api::transaction::DeployAccountTransaction { - &self.tx - } - - pub fn tx_hash(&self) -> TransactionHash { - self.tx_hash + self.tx.tx() } } @@ -363,7 +373,7 @@ impl Executable for DeployAccountTransaction { let ctor_context = ConstructorContext { class_hash, code_address: None, - storage_address: self.contract_address, + storage_address: self.contract_address(), caller_address: ContractAddress::default(), }; let call_info = execute_deployment( @@ -387,11 +397,11 @@ impl TransactionInfoCreator for DeployAccountTransaction { version: self.version(), signature: self.signature(), nonce: self.nonce(), - sender_address: self.contract_address, + sender_address: self.contract_address(), only_query: self.only_query, }; - match &self.tx { + match &self.tx() { starknet_api::transaction::DeployAccountTransaction::V1(tx) => { TransactionInfo::Deprecated(DeprecatedTransactionInfo { common_fields, diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index a8198cfa9b..ba19708ece 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -1304,7 +1304,7 @@ fn test_deploy_account_tx( // Extract deploy account transaction fields for testing, as it is consumed when creating an // account transaction. let class_hash = deploy_account.class_hash(); - let deployed_account_address = deploy_account.contract_address; + let deployed_account_address = deploy_account.contract_address(); let constructor_calldata = deploy_account.constructor_calldata(); let salt = deploy_account.contract_address_salt(); @@ -1472,7 +1472,7 @@ fn test_fail_deploy_account_undeclared_class_hash( state .set_storage_at( chain_info.fee_token_address(&fee_type), - get_fee_token_var_address(deploy_account.contract_address), + get_fee_token_var_address(deploy_account.contract_address()), felt!(BALANCE), ) .unwrap(); diff --git a/crates/gateway/src/utils.rs b/crates/gateway/src/utils.rs index 27d3f1fabd..92925ef228 100644 --- a/crates/gateway/src/utils.rs +++ b/crates/gateway/src/utils.rs @@ -145,7 +145,7 @@ pub fn get_sender_address(tx: &AccountTransaction) -> ContractAddress { DeclareTransaction::V3(tx) => tx.sender_address, _ => panic!("Unsupported transaction version"), }, - AccountTransaction::DeployAccount(tx) => tx.contract_address, + AccountTransaction::DeployAccount(tx) => tx.contract_address(), AccountTransaction::Invoke(tx) => match &tx.tx { InvokeTransaction::V3(tx) => tx.sender_address, _ => panic!("Unsupported transaction version"), diff --git a/crates/starknet_api/src/executable_transaction.rs b/crates/starknet_api/src/executable_transaction.rs index 3b65f39a9f..364cf67a44 100644 --- a/crates/starknet_api/src/executable_transaction.rs +++ b/crates/starknet_api/src/executable_transaction.rs @@ -1,8 +1,31 @@ use serde::{Deserialize, Serialize}; use crate::contract_class::ClassInfo; -use crate::core::{ContractAddress, Nonce}; -use crate::transaction::{Tip, TransactionHash}; +use crate::core::{ClassHash, ContractAddress, Nonce}; +use crate::transaction::{ + Calldata, + ContractAddressSalt, + Tip, + TransactionHash, + TransactionSignature, + TransactionVersion, +}; + +macro_rules! implement_inner_tx_getter_calls { + ($(($field:ident, $field_type:ty)),*) => { + $(pub fn $field(&self) -> $field_type { + self.tx.$field().clone() + })* + }; +} + +macro_rules! implement_getter_calls { + ($(($field:ident, $field_type:ty)),*) => { + $(pub fn $field(&self) -> $field_type { + self.$field + })* + }; +} /// Represents a paid Starknet transaction. #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] @@ -70,6 +93,22 @@ pub struct DeployAccountTransaction { pub contract_address: ContractAddress, } +impl DeployAccountTransaction { + implement_inner_tx_getter_calls!( + (class_hash, ClassHash), + (constructor_calldata, Calldata), + (contract_address_salt, ContractAddressSalt), + (nonce, Nonce), + (signature, TransactionSignature), + (version, TransactionVersion) + ); + implement_getter_calls!((tx_hash, TransactionHash), (contract_address, ContractAddress)); + + pub fn tx(&self) -> &crate::transaction::DeployAccountTransaction { + &self.tx + } +} + #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] pub struct InvokeTransaction { pub tx: crate::transaction::InvokeTransaction,