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 Aug 12, 2024
1 parent dd0da5e commit 62b16c3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
36 changes: 24 additions & 12 deletions crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ 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,
}
Expand All @@ -430,21 +429,34 @@ impl InvokeTransaction {
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!(
(calldata, Calldata),
(nonce, Nonce),
(signature, TransactionSignature),
(sender_address, ContractAddress)
(sender_address, ContractAddress),
(tx_hash, TransactionHash),
(version, TransactionVersion)
);

pub fn tx(&self) -> &starknet_api::transaction::InvokeTransaction {
self.tx.tx()
}
}

impl<S: State> Executable<S> for InvokeTransaction {
Expand All @@ -455,7 +467,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 @@ -493,15 +505,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_hash(),
version: self.version(),
signature: self.signature(),
nonce: self.nonce(),
sender_address: self.sender_address(),
only_query: self.only_query,
};

match &self.tx {
match &self.tx() {
starknet_api::transaction::InvokeTransaction::V0(tx) => {
TransactionInfo::Deprecated(DeprecatedTransactionInfo {
common_fields,
Expand Down
4 changes: 2 additions & 2 deletions crates/gateway/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn get_tx_hash(tx: &AccountTransaction) -> TransactionHash {
match tx {
AccountTransaction::Declare(tx) => tx.tx_hash,
AccountTransaction::DeployAccount(tx) => tx.tx_hash(),
AccountTransaction::Invoke(tx) => tx.tx_hash,
AccountTransaction::Invoke(tx) => tx.tx_hash(),
}
}

Expand All @@ -132,7 +132,7 @@ pub fn get_sender_address(tx: &AccountTransaction) -> ContractAddress {
_ => panic!("Unsupported transaction version"),
},
AccountTransaction::DeployAccount(tx) => tx.contract_address(),
AccountTransaction::Invoke(tx) => match &tx.tx {
AccountTransaction::Invoke(tx) => match &tx.tx() {
InvokeTransaction::V3(tx) => tx.sender_address,
_ => panic!("Unsupported transaction version"),
},
Expand Down
15 changes: 15 additions & 0 deletions crates/starknet_api/src/executable_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,18 @@ pub struct InvokeTransaction {
pub tx: crate::transaction::InvokeTransaction,
pub tx_hash: TransactionHash,
}

impl InvokeTransaction {
implement_inner_tx_getter_calls!(
(calldata, Calldata),
(nonce, Nonce),
(signature, TransactionSignature),
(sender_address, ContractAddress),
(version, TransactionVersion)
);
implement_getter_calls!((tx_hash, TransactionHash));

pub fn tx(&self) -> &crate::transaction::InvokeTransaction {
&self.tx
}
}

0 comments on commit 62b16c3

Please sign in to comment.