Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: streamline the starknet api contract class object #524

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
Loading