Skip to content

Commit

Permalink
chore: streamline the starknet api contract class object
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Aug 20, 2024
1 parent 98f8d2c commit a5fa529
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 34 deletions.
30 changes: 9 additions & 21 deletions crates/blockifier/src/execution/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,11 @@ pub enum ContractClass {
V1(ContractClassV1),
}

impl TryFrom<starknet_api::contract_class::ContractClass> for ContractClass {
impl TryFrom<CasmContractClass> for ContractClass {
type Error = ProgramError;

fn try_from(
contract_class: starknet_api::contract_class::ContractClass,
) -> Result<Self, Self::Error> {
let starknet_api::contract_class::ContractClass::V1(contract_class_v1) = contract_class;
Ok(ContractClass::V1(contract_class_v1.try_into()?))
fn try_from(contract_class: CasmContractClass) -> Result<Self, Self::Error> {
Ok(ContractClass::V1(contract_class.try_into()?))
}
}

Expand Down Expand Up @@ -373,18 +370,6 @@ impl EntryPointV1 {
}
}

impl TryFrom<starknet_api::contract_class::ContractClassV1> for ContractClassV1 {
type Error = ProgramError;

fn try_from(
contract_class: starknet_api::contract_class::ContractClassV1,
) -> Result<Self, Self::Error> {
let starknet_api::contract_class::ContractClassV1::Casm(casm_contract_class) =
contract_class;
casm_contract_class.try_into()
}
}

impl TryFrom<CasmContractClass> for ContractClassV1 {
type Error = ProgramError;

Expand Down Expand Up @@ -509,13 +494,16 @@ impl TryFrom<starknet_api::contract_class::ClassInfo> for ClassInfo {

fn try_from(class_info: starknet_api::contract_class::ClassInfo) -> Result<Self, Self::Error> {
let starknet_api::contract_class::ClassInfo {
contract_class,
casm_contract_class,
sierra_program_length,
abi_length,
} = class_info;

let contract_class: ContractClass = contract_class.try_into()?;
Ok(Self { contract_class, sierra_program_length, abi_length })
Ok(Self {
contract_class: casm_contract_class.try_into()?,
sierra_program_length,
abi_length,
})
}
}

Expand Down
14 changes: 1 addition & 13 deletions crates/starknet_api/src/contract_class.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use serde::{Deserialize, Serialize};

/// Compiled contract class.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum ContractClass {
V1(ContractClassV1),
}

/// Compiled contract class variant for Cairo 1 contracts.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum ContractClassV1 {
Casm(CasmContractClass),
}

/// All relevant information about a declared contract class, including the compiled contract class
/// and other parameters derived from the original declare transaction required for billing.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ClassInfo {
pub contract_class: ContractClass,
pub casm_contract_class: CasmContractClass,
pub sierra_program_length: usize,
pub abi_length: usize,
}

0 comments on commit a5fa529

Please sign in to comment.