Skip to content

Commit 13b53f4

Browse files
apollo_storage: split get_casm into two functions for separate location and data retrieval (#11283)
1 parent e7d1903 commit 13b53f4

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

crates/apollo_storage/src/compiled_class.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ pub trait CasmStorageReader {
7373
&self,
7474
class_hash: &ClassHash,
7575
) -> StorageResult<(Option<CasmContractClass>, Option<SierraContractClass>)>;
76+
77+
/// Returns the file location for a CASM with the given class hash.
78+
fn get_casm_location(&self, class_hash: &ClassHash) -> StorageResult<Option<LocationInFile>>;
79+
80+
/// Returns the CASM from a specific file location.
81+
fn get_casm_from_location(&self, location: LocationInFile) -> StorageResult<CasmContractClass>;
82+
7683
/// The block marker is the first block number that doesn't exist yet.
7784
///
7885
/// Note: If the last blocks don't contain any declared classes, the marker will point at the
@@ -92,9 +99,8 @@ where
9299

93100
impl<Mode: TransactionKind> CasmStorageReader for StorageTxn<'_, Mode> {
94101
fn get_casm(&self, class_hash: &ClassHash) -> StorageResult<Option<CasmContractClass>> {
95-
let casm_table = self.open_table(&self.tables.casms)?;
96-
let casm_location = casm_table.get(&self.txn, class_hash)?;
97-
casm_location.map(|location| self.file_handlers.get_casm_unchecked(location)).transpose()
102+
let casm_location = self.get_casm_location(class_hash)?;
103+
casm_location.map(|location| self.get_casm_from_location(location)).transpose()
98104
}
99105

100106
fn get_casm_and_sierra(
@@ -104,6 +110,16 @@ impl<Mode: TransactionKind> CasmStorageReader for StorageTxn<'_, Mode> {
104110
Ok((self.get_casm(class_hash)?, self.get_class(class_hash)?))
105111
}
106112

113+
fn get_casm_location(&self, class_hash: &ClassHash) -> StorageResult<Option<LocationInFile>> {
114+
let casm_table = self.open_table(&self.tables.casms)?;
115+
let casm_location = casm_table.get(&self.txn, class_hash)?;
116+
Ok(casm_location)
117+
}
118+
119+
fn get_casm_from_location(&self, location: LocationInFile) -> StorageResult<CasmContractClass> {
120+
self.file_handlers.get_casm_unchecked(location)
121+
}
122+
107123
fn get_compiled_class_marker(&self) -> StorageResult<BlockNumber> {
108124
let markers_table = self.open_table(&self.tables.markers)?;
109125
Ok(markers_table.get(&self.txn, &MarkerKind::CompiledClass)?.unwrap_or_default())

0 commit comments

Comments
 (0)