Slight merkle improvements

This commit is contained in:
Luke Parker 2023-04-11 19:04:27 -04:00
parent 4d17b922fe
commit 90f67b5e54
No known key found for this signature in database

View file

@ -9,7 +9,7 @@ pub(crate) fn merkle(hash_args: &[[u8; 32]]) -> [u8; 32] {
let zero = [0; 32];
let mut interim;
while hashes.len() > 1 {
interim = Vec::with_capacity(hashes.len() / 2);
interim = Vec::with_capacity((hashes.len() + 1) / 2);
let mut i = 0;
while i < hashes.len() {
@ -33,9 +33,5 @@ pub(crate) fn merkle(hash_args: &[[u8; 32]]) -> [u8; 32] {
hashes = interim;
}
let mut res = zero;
if let Some(hash) = hashes.get(0) {
res.copy_from_slice(hash.as_ref());
}
res
hashes.get(0).copied().map(Into::into).unwrap_or(zero)
}