MCPcopy Create free account
hub / github.com/base/base / open

Method open

crates/proof/mpt/src/node.rs:153–182  ·  view source on GitHub ↗

Walks down the trie to a leaf value with the given key, if it exists. Preimages for blinded nodes along the path are fetched using the `fetcher` function, and persisted in the inner [`TrieNode`] elements. ## Takes - `self` - The root trie node - `path` - The nibbles representation of the path to the leaf node - `fetcher` - The preimage fetcher for intermediate blinded nodes ## Returns - `Err(_)`

(
        &'a mut self,
        path: &Nibbles,
        fetcher: &F,
    )

Source from the content-addressed store, hash-verified

151 /// - `Ok(None)` - The node with the given key does not exist in the trie.
152 /// - `Ok(Some(_))` - The value of the node
153 pub fn open<'a, F: TrieProvider>(
154 &'a mut self,
155 path: &Nibbles,
156 fetcher: &F,
157 ) -> TrieNodeResult<Option<&'a mut Bytes>> {
158 match self {
159 Self::Branch { stack } => {
160 let branch_nibble = path.get(0).ok_or(TrieNodeError::PathTooShort)? as usize;
161 stack
162 .get_mut(branch_nibble)
163 .map(|node| node.open(&path.slice(BRANCH_NODE_NIBBLES..), fetcher))
164 .unwrap_or(Ok(None))
165 }
166 Self::Leaf { prefix, value } => Ok((path == prefix).then_some(value)),
167 Self::Extension { prefix, node } => {
168 if path.slice(..prefix.len()) == *prefix {
169 // Follow extension branch
170 node.unblind(fetcher)?;
171 node.open(&path.slice(prefix.len()..), fetcher)
172 } else {
173 Ok(None)
174 }
175 }
176 Self::Blinded { .. } => {
177 self.unblind(fetcher)?;
178 self.open(path, fetcher)
179 }
180 Self::Empty => Ok(None),
181 }
182 }
183
184 /// Inserts a [`TrieNode`] at the given path into the trie rooted at Self.
185 ///

Callers 8

render_reportFunction · 0.45
eip_2935_history_lookupFunction · 0.45
get_trie_accountMethod · 0.45
storageMethod · 0.45
trieFunction · 0.45
write_to_pathMethod · 0.45
download_archiveMethod · 0.45

Calls 4

unblindMethod · 0.80
getMethod · 0.45
get_mutMethod · 0.45
lenMethod · 0.45

Tested by 1