|
1 | 1 | use std::collections::HashMap; |
2 | 2 |
|
3 | 3 | use starknet_api::core::{ClassHash, ContractAddress, Nonce}; |
| 4 | +use starknet_api::hash::HashOutput; |
4 | 5 | use starknet_patricia::patricia_merkle_tree::node_data::leaf::{LeafModifications, SkeletonLeaf}; |
5 | 6 | use starknet_patricia::patricia_merkle_tree::types::NodeIndex; |
| 7 | +use starknet_patricia::patricia_merkle_tree::updated_skeleton_tree::node::UpdatedSkeletonNode; |
6 | 8 | use starknet_patricia::patricia_merkle_tree::updated_skeleton_tree::tree::{ |
7 | 9 | UpdatedSkeletonTree, |
8 | 10 | UpdatedSkeletonTreeImpl, |
@@ -96,4 +98,35 @@ impl UpdatedSkeletonForest { |
96 | 98 | SkeletonLeaf::NonZero |
97 | 99 | } |
98 | 100 | } |
| 101 | + |
| 102 | + pub(crate) fn siblings(&self) -> Siblings { |
| 103 | + Siblings { |
| 104 | + classes_trie: Self::filter_siblings(&self.classes_trie), |
| 105 | + contracts_trie: Self::filter_siblings(&self.contracts_trie), |
| 106 | + storage_tries: self |
| 107 | + .storage_tries |
| 108 | + .iter() |
| 109 | + .map(|(address, trie)| (*address, Self::filter_siblings(trie))) |
| 110 | + .collect(), |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + fn filter_siblings(skeleton_tree: &UpdatedSkeletonTreeImpl) -> HashMap<NodeIndex, HashOutput> { |
| 115 | + skeleton_tree |
| 116 | + .get_nodes() |
| 117 | + .filter_map(|(index, node)| match node { |
| 118 | + UpdatedSkeletonNode::UnmodifiedSubTree(hash) => Some((index, hash)), |
| 119 | + _ => None, |
| 120 | + }) |
| 121 | + .collect() |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +pub(crate) struct Siblings { |
| 126 | + #[allow(dead_code)] |
| 127 | + pub(crate) classes_trie: HashMap<NodeIndex, HashOutput>, |
| 128 | + #[allow(dead_code)] |
| 129 | + pub(crate) contracts_trie: HashMap<NodeIndex, HashOutput>, |
| 130 | + #[allow(dead_code)] |
| 131 | + pub(crate) storage_tries: HashMap<ContractAddress, HashMap<NodeIndex, HashOutput>>, |
99 | 132 | } |
0 commit comments