Creates a new account leaf or storage leaf [Node] from a [Nibbles] prefix and a [TrieValue]. # Panics This function will panic if the provided prefix is greater than 64 nibbles long.
(prefix: &RawPath, value: &TrieValue)
| 80 | /// |
| 81 | /// This function will panic if the provided prefix is greater than 64 nibbles long. |
| 82 | pub fn new_leaf(prefix: &RawPath, value: &TrieValue) -> Result<Self, NodeError> { |
| 83 | let prefix = prefix.try_into().map_err(|_| NodeError::MaxPrefixLengthExceeded)?; |
| 84 | |
| 85 | match value { |
| 86 | TrieValue::Account(account) => Ok(Self::new_account_leaf( |
| 87 | prefix, |
| 88 | encode_fixed_size(&account.balance), |
| 89 | encode_fixed_size(&account.nonce), |
| 90 | account.code_hash, |
| 91 | None, |
| 92 | )), |
| 93 | TrieValue::Storage(storage) => { |
| 94 | Ok(Self::new_storage_leaf(prefix, encode_fixed_size(storage))) |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | fn new_account_leaf( |
| 100 | prefix: Nibbles, |