Skip to content

Commit

Permalink
Rename simple_hash_from_byte_slices to simple_hash_from_byte_vectors
Browse files Browse the repository at this point in the history
The method that computes the root from arbitrary given bytes doesn't
take slices but Rust's array-type: vector. Also, update comment.
  • Loading branch information
liamsi committed Nov 16, 2019
1 parent b4478b8 commit 937ba67
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions tendermint/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ pub const HASH_SIZE: usize = 32;
/// Hash is the output of the cryptographic digest function
pub type Hash = [u8; HASH_SIZE];

/// Compute a simple Merkle root from the arbitrary byte arrays
pub fn simple_hash_from_byte_slices(byte_slices: Vec<Vec<u8>>) -> Hash {
simple_hash_from_byte_slices_inner(byte_slices.as_slice())
/// Compute a simple Merkle root from vectors of arbitrary byte vectors.
/// The leaves of the tree are the bytes of the given byte vectors in
/// the given order.
pub fn simple_hash_from_byte_vectors(byte_vecs: Vec<Vec<u8>>) -> Hash {
simple_hash_from_byte_slices_inner(byte_vecs.as_slice())
}

// recurse into subtrees
Expand Down Expand Up @@ -97,7 +99,7 @@ mod tests {
let empty_leaf_root = &hex::decode(empty_leaf_root_hex).unwrap();
let empty_tree: Vec<Vec<u8>> = vec![vec![]; 1];

let root = simple_hash_from_byte_slices(empty_tree);
let root = simple_hash_from_byte_vectors(empty_tree);
assert_eq!(empty_leaf_root, &root);
}

Expand All @@ -109,7 +111,7 @@ mod tests {
let leaf_root = &hex::decode(leaf_root_hex).unwrap();
let leaf_tree: Vec<Vec<u8>> = vec![leaf_string.as_bytes().to_vec(); 1];

let root = simple_hash_from_byte_slices(leaf_tree);
let root = simple_hash_from_byte_vectors(leaf_tree);
assert_eq!(leaf_root, &root);
}

Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Set {
.into_iter()
.map(|x| x.hash_bytes())
.collect();
merkle::simple_hash_from_byte_slices(validator_bytes)
merkle::simple_hash_from_byte_vectors(validator_bytes)
}
}

Expand Down

0 comments on commit 937ba67

Please sign in to comment.