hashTreeToString function

String hashTreeToString(
  1. List tree
)

Make a human readable string out of a hash tree. @param tree

Implementation

String hashTreeToString(List tree) {
  String indent(String s) => s.split('\n').map((x) => '  $x').join('\n');

  switch (tree[0]) {
    case 0:
      return '()';
    case 1:
      final left = hashTreeToString(tree[1] as List);
      final right = hashTreeToString(tree[2] as List);
      return 'sub(\n left:\n${indent(left)}\n---\n right:\n${indent(right)}\n)';
    case 2:
      final label = u8aToString(tree[1] as Uint8List, useDartEncode: true);
      final sub = hashTreeToString(tree[2] as List);
      return 'label(\n label:\n${indent(label)}\n sub:\n${indent(sub)}\n)';
    case 3:
      return 'leaf(...${(tree[1] as Uint8List).lengthInBytes} bytes)';
    case 4:
      return 'pruned(${blobToHex(tree[1] as Uint8List)}';
    default:
      return 'unknown(${jsonEncode(tree[0])})';
  }
}