mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Slight merkle improvements
This commit is contained in:
@@ -9,7 +9,7 @@ pub(crate) fn merkle(hash_args: &[[u8; 32]]) -> [u8; 32] {
|
|||||||
let zero = [0; 32];
|
let zero = [0; 32];
|
||||||
let mut interim;
|
let mut interim;
|
||||||
while hashes.len() > 1 {
|
while hashes.len() > 1 {
|
||||||
interim = Vec::with_capacity(hashes.len() / 2);
|
interim = Vec::with_capacity((hashes.len() + 1) / 2);
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < hashes.len() {
|
while i < hashes.len() {
|
||||||
@@ -33,9 +33,5 @@ pub(crate) fn merkle(hash_args: &[[u8; 32]]) -> [u8; 32] {
|
|||||||
hashes = interim;
|
hashes = interim;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut res = zero;
|
hashes.get(0).copied().map(Into::into).unwrap_or(zero)
|
||||||
if let Some(hash) = hashes.get(0) {
|
|
||||||
res.copy_from_slice(hash.as_ref());
|
|
||||||
}
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user