Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Add V3 support in get_account_tx_context. (#970)
Browse files Browse the repository at this point in the history
  • Loading branch information
NirLevi-starkware authored Oct 5, 2023
1 parent 3d95cae commit 2ced530
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 16 deletions.
6 changes: 3 additions & 3 deletions crates/blockifier/src/transaction/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ macro_rules! implement_getters {
($(($field:ident, $field_type:ty)),*) => {
$(pub fn $field(&self) -> $field_type {
match self{
Self::Deprecated(context) => context.common_fields.$field,
Self::Current(context) => context.common_fields.$field,
Self::Deprecated(context) => context.common_fields.$field,
}
})*
};
Expand Down Expand Up @@ -50,20 +50,20 @@ impl AccountTransactionContext {

pub fn signature(&self) -> TransactionSignature {
match self {
Self::Deprecated(context) => context.common_fields.signature.clone(),
Self::Current(context) => context.common_fields.signature.clone(),
Self::Deprecated(context) => context.common_fields.signature.clone(),
}
}

pub fn max_fee(&self) -> Fee {
match self {
Self::Deprecated(context) => context.max_fee,
Self::Current(context) => {
let l1_resource_bounds =
context.resource_bounds.0.get(&Resource::L1Gas).copied().unwrap_or_default();
// TODO(nir, 01/11/2023): Change to max_amount * block_context.gas_price.
Fee(l1_resource_bounds.max_amount as u128 * l1_resource_bounds.max_price_per_unit)
}
Self::Deprecated(context) => context.max_fee,
}
}

Expand Down
63 changes: 50 additions & 13 deletions crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::sync::Arc;
use starknet_api::core::{ClassHash, ContractAddress, Nonce};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::transaction::{
Calldata, ContractAddressSalt, DeclareTransactionV2, DeclareTransactionV3, Fee, Resource,
TransactionHash, TransactionSignature, TransactionVersion,
AccountDeploymentData, Calldata, ContractAddressSalt, DeclareTransactionV2,
DeclareTransactionV3, Fee, Resource, TransactionHash, TransactionSignature, TransactionVersion,
};

use super::objects::{
AccountTransactionContext, CommonAccountFields, DeprecatedAccountTransactionContext,
HasRelatedFeeType,
AccountTransactionContext, CommonAccountFields, CurrentAccountTransactionContext,
DeprecatedAccountTransactionContext, HasRelatedFeeType,
};
use crate::abi::abi_utils::selector_from_name;
use crate::block_context::BlockContext;
Expand Down Expand Up @@ -173,21 +173,35 @@ impl DeclareTransaction {
}

pub fn get_account_tx_context(&self) -> AccountTransactionContext {
// TODO(Nir, 01/11/2023): Consider to move this (from all get_account_tx_context methods).
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(),
};
match self.tx.version() {
TransactionVersion::ZERO | TransactionVersion::ONE | TransactionVersion::TWO => {

match &self.tx {
starknet_api::transaction::DeclareTransaction::V0(_)
| starknet_api::transaction::DeclareTransaction::V1(_)
| starknet_api::transaction::DeclareTransaction::V2(_) => {
AccountTransactionContext::Deprecated(DeprecatedAccountTransactionContext {
common_fields,
max_fee: self.max_fee(),
})
}
_ => unreachable!("Not implemented for tx version {:?}", self.tx.version()),
starknet_api::transaction::DeclareTransaction::V3(tx) => {
AccountTransactionContext::Current(CurrentAccountTransactionContext {
common_fields,
resource_bounds: tx.resource_bounds.clone(),
tip: tx.tip,
nonce_data_availability_mode: tx.nonce_data_availability_mode,
fee_data_availability_mode: tx.fee_data_availability_mode,
paymaster_data: tx.paymaster_data.clone(),
account_deployment_data: tx.account_deployment_data.clone(),
})
}
}
}
}
Expand Down Expand Up @@ -276,14 +290,25 @@ impl DeployAccountTransaction {
nonce: self.tx.nonce(),
sender_address: self.contract_address,
};
match self.tx.version() {
TransactionVersion::ONE => {

match &self.tx {
starknet_api::transaction::DeployAccountTransaction::V1(_) => {
AccountTransactionContext::Deprecated(DeprecatedAccountTransactionContext {
common_fields,
max_fee: self.max_fee(),
})
}
_ => unreachable!("Not implemented for tx version {:?}", self.tx.version()),
starknet_api::transaction::DeployAccountTransaction::V3(tx) => {
AccountTransactionContext::Current(CurrentAccountTransactionContext {
common_fields,
resource_bounds: tx.resource_bounds.clone(),
tip: tx.tip,
nonce_data_availability_mode: tx.nonce_data_availability_mode,
fee_data_availability_mode: tx.fee_data_availability_mode,
paymaster_data: tx.paymaster_data.clone(),
account_deployment_data: AccountDeploymentData::default(),
})
}
}
}
}
Expand Down Expand Up @@ -349,14 +374,26 @@ impl InvokeTransaction {
nonce: self.tx.nonce(),
sender_address: self.tx.sender_address(),
};
match self.tx.version() {
TransactionVersion::ZERO | TransactionVersion::ONE => {

match &self.tx {
starknet_api::transaction::InvokeTransaction::V0(_)
| starknet_api::transaction::InvokeTransaction::V1(_) => {
AccountTransactionContext::Deprecated(DeprecatedAccountTransactionContext {
common_fields,
max_fee: self.max_fee(),
})
}
_ => unreachable!("Not implemented for tx version {:?}", self.tx.version()),
starknet_api::transaction::InvokeTransaction::V3(tx) => {
AccountTransactionContext::Current(CurrentAccountTransactionContext {
common_fields,
resource_bounds: tx.resource_bounds.clone(),
tip: tx.tip,
nonce_data_availability_mode: tx.nonce_data_availability_mode,
fee_data_availability_mode: tx.fee_data_availability_mode,
paymaster_data: tx.paymaster_data.clone(),
account_deployment_data: tx.account_deployment_data.clone(),
})
}
}
}
}
Expand Down

0 comments on commit 2ced530

Please sign in to comment.