11use std:: collections:: HashMap ;
22use std:: future:: Future ;
33
4+ use starknet_api:: block:: BlockNumber ;
45use starknet_api:: core:: ContractAddress ;
56use starknet_api:: hash:: HashOutput ;
67use starknet_patricia:: patricia_merkle_tree:: node_data:: leaf:: LeafModifications ;
78use starknet_patricia:: patricia_merkle_tree:: types:: NodeIndex ;
9+ use starknet_patricia_storage:: storage_trait:: { DbHashMap , DbKey , DbValue , Storage } ;
810
911use crate :: block_committer:: input:: { ConfigImpl , StarknetStorageValue } ;
1012use crate :: forest:: filled_forest:: FilledForest ;
@@ -13,6 +15,39 @@ use crate::forest::original_skeleton_forest::{ForestSortedIndices, OriginalSkele
1315use crate :: patricia_merkle_tree:: leaf:: leaf_impl:: ContractState ;
1416use crate :: patricia_merkle_tree:: types:: CompiledClassHash ;
1517
18+ pub enum ForestMetadataType {
19+ CommitmentOffset ,
20+ StateDiffHash ( BlockNumber ) ,
21+ }
22+
23+ pub trait ForestMetadata {
24+ /// Returns the db key for the metadata type.
25+ fn metadata_key ( metadata_type : ForestMetadataType ) -> DbKey ;
26+
27+ /// Reads the metadata from the storage.
28+ fn read_metadata (
29+ & self ,
30+ storage : & mut impl Storage ,
31+ metadata_type : ForestMetadataType ,
32+ ) -> impl Future < Output = ForestResult < Option < DbValue > > > + Send {
33+ async {
34+ let db_key = Self :: metadata_key ( metadata_type) ;
35+ Ok ( storage. get ( & db_key) . await ?)
36+ }
37+ }
38+
39+ /// Sets the metadata in the storage. Returns the previous value if it existed.
40+ fn set_metadata (
41+ updates : & mut DbHashMap ,
42+ metadata_type : ForestMetadataType ,
43+ value : DbValue ,
44+ ) -> Option < DbValue > {
45+ let db_key = Self :: metadata_key ( metadata_type) ;
46+ updates. insert ( db_key, value)
47+ }
48+ }
49+
50+
1651/// Trait for reading an original skeleton forest from some storage.
1752/// The implementation may depend on the underlying storage layout.
1853pub trait ForestReader < ' a > {
0 commit comments