diff --git a/crates/blockifier/src/execution/contract_class.rs b/crates/blockifier/src/execution/contract_class.rs index 24964c828e..4172a192e7 100644 --- a/crates/blockifier/src/execution/contract_class.rs +++ b/crates/blockifier/src/execution/contract_class.rs @@ -498,6 +498,21 @@ pub struct ClassInfo { abi_length: usize, } +impl TryFrom for ClassInfo { + type Error = ProgramError; + + fn try_from(value: starknet_api::contract_class::ClassInfo) -> Result { + let starknet_api::contract_class::ClassInfo { + contract_class, + sierra_program_length, + abi_length, + } = value; + + let contract_class: ContractClass = contract_class.try_into()?; + Ok(Self { contract_class, sierra_program_length, abi_length }) + } +} + impl ClassInfo { pub fn bytecode_length(&self) -> usize { self.contract_class.bytecode_length() diff --git a/crates/blockifier/src/transaction/errors.rs b/crates/blockifier/src/transaction/errors.rs index 70b9fbe6ab..cbd9d38085 100644 --- a/crates/blockifier/src/transaction/errors.rs +++ b/crates/blockifier/src/transaction/errors.rs @@ -1,3 +1,4 @@ +use cairo_vm::types::errors::program_errors::ProgramError; use num_bigint::BigUint; use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector, Nonce}; use starknet_api::transaction::{Fee, TransactionVersion}; @@ -109,6 +110,8 @@ pub enum TransactionExecutionError { not." )] InvalidSegmentStructure(usize, usize), + #[error(transparent)] + ProgramError(#[from] ProgramError), } #[derive(Debug, Error)] diff --git a/crates/blockifier/src/transaction/transactions.rs b/crates/blockifier/src/transaction/transactions.rs index 834660c740..e89a98e56d 100644 --- a/crates/blockifier/src/transaction/transactions.rs +++ b/crates/blockifier/src/transaction/transactions.rs @@ -135,6 +135,16 @@ pub struct DeclareTransaction { pub class_info: ClassInfo, } +impl TryFrom for DeclareTransaction { + type Error = TransactionExecutionError; + + fn try_from( + value: starknet_api::executable_transaction::DeclareTransaction, + ) -> Result { + Self::new_from_executable_tx(value, false) + } +} + impl DeclareTransaction { fn create( declare_tx: starknet_api::transaction::DeclareTransaction, @@ -163,6 +173,19 @@ impl DeclareTransaction { Self::create(declare_tx, tx_hash, class_info, true) } + pub fn new_from_executable_tx( + declare_tx: starknet_api::executable_transaction::DeclareTransaction, + only_query: bool, + ) -> Result { + let starknet_api::executable_transaction::DeclareTransaction { tx, tx_hash, class_info } = + declare_tx; + let class_info: ClassInfo = class_info.try_into()?; + + // TODO(Arni): We don't need to verify the contract class version here, any executable + // declare transaction will always have matching versions. + Self::create(tx, tx_hash, class_info, only_query) + } + implement_inner_tx_getter_calls!((class_hash, ClassHash), (signature, TransactionSignature)); pub fn tx(&self) -> &starknet_api::transaction::DeclareTransaction { diff --git a/crates/starknet_api/src/contract_class.rs b/crates/starknet_api/src/contract_class.rs index b070c50114..750a33a9ff 100644 --- a/crates/starknet_api/src/contract_class.rs +++ b/crates/starknet_api/src/contract_class.rs @@ -12,7 +12,7 @@ pub enum ContractClassV1 { #[derive(Clone, Debug, Eq, PartialEq)] pub struct ClassInfo { - contract_class: ContractClass, - sierra_program_length: usize, - abi_length: usize, + pub contract_class: ContractClass, + pub sierra_program_length: usize, + pub abi_length: usize, }