1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::commitment::{CTree, Witness};
use zcash_primitives::merkle_tree::{CommitmentTree, IncrementalWitness};
use zcash_primitives::sapling::Node;

#[allow(dead_code)]
pub fn print_node(n: &Node) {
    println!("{:?}", hex::encode(n.repr));
}

#[allow(dead_code)]
pub fn print_tree(t: &CommitmentTree<Node>) {
    println!("{:?}", t.left.map(|n| hex::encode(n.repr)));
    println!("{:?}", t.right.map(|n| hex::encode(n.repr)));
    for p in t.parents.iter() {
        println!("{:?}", p.map(|n| hex::encode(n.repr)));
    }
}

#[allow(dead_code)]
pub fn print_witness(w: &IncrementalWitness<Node>) {
    println!("Tree");
    print_tree(&w.tree);
    println!("Filled");
    for n in w.filled.iter() {
        print_node(n);
    }
    println!("Cursor");
    w.cursor.as_ref().map(print_tree);
}

pub fn print_ctree(t: &CTree) {
    println!("Tree");
    println!("{:?}", t.left.map(|n| hex::encode(n.repr)));
    println!("{:?}", t.right.map(|n| hex::encode(n.repr)));
    for p in t.parents.iter() {
        println!("{:?}", p.map(|n| hex::encode(n.repr)));
    }
}

#[allow(dead_code)]
pub fn print_witness2(w: &Witness) {
    let t = &w.tree;
    print_ctree(t);
    println!("Filled");
    for n in w.filled.iter() {
        print_node(n);
    }
    let t = &w.cursor;
    println!("Cursor");
    println!("{:?}", t.left.map(|n| hex::encode(n.repr)));
    println!("{:?}", t.right.map(|n| hex::encode(n.repr)));
    for p in t.parents.iter() {
        println!("{:?}", p.map(|n| hex::encode(n.repr)));
    }
}