Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 6ddb5a9

Browse files
committed
Document InMemoryStateReader
1 parent dce8b59 commit 6ddb5a9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/state/in_memory_state_reader.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ use cairo_vm::felt::Felt252;
1414
use getset::{Getters, MutGetters};
1515
use std::collections::HashMap;
1616

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

3337
impl InMemoryStateReader {
38+
/// Creates a new InMemoryStateReader.
39+
///
40+
/// # Parameters
41+
/// - `address_to_class_hash` - A HashMap from contract addresses to their class hashes.
42+
/// - `address_to_nonce` - A HashMap from contract addresses to their nonces.
43+
/// - `address_to_storage` - A HashMap from storage entries to their values.
44+
/// - `class_hash_to_contract_class` - A HashMap from class hashes to their contract classes.
45+
/// - `casm_contract_classes` - A [CasmClassCache].
46+
/// - `class_hash_to_compiled_class_hash` - A HashMap from class hashes to their compiled class hashes.
3447
pub fn new(
3548
address_to_class_hash: HashMap<Address, ClassHash>,
3649
address_to_nonce: HashMap<Address, Felt252>,
@@ -49,6 +62,18 @@ impl InMemoryStateReader {
4962
}
5063
}
5164

65+
/// Gets the [CompiledClass] with the given [CompiledClassHash].
66+
///
67+
/// It looks for the [CompiledClass] both in the cache and the storage.
68+
///
69+
/// # Parameters
70+
/// - `compiled_class_hash` - The [CompiledClassHash] of the [CompiledClass] to get.
71+
///
72+
/// # Errors
73+
/// - [StateError::NoneCompiledClass] - If the [CompiledClass] is not found.
74+
///
75+
/// # Returns
76+
/// The [CompiledClass] with the given [CompiledClassHash].
5277
fn get_compiled_class(
5378
&mut self,
5479
compiled_class_hash: &CompiledClassHash,

0 commit comments

Comments
 (0)