Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor invoke as wrapper #93

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,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 @@ -436,26 +435,33 @@ 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),
(tx_hash, TransactionHash),
(version, TransactionVersion)
);

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

Expand All @@ -467,7 +473,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 @@ -513,7 +519,7 @@ impl TransactionInfoCreator for InvokeTransaction {
only_query: self.only_query,
};

match &self.tx {
match &self.tx() {
starknet_api::transaction::InvokeTransaction::V0(tx) => {
TransactionInfo::Deprecated(DeprecatedTransactionInfo {
common_fields,
Expand Down
2 changes: 1 addition & 1 deletion crates/gateway/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,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() {
starknet_api::transaction::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 @@ -144,3 +144,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
}
}
Loading