From 937ba676fd4fb996c1c2f2c086bf3e8b513ebc3d Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Sat, 16 Nov 2019 12:34:29 +0100 Subject: [PATCH] Rename simple_hash_from_byte_slices to simple_hash_from_byte_vectors The method that computes the root from arbitrary given bytes doesn't take slices but Rust's array-type: vector. Also, update comment. --- tendermint/src/merkle.rs | 12 +++++++----- tendermint/src/validator.rs | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tendermint/src/merkle.rs b/tendermint/src/merkle.rs index e289d73a8..f34f0cc5f 100644 --- a/tendermint/src/merkle.rs +++ b/tendermint/src/merkle.rs @@ -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>) -> 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>) -> Hash { + simple_hash_from_byte_slices_inner(byte_vecs.as_slice()) } // recurse into subtrees @@ -97,7 +99,7 @@ mod tests { let empty_leaf_root = &hex::decode(empty_leaf_root_hex).unwrap(); let empty_tree: Vec> = 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); } @@ -109,7 +111,7 @@ mod tests { let leaf_root = &hex::decode(leaf_root_hex).unwrap(); let leaf_tree: Vec> = 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); } diff --git a/tendermint/src/validator.rs b/tendermint/src/validator.rs index 8cafe386e..f936de8a9 100644 --- a/tendermint/src/validator.rs +++ b/tendermint/src/validator.rs @@ -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) } }