pub mod declare;
pub mod declare_v2;
pub mod deploy;
pub mod deploy_account;
pub mod error;
pub mod fee;
pub mod invoke_function;
pub mod l1_handler;
mod verify_version;
pub use declare::Declare;
pub use declare_v2::DeclareV2;
pub use deploy::Deploy;
pub use deploy_account::DeployAccount;
pub use invoke_function::InvokeFunction;
pub use l1_handler::L1Handler;
pub use verify_version::verify_version;
use crate::{
definitions::block_context::BlockContext,
execution::TransactionExecutionInfo,
state::{cached_state::CachedState, state_api::StateReader},
utils::Address,
};
use error::TransactionError;
pub enum Transaction {
Declare(Declare),
DeclareV2(Box<DeclareV2>),
Deploy(Deploy),
DeployAccount(DeployAccount),
InvokeFunction(InvokeFunction),
L1Handler(L1Handler),
}
impl Transaction {
pub fn contract_address(&self) -> Address {
match self {
Transaction::Deploy(tx) => tx.contract_address.clone(),
Transaction::InvokeFunction(tx) => tx.contract_address().clone(),
Transaction::Declare(tx) => tx.sender_address.clone(),
Transaction::DeclareV2(tx) => tx.sender_address.clone(),
Transaction::DeployAccount(tx) => tx.contract_address().clone(),
Transaction::L1Handler(tx) => tx.contract_address().clone(),
}
}
pub fn execute<S: StateReader>(
&self,
state: &mut CachedState<S>,
block_context: &BlockContext,
remaining_gas: u128,
) -> Result<TransactionExecutionInfo, TransactionError> {
match self {
Transaction::Declare(tx) => tx.execute(state, block_context),
Transaction::DeclareV2(tx) => tx.execute(state, block_context),
Transaction::Deploy(tx) => tx.execute(state, block_context),
Transaction::DeployAccount(tx) => tx.execute(state, block_context),
Transaction::InvokeFunction(tx) => tx.execute(state, block_context, remaining_gas),
Transaction::L1Handler(tx) => tx.execute(state, block_context, remaining_gas),
}
}
pub fn create_for_simulation(
&self,
skip_validate: bool,
skip_execute: bool,
skip_fee_transfer: bool,
ignore_max_fee: bool,
skip_nonce_check: bool,
) -> Self {
match self {
Transaction::Declare(tx) => tx.create_for_simulation(
skip_validate,
skip_execute,
skip_fee_transfer,
ignore_max_fee,
),
Transaction::DeclareV2(tx) => tx.create_for_simulation(
skip_validate,
skip_execute,
skip_fee_transfer,
ignore_max_fee,
),
Transaction::Deploy(tx) => {
tx.create_for_simulation(skip_validate, skip_execute, skip_fee_transfer)
}
Transaction::DeployAccount(tx) => tx.create_for_simulation(
skip_validate,
skip_execute,
skip_fee_transfer,
ignore_max_fee,
),
Transaction::InvokeFunction(tx) => tx.create_for_simulation(
skip_validate,
skip_execute,
skip_fee_transfer,
ignore_max_fee,
skip_nonce_check,
),
Transaction::L1Handler(tx) => tx.create_for_simulation(skip_validate, skip_execute),
}
}
}