Skip to content

Commit

Permalink
impl HasTransactionVersion for AccountTransaction (starkware-libs#896)
Browse files Browse the repository at this point in the history
Signed-off-by: Dori Medini <[email protected]>
  • Loading branch information
dorimedini-starkware committed Sep 6, 2023
1 parent 1c6d2c0 commit f461015
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::hash::StarkFelt;
use starknet_api::transaction::{Calldata, Fee, TransactionVersion};

use super::objects::HasTransactionVersion;
use crate::abi::abi_utils::selector_from_name;
use crate::abi::constants as abi_constants;
use crate::block_context::BlockContext;
Expand Down Expand Up @@ -53,6 +54,23 @@ pub enum AccountTransaction {
Invoke(InvokeTransaction),
}

impl HasTransactionVersion for AccountTransaction {
fn version(&self) -> TransactionVersion {
match self {
Self::Declare(tx) => tx.tx().version(),
Self::DeployAccount(tx) => tx.version(),
Self::Invoke(tx) => match tx.tx {
starknet_api::transaction::InvokeTransaction::V0(_) => {
TransactionVersion(StarkFelt::from(0_u8))
}
starknet_api::transaction::InvokeTransaction::V1(_) => {
TransactionVersion(StarkFelt::from(1_u8))
}
},
}
}
}

impl AccountTransaction {
pub fn tx_type(&self) -> TransactionType {
match self {
Expand Down Expand Up @@ -110,7 +128,7 @@ impl AccountTransaction {
AccountTransactionContext {
transaction_hash: tx.tx_hash(),
max_fee: sn_api_tx.max_fee(),
version: sn_api_tx.version(),
version: self.version(),
signature: sn_api_tx.signature(),
nonce: sn_api_tx.nonce(),
sender_address: sn_api_tx.sender_address(),
Expand All @@ -119,7 +137,7 @@ impl AccountTransaction {
Self::DeployAccount(tx) => AccountTransactionContext {
transaction_hash: tx.tx_hash,
max_fee: tx.max_fee(),
version: tx.version(),
version: self.version(),
signature: tx.signature(),
nonce: tx.nonce(),
sender_address: tx.contract_address,
Expand All @@ -129,14 +147,7 @@ impl AccountTransaction {
AccountTransactionContext {
transaction_hash: tx.tx_hash,
max_fee: sn_api_tx.max_fee(),
version: match sn_api_tx {
starknet_api::transaction::InvokeTransaction::V0(_) => {
TransactionVersion(StarkFelt::from(0_u8))
}
starknet_api::transaction::InvokeTransaction::V1(_) => {
TransactionVersion(StarkFelt::from(1_u8))
}
},
version: self.version(),
signature: sn_api_tx.signature(),
nonce: match sn_api_tx {
starknet_api::transaction::InvokeTransaction::V0(_) => Nonce::default(),
Expand Down

0 comments on commit f461015

Please sign in to comment.