mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(trie): add leaf value retrieval methods to SparseStateTrie (#13750)
This commit is contained in:
@ -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,
|
||||
|
||||
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user