From f46101544c54e433adea39c56eeee63d0715e49d Mon Sep 17 00:00:00 2001 From: dorimedini-starkware Date: Wed, 6 Sep 2023 16:51:38 +0300 Subject: [PATCH] impl HasTransactionVersion for AccountTransaction (#896) Signed-off-by: Dori Medini --- .../src/transaction/account_transaction.rs | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/crates/blockifier/src/transaction/account_transaction.rs b/crates/blockifier/src/transaction/account_transaction.rs index 2978f8bf0e..bc104becb2 100644 --- a/crates/blockifier/src/transaction/account_transaction.rs +++ b/crates/blockifier/src/transaction/account_transaction.rs @@ -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; @@ -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 { @@ -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(), @@ -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, @@ -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(),