Skip to content

Commit

Permalink
chore: refactor deploy account as wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Jul 31, 2024
1 parent c859c5e commit e90a275
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 27 additions & 6 deletions crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::ops::Deref;
use std::sync::Arc;

use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
Expand Down Expand Up @@ -282,28 +283,48 @@ 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(
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: true }
Self {
tx: starknet_api::executable_transaction::DeployAccountTransaction {
tx: deploy_account_tx,
tx_hash,
contract_address,
},
only_query: true,
}
}

implement_inner_tx_getter_calls!(
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions crates/starknet_api/src/executable_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e90a275

Please sign in to comment.