feat(trie): add leaf value retrieval methods to SparseStateTrie (#13750)

This commit is contained in:
Roman Krasiuk
2025-01-09 12:40:45 +01:00
committed by GitHub
parent 383eb2331c
commit 017217f3eb
2 changed files with 19 additions and 0 deletions

View File

@ -97,6 +97,16 @@ impl<F: BlindedProviderFactory> SparseStateTrie<F> {
self.revealed.get(account).is_some_and(|slots| slots.contains(slot))
}
/// Returns reference to bytes representing leaf value for the target account.
pub fn get_account_value(&self, account: &B256) -> Option<&Vec<u8>> {
self.state.as_revealed_ref()?.get_leaf_value(&Nibbles::unpack(account))
}
/// Returns reference to bytes representing leaf value for the target account and storage slot.
pub fn get_storage_slot_value(&self, account: &B256, slot: &B256) -> Option<&Vec<u8>> {
self.storages.get(account)?.as_revealed_ref()?.get_leaf_value(&Nibbles::unpack(slot))
}
/// Returns mutable reference to storage sparse trie if it was revealed.
pub fn storage_trie_mut(
&mut self,

View File

@ -72,6 +72,15 @@ impl<P> SparseTrie<P> {
matches!(self, Self::Blind)
}
/// Returns reference to revealed sparse trie if the trie is not blind.
pub fn as_revealed_ref(&self) -> Option<&RevealedSparseTrie<P>> {
if let Self::Revealed(revealed) = self {
Some(revealed)
} else {
None
}
}
/// Returns mutable reference to revealed sparse trie if the trie is not blind.
pub fn as_revealed_mut(&mut self) -> Option<&mut RevealedSparseTrie<P>> {
if let Self::Revealed(revealed) = self {