|
| 1 | +use starknet_patricia::patricia_merkle_tree::filled_tree::node::FilledNode; |
| 2 | +use starknet_patricia::patricia_merkle_tree::node_data::leaf::Leaf; |
| 3 | +use starknet_patricia::patricia_merkle_tree::traversal::{SubTreeTrait, UnmodifiedChildTraversal}; |
| 4 | +use starknet_patricia::patricia_merkle_tree::types::{NodeIndex, SortedLeafIndices}; |
| 5 | +use starknet_patricia_storage::db_object::HasStaticPrefix; |
| 6 | +use starknet_patricia_storage::storage_trait::DbKeyPrefix; |
| 7 | + |
| 8 | +pub struct IndexFilledNode<L: Leaf>(pub FilledNode<L, ()>); |
| 9 | + |
| 10 | +pub struct IndexNodeContext { |
| 11 | + pub is_leaf: bool, |
| 12 | +} |
| 13 | + |
| 14 | +pub struct IndexLayoutSubTree<'a> { |
| 15 | + pub sorted_leaf_indices: SortedLeafIndices<'a>, |
| 16 | + pub root_index: NodeIndex, |
| 17 | +} |
| 18 | + |
| 19 | +impl<'a> SubTreeTrait<'a> for IndexLayoutSubTree<'a> { |
| 20 | + type NodeData = (); |
| 21 | + type NodeDeserializeContext = IndexNodeContext; |
| 22 | + |
| 23 | + fn create( |
| 24 | + sorted_leaf_indices: SortedLeafIndices<'a>, |
| 25 | + root_index: NodeIndex, |
| 26 | + _child_data: Self::NodeData, |
| 27 | + ) -> Self { |
| 28 | + Self { sorted_leaf_indices, root_index } |
| 29 | + } |
| 30 | + |
| 31 | + fn get_root_index(&self) -> NodeIndex { |
| 32 | + self.root_index |
| 33 | + } |
| 34 | + |
| 35 | + fn get_sorted_leaf_indices(&self) -> &SortedLeafIndices<'a> { |
| 36 | + &self.sorted_leaf_indices |
| 37 | + } |
| 38 | + |
| 39 | + fn should_traverse_unmodified_child(_data: Self::NodeData) -> UnmodifiedChildTraversal { |
| 40 | + UnmodifiedChildTraversal::Traverse |
| 41 | + } |
| 42 | + |
| 43 | + fn get_root_context(&self) -> Self::NodeDeserializeContext { |
| 44 | + Self::NodeDeserializeContext { is_leaf: self.is_leaf() } |
| 45 | + } |
| 46 | + |
| 47 | + fn get_root_prefix<L: Leaf>( |
| 48 | + &self, |
| 49 | + key_context: &<L as HasStaticPrefix>::KeyContext, |
| 50 | + ) -> DbKeyPrefix { |
| 51 | + L::get_static_prefix(key_context) |
| 52 | + } |
| 53 | + |
| 54 | + fn get_root_suffix(&self) -> Vec<u8> { |
| 55 | + self.root_index.0.to_be_bytes().to_vec() |
| 56 | + } |
| 57 | +} |
0 commit comments