From e90a2752f2b6a11b41df4b6f0275008c82e2c088 Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Wed, 31 Jul 2024 15:09:14 +0300 Subject: [PATCH] chore: refactor deploy account as wrapper --- .../src/transaction/account_transaction.rs | 2 +- .../src/transaction/transactions.rs | 33 +++++++++++++++---- .../src/executable_transaction.rs | 8 +++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index 14fa0ed929..351cd3eedd 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -74,7 +74,7 @@ impl HasRelatedFeeType for AccountTransaction { fn version(&self) -> TransactionVersion { match self { Self::Declare(tx) => tx.tx.version(), - Self::DeployAccount(tx) => tx.tx.version(), + Self::DeployAccount(tx) => tx.version(), Self::Invoke(tx) => match tx.tx { starknet_api::transaction::InvokeTransaction::V0(_) => TransactionVersion::ZERO, starknet_api::transaction::InvokeTransaction::V1(_) => TransactionVersion::ONE, diff --git a/crates/blockifier/src/transaction/transactions.rs b/crates/blockifier/src/transaction/transactions.rs index 834660c740..bed31976f8 100644 --- a/crates/blockifier/src/transaction/transactions.rs +++ b/crates/blockifier/src/transaction/transactions.rs @@ -1,3 +1,4 @@ +use std::ops::Deref; use std::sync::Arc; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; @@ -282,20 +283,33 @@ 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, } +impl Deref for DeployAccountTransaction { + type Target = starknet_api::executable_transaction::DeployAccountTransaction; + + fn deref(&self) -> &Self::Target { + &self.tx + } +} + impl DeployAccountTransaction { pub fn new( deploy_account_tx: starknet_api::transaction::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( @@ -303,7 +317,14 @@ 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!( @@ -359,7 +380,7 @@ impl TransactionInfoCreator for DeployAccountTransaction { only_query: self.only_query, }; - match &self.tx { + match &self.tx.tx { starknet_api::transaction::DeployAccountTransaction::V1(tx) => { TransactionInfo::Deprecated(DeprecatedTransactionInfo { common_fields, diff --git a/crates/starknet_api/src/executable_transaction.rs b/crates/starknet_api/src/executable_transaction.rs index 40ac70a97a..357d11ed7f 100644 --- a/crates/starknet_api/src/executable_transaction.rs +++ b/crates/starknet_api/src/executable_transaction.rs @@ -68,6 +68,14 @@ pub struct DeployAccountTransaction { pub contract_address: ContractAddress, } +impl std::ops::Deref for DeployAccountTransaction { + type Target = crate::transaction::DeployAccountTransaction; + + fn deref(&self) -> &Self::Target { + &self.tx + } +} + #[derive(Clone, Debug, Eq, PartialEq)] pub struct InvokeTransaction { pub tx: crate::transaction::InvokeTransaction,