Skip to content

Commit

Permalink
chore: organize methods such that public methods are at bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Aug 18, 2024
1 parent 4b89e22 commit 85e18ed
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions crates/blockifier/src/execution/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ impl ContractClassV0 {
self.entry_points_by_type.values().map(|vec| vec.len()).sum()
}

pub fn n_builtins(&self) -> usize {
self.program.builtins_len()
}

pub fn bytecode_length(&self) -> usize {
self.program.data_len()
}

fn estimate_casm_hash_computation_resources(&self) -> ExecutionResources {
let hashed_data_size = (constants::CAIRO0_ENTRY_POINT_STRUCT_SIZE * self.n_entry_points())
+ self.n_builtins()
Expand All @@ -145,6 +137,14 @@ impl ContractClassV0 {
}
}

pub fn n_builtins(&self) -> usize {
self.program.builtins_len()
}

pub fn bytecode_length(&self) -> usize {
self.program.data_len()
}

pub fn try_from_json_string(raw_contract_class: &str) -> Result<ContractClassV0, ProgramError> {
let contract_class: ContractClassV0Inner = serde_json::from_str(raw_contract_class)?;
Ok(ContractClassV0(Arc::new(contract_class)))
Expand Down Expand Up @@ -185,6 +185,13 @@ impl ContractClassV1 {
Some(self.0.entry_points_by_type[&EntryPointType::Constructor].first()?.selector)
}

/// Returns the estimated VM resources required for computing Casm hash.
/// This is an empiric measurement of several bytecode lengths, which constitutes as the
/// dominant factor in it.
fn estimate_casm_hash_computation_resources(&self) -> ExecutionResources {
estimate_casm_hash_computation_resources(&self.bytecode_segment_lengths)
}

pub fn bytecode_length(&self) -> usize {
self.program.data_len()
}
Expand Down Expand Up @@ -219,30 +226,23 @@ impl ContractClassV1 {
}
}

/// Returns the estimated VM resources required for computing Casm hash.
/// This is an empiric measurement of several bytecode lengths, which constitutes as the
/// dominant factor in it.
fn estimate_casm_hash_computation_resources(&self) -> ExecutionResources {
estimate_casm_hash_computation_resources(&self.bytecode_segment_lengths)
pub fn try_from_json_string(raw_contract_class: &str) -> Result<ContractClassV1, ProgramError> {
let casm_contract_class: CasmContractClass = serde_json::from_str(raw_contract_class)?;
let contract_class: ContractClassV1 = casm_contract_class.try_into()?;

Ok(contract_class)
}

// Returns the set of segments that were visited according to the given visited PCs.
// Each visited segment must have its starting PC visited, and is represented by it.
fn get_visited_segments(
pub fn get_visited_segments(
&self,
visited_pcs: &HashSet<usize>,
) -> Result<Vec<usize>, TransactionExecutionError> {
let mut reversed_visited_pcs: Vec<_> = visited_pcs.iter().cloned().sorted().rev().collect();
get_visited_segments(&self.bytecode_segment_lengths, &mut reversed_visited_pcs, &mut 0)
}

pub fn try_from_json_string(raw_contract_class: &str) -> Result<ContractClassV1, ProgramError> {
let casm_contract_class: CasmContractClass = serde_json::from_str(raw_contract_class)?;
let contract_class: ContractClassV1 = casm_contract_class.try_into()?;

Ok(contract_class)
}

/// Returns an empty contract class for testing purposes.
#[cfg(any(feature = "testing", test))]
pub fn empty_for_testing() -> Self {
Expand Down

0 comments on commit 85e18ed

Please sign in to comment.