Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Merged
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions src/state/in_memory_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ use cairo_vm::felt::Felt252;
use getset::{Getters, MutGetters};
use std::collections::HashMap;

/// A StateReader that holds all the data in memory.
///
/// This implementation is used for testing and debugging.
/// It uses HashMaps to store the data.
#[derive(Debug, MutGetters, Getters, PartialEq, Clone, Default)]
pub struct InMemoryStateReader {
#[getset(get_mut = "pub")]
Expand All @@ -31,6 +35,15 @@ pub struct InMemoryStateReader {
}

impl InMemoryStateReader {
/// Creates a new InMemoryStateReader.
///
/// # Parameters
/// - `address_to_class_hash` - A HashMap from contract addresses to their class hashes.
/// - `address_to_nonce` - A HashMap from contract addresses to their nonces.
/// - `address_to_storage` - A HashMap from storage entries to their values.
/// - `class_hash_to_contract_class` - A HashMap from class hashes to their contract classes.
/// - `casm_contract_classes` - A [CasmClassCache].
/// - `class_hash_to_compiled_class_hash` - A HashMap from class hashes to their compiled class hashes.
pub fn new(
address_to_class_hash: HashMap<Address, ClassHash>,
address_to_nonce: HashMap<Address, Felt252>,
Expand All @@ -49,6 +62,18 @@ impl InMemoryStateReader {
}
}

/// Gets the [CompiledClass] with the given [CompiledClassHash].
///
/// It looks for the [CompiledClass] both in the cache and the storage.
///
/// # Parameters
/// - `compiled_class_hash` - The [CompiledClassHash] of the [CompiledClass] to get.
///
/// # Errors
/// - [StateError::NoneCompiledClass] - If the [CompiledClass] is not found.
///
/// # Returns
/// The [CompiledClass] with the given [CompiledClassHash].
fn get_compiled_class(
&mut self,
compiled_class_hash: &CompiledClassHash,
Expand Down