Function tallytree::proof::util::find_node_index [−][src]
pub fn find_node_index(
reference: &VoteReference,
leaf_branch: &ProofBranch,
directions: &[TraverseDirection]
) -> Result<usize, String>
Expand description
Find the index of a vote in a merkle tree using the merkle proof for the vote.
Use collapse_branches
on the proof to get the directions parameter.
leaf_branch
is the zero-indexed branch in the merkle proof.
Example:
use tallytree::proof::util::{collapse_branches, create_merkle_proof, CollapseBranchConstrains, find_node_index};
use tallytree::navigate::find_node_by_vote_reference;
use tallytree::{Validation, VoteReference};
use tallytree::generate::generate_tree;
let tree = generate_tree(vec![
([0xaa; 32], vec![1, 0]),
([0xbb; 32], vec![1, 0]),
([0xcc; 32], vec![0, 1]),
], true).unwrap();
let v = &Validation::Strict;
let proof = create_merkle_proof(
&find_node_by_vote_reference(&tree, &[0xbb; 32]).unwrap(),
v
).unwrap();
let ((_, _), directions) = collapse_branches(
proof.branches.clone(),
&CollapseBranchConstrains::None,
v
).unwrap();
assert_eq!(1, find_node_index(&[0xbb; 32], &proof.branches[0], &directions).unwrap());