Skip to content

Commit

Permalink
chore: refactor invoke as wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Jul 31, 2024
1 parent e90a275 commit 91422c2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 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 @@ -75,7 +75,7 @@ impl HasRelatedFeeType for AccountTransaction {
match self {
Self::Declare(tx) => tx.tx.version(),
Self::DeployAccount(tx) => tx.version(),
Self::Invoke(tx) => match tx.tx {
Self::Invoke(tx) => match tx.tx.tx {
starknet_api::transaction::InvokeTransaction::V0(_) => TransactionVersion::ZERO,
starknet_api::transaction::InvokeTransaction::V1(_) => TransactionVersion::ONE,
starknet_api::transaction::InvokeTransaction::V3(_) => TransactionVersion::THREE,
Expand Down
35 changes: 24 additions & 11 deletions crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,25 +404,38 @@ impl TransactionInfoCreator for DeployAccountTransaction {

#[derive(Debug, Clone)]
pub struct InvokeTransaction {
pub tx: starknet_api::transaction::InvokeTransaction,
pub tx_hash: TransactionHash,
pub tx: starknet_api::executable_transaction::InvokeTransaction,
// Indicates the presence of the only_query bit in the version.
pub only_query: bool,
}

impl Deref for InvokeTransaction {
type Target = starknet_api::executable_transaction::InvokeTransaction;

fn deref(&self) -> &Self::Target {
&self.tx
}
}

impl InvokeTransaction {
pub fn new(
invoke_tx: starknet_api::transaction::InvokeTransaction,
tx_hash: TransactionHash,
) -> Self {
Self { tx: invoke_tx, tx_hash, only_query: false }
Self {
tx: starknet_api::executable_transaction::InvokeTransaction { tx: invoke_tx, tx_hash },
only_query: false,
}
}

pub fn new_for_query(
invoke_tx: starknet_api::transaction::InvokeTransaction,
tx_hash: TransactionHash,
) -> Self {
Self { tx: invoke_tx, tx_hash, only_query: true }
Self {
tx: starknet_api::executable_transaction::InvokeTransaction { tx: invoke_tx, tx_hash },
only_query: true,
}
}

implement_inner_tx_getter_calls!(
Expand All @@ -440,7 +453,7 @@ impl<S: State> Executable<S> for InvokeTransaction {
context: &mut EntryPointExecutionContext,
remaining_gas: &mut u64,
) -> TransactionExecutionResult<Option<CallInfo>> {
let entry_point_selector = match &self.tx {
let entry_point_selector = match &self.tx.tx {
starknet_api::transaction::InvokeTransaction::V0(tx) => tx.entry_point_selector,
starknet_api::transaction::InvokeTransaction::V1(_)
| starknet_api::transaction::InvokeTransaction::V3(_) => {
Expand Down Expand Up @@ -478,15 +491,15 @@ impl<S: State> Executable<S> for InvokeTransaction {
impl TransactionInfoCreator for InvokeTransaction {
fn create_tx_info(&self) -> TransactionInfo {
let common_fields = CommonAccountFields {
transaction_hash: self.tx_hash,
version: self.tx.version(),
signature: self.tx.signature(),
nonce: self.tx.nonce(),
sender_address: self.tx.sender_address(),
transaction_hash: self.tx.tx_hash,
version: self.tx.tx.version(),
signature: self.tx.tx.signature(),
nonce: self.tx.tx.nonce(),
sender_address: self.tx.tx.sender_address(),
only_query: self.only_query,
};

match &self.tx {
match &self.tx.tx {
starknet_api::transaction::InvokeTransaction::V0(tx) => {
TransactionInfo::Deprecated(DeprecatedTransactionInfo {
common_fields,
Expand Down
12 changes: 11 additions & 1 deletion crates/starknet_api/src/executable_transaction.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Deref;

use crate::core::{ContractAddress, Nonce};
use crate::state::ContractClass;
use crate::transaction::{Tip, TransactionHash};
Expand Down Expand Up @@ -68,7 +70,7 @@ pub struct DeployAccountTransaction {
pub contract_address: ContractAddress,
}

impl std::ops::Deref for DeployAccountTransaction {
impl Deref for DeployAccountTransaction {
type Target = crate::transaction::DeployAccountTransaction;

fn deref(&self) -> &Self::Target {
Expand All @@ -82,6 +84,14 @@ pub struct InvokeTransaction {
pub tx_hash: TransactionHash,
}

impl Deref for InvokeTransaction {
type Target = crate::transaction::InvokeTransaction;

fn deref(&self) -> &Self::Target {
&self.tx
}
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ClassInfo {
// TODO: use compiled contract class.
Expand Down

0 comments on commit 91422c2

Please sign in to comment.