Helper function to convert node information to string for printing/writing to file.
(
node: &Node,
page_id: PageId,
buf: &mut W,
indent: &str,
)
| 313 | |
| 314 | /// Helper function to convert node information to string for printing/writing to file. |
| 315 | fn write_node_value<W: io::Write>( |
| 316 | node: &Node, |
| 317 | page_id: PageId, |
| 318 | buf: &mut W, |
| 319 | indent: &str, |
| 320 | ) -> Result<(), Error> { |
| 321 | let prefix = node.prefix(); |
| 322 | match node.kind() { |
| 323 | Branch { ref children } => { |
| 324 | writeln!( |
| 325 | buf, |
| 326 | "{}Branch Node: Page ID: {} Children: [{}], Prefix: {}", |
| 327 | indent, |
| 328 | page_id, |
| 329 | children.iter().enumerate().filter(|(_, child)| child.is_some()).fold( |
| 330 | String::new(), |
| 331 | |mut s, (i, _)| { |
| 332 | if !s.is_empty() { |
| 333 | s.push_str(", ") |
| 334 | }; |
| 335 | s.push_str(&i.to_string()); |
| 336 | s |
| 337 | } |
| 338 | ), |
| 339 | alloy_primitives::hex::encode(prefix.pack()) |
| 340 | )?; |
| 341 | Ok(()) |
| 342 | } |
| 343 | AccountLeaf { .. } => { |
| 344 | match node.value() { |
| 345 | Ok(TrieValue::Account(acct)) => { |
| 346 | writeln!( |
| 347 | buf, |
| 348 | "{}AccountLeaf: nonce: {:?}, balance: {:?}, prefix: {}, code_hash: {:x?}, storage_root: {:?}", |
| 349 | indent, |
| 350 | acct.nonce, acct.balance, alloy_primitives::hex::encode(prefix.pack()), acct.code_hash, acct.storage_root, |
| 351 | )?; |
| 352 | } |
| 353 | _ => { |
| 354 | writeln!(buf, "{indent}AccountLeaf: no value ")?; |
| 355 | } |
| 356 | }; |
| 357 | Ok(()) |
| 358 | } |
| 359 | StorageLeaf { .. } => { |
| 360 | match node.value() { |
| 361 | Ok(TrieValue::Storage(strg)) => { |
| 362 | let str_prefix = alloy_primitives::hex::encode(prefix.pack()); |
| 363 | writeln!( |
| 364 | buf, |
| 365 | "{indent}StorageLeaf: storage: {strg:?}, prefix: {str_prefix}" |
| 366 | )?; |
| 367 | } |
| 368 | _ => { |
| 369 | writeln!(buf, "{indent}StorageLeaf: no value")?; |
| 370 | } |
| 371 | }; |
| 372 | Ok(()) |