mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(trie): sparse trie accessors (#13815)
This commit is contained in:
@ -105,6 +105,19 @@ impl<F: BlindedProviderFactory> SparseStateTrie<F> {
|
||||
self.storages.get(account)?.as_revealed_ref()?.get_leaf_value(&Nibbles::unpack(slot))
|
||||
}
|
||||
|
||||
/// Returns reference to state trie if it was revealed.
|
||||
pub const fn state_trie_ref(&self) -> Option<&RevealedSparseTrie<F::AccountNodeProvider>> {
|
||||
self.state.as_revealed_ref()
|
||||
}
|
||||
|
||||
/// Returns reference to storage trie if it was revealed.
|
||||
pub fn storage_trie_ref(
|
||||
&self,
|
||||
address: &B256,
|
||||
) -> Option<&RevealedSparseTrie<F::StorageNodeProvider>> {
|
||||
self.storages.get(address).and_then(|e| e.as_revealed_ref())
|
||||
}
|
||||
|
||||
/// Returns mutable reference to storage sparse trie if it was revealed.
|
||||
pub fn storage_trie_mut(
|
||||
&mut self,
|
||||
|
||||
@ -288,6 +288,11 @@ impl<P> RevealedSparseTrie<P> {
|
||||
self.updates.as_ref().map_or(Cow::Owned(SparseTrieUpdates::default()), Cow::Borrowed)
|
||||
}
|
||||
|
||||
/// Returns reference to all trie nodes.
|
||||
pub const fn nodes_ref(&self) -> &HashMap<Nibbles, SparseNode> {
|
||||
&self.nodes
|
||||
}
|
||||
|
||||
/// Returns a reference to the leaf value if present.
|
||||
pub fn get_leaf_value(&self, path: &Nibbles) -> Option<&Vec<u8>> {
|
||||
self.values.get(path)
|
||||
@ -1130,8 +1135,7 @@ impl<P: BlindedProvider> RevealedSparseTrie<P> {
|
||||
|
||||
new_node
|
||||
}
|
||||
// If more than one child is left set in the branch, we just re-insert it
|
||||
// as-is.
|
||||
// If more than one child is left set in the branch, we just re-insert it as-is.
|
||||
else {
|
||||
SparseNode::new_branch(state_mask)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user