Skip to content

Commit

Permalink
refactor: use deploy account transaction extension trait
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Jul 24, 2024
1 parent c13342e commit 5f2855e
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 15 deletions.
2 changes: 1 addition & 1 deletion crates/blockifier/src/test_utils/deploy_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use starknet_api::transaction::{
};

use crate::test_utils::{default_testing_resource_bounds, NonceManager};
use crate::transaction::transactions::DeployAccountTransaction;
use crate::transaction::transactions::{DeployAccountTransaction, DeployAccountTransactionExt};

#[derive(Clone)]
pub struct DeployAccountTxArgs {
Expand Down
1 change: 1 addition & 0 deletions crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use crate::transaction::transaction_utils::update_remaining_gas;
use crate::transaction::transactions::{
DeclareTransaction,
DeployAccountTransaction,
DeployAccountTransactionExt,
Executable,
ExecutableTransaction,
ExecutionFlags,
Expand Down
1 change: 1 addition & 0 deletions crates/blockifier/src/transaction/transaction_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::transaction::objects::{
use crate::transaction::transactions::{
DeclareTransaction,
DeployAccountTransaction,
DeployAccountTransactionExt,
Executable,
ExecutableTransaction,
ExecutionFlags,
Expand Down
58 changes: 46 additions & 12 deletions crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use starknet_api::calldata;
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::internal_transaction::InternalDeployAccountTransaction;
use starknet_api::transaction::{
AccountDeploymentData,
Calldata,
Expand Down Expand Up @@ -57,6 +58,20 @@ macro_rules! implement_inner_tx_getter_calls {
};
}

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

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

#[derive(Clone, Copy, Debug)]
pub struct ExecutionFlags {
pub charge_fee: bool,
Expand Down Expand Up @@ -282,41 +297,60 @@ impl TransactionInfoCreator for DeclareTransaction {
}
}
}
#[derive(Debug, Clone)]
pub struct DeployAccountTransaction {
pub tx: starknet_api::transaction::DeployAccountTransaction,
pub tx_hash: TransactionHash,
pub contract_address: ContractAddress,
// Indicates the presence of the only_query bit in the version.
pub only_query: bool,

pub type DeployAccountTransaction = InternalDeployAccountTransaction;

/// A trait for extending the `DeployAccountTransaction` with additional functionality.
pub trait DeployAccountTransactionExt {
fn new(
deploy_account_tx: starknet_api::transaction::DeployAccountTransaction,
tx_hash: TransactionHash,
contract_address: ContractAddress,
) -> Self;

fn new_for_query(
deploy_account_tx: starknet_api::transaction::DeployAccountTransaction,
tx_hash: TransactionHash,
contract_address: ContractAddress,
) -> Self;

trait_inner_tx_getter_calls!(
(class_hash, ClassHash),
(constructor_calldata, Calldata),
(contract_address_salt, ContractAddressSalt),
(nonce, Nonce),
(signature, TransactionSignature)
);

fn tx(&self) -> &starknet_api::transaction::DeployAccountTransaction;
}

impl DeployAccountTransaction {
pub fn new(
impl DeployAccountTransactionExt for DeployAccountTransaction {
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 }
}

pub fn new_for_query(
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 }
}

implement_inner_tx_getter_calls!(
implement_trait_inner_tx_getter_calls!(
(class_hash, ClassHash),
(constructor_calldata, Calldata),
(contract_address_salt, ContractAddressSalt),
(nonce, Nonce),
(signature, TransactionSignature)
);

pub fn tx(&self) -> &starknet_api::transaction::DeployAccountTransaction {
fn tx(&self) -> &starknet_api::transaction::DeployAccountTransaction {
&self.tx
}
}
Expand Down
6 changes: 5 additions & 1 deletion crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ use crate::transaction::test_utils::{
VALID,
};
use crate::transaction::transaction_types::TransactionType;
use crate::transaction::transactions::{ExecutableTransaction, L1HandlerTransaction};
use crate::transaction::transactions::{
DeployAccountTransactionExt,
ExecutableTransaction,
L1HandlerTransaction,
};
use crate::versioned_constants::VersionedConstants;
use crate::{
check_transaction_execution_error_for_custom_hint,
Expand Down
1 change: 1 addition & 0 deletions crates/gateway/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use blockifier::transaction::account_transaction::AccountTransaction;
use blockifier::transaction::transactions::{
DeclareTransaction as BlockifierDeclareTransaction,
DeployAccountTransaction as BlockifierDeployAccountTransaction,
DeployAccountTransactionExt,
InvokeTransaction as BlockifierInvokeTransaction,
};
use starknet_api::core::{calculate_contract_address, ChainId, ClassHash, ContractAddress, Nonce};
Expand Down
5 changes: 4 additions & 1 deletion crates/native_blockifier/src/py_deploy_account.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::sync::Arc;

use blockifier::transaction::transaction_types::TransactionType;
use blockifier::transaction::transactions::DeployAccountTransaction;
use blockifier::transaction::transactions::{
DeployAccountTransaction,
DeployAccountTransactionExt,
};
use pyo3::prelude::*;
use starknet_api::core::{ClassHash, ContractAddress, Nonce};
use starknet_api::data_availability::DataAvailabilityMode;
Expand Down

0 comments on commit 5f2855e

Please sign in to comment.