Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(trie): add helpers to return trie keys as variants #9075

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions crates/trie/trie/src/updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,35 @@ pub enum TrieKey {
StorageTrie(B256),
}

impl TrieKey {
/// Returns reference to account node key if the key is for [`Self::AccountNode`].
pub const fn as_account_node_key(&self) -> Option<&StoredNibbles> {
if let Self::AccountNode(nibbles) = &self {
Some(nibbles)
} else {
None
}
}

/// Returns reference to storage node key if the key is for [`Self::StorageNode`].
pub const fn as_storage_node_key(&self) -> Option<(&B256, &StoredNibblesSubKey)> {
if let Self::StorageNode(key, subkey) = &self {
Some((key, subkey))
} else {
None
}
}

/// Returns reference to storage trie key if the key is for [`Self::StorageTrie`].
pub const fn as_storage_trie_key(&self) -> Option<&B256> {
if let Self::StorageTrie(key) = &self {
Some(key)
} else {
None
}
}
}

/// The operation to perform on the trie.
#[derive(PartialEq, Eq, Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down
Loading