Use iterators in construct_mmr_tree

This commit is contained in:
Jack Grigg 2019-12-05 11:06:26 +00:00
parent 9ea0427678
commit fb8c73c950
No known key found for this signature in database
GPG Key ID: 9E8255172BBF9898
1 changed files with 10 additions and 24 deletions

View File

@ -1199,31 +1199,17 @@ fn construct_mmr_tree(
) )
}; };
let mut peaks = Vec::new(); let mut peaks: Vec<_> = indices
for i in 0..p_len { .iter()
peaks.push(( .zip(nodes.iter())
indices[i], .map(
match MMREntry::from_bytes(cbranch, &nodes[i][..]) { |(index, node)| match MMREntry::from_bytes(cbranch, &node[..]) {
Ok(entry) => entry, Ok(entry) => Ok((*index, entry)),
_ => { Err(_) => Err("Invalid encoding"),
return Err("Invalid encoding");
} // error
}, },
)); )
} .collect::<Result<_, _>>()?;
let extra = peaks.split_off(p_len);
let mut extra = Vec::new();
for i in p_len..(p_len + e_len) {
extra.push((
indices[i],
match MMREntry::from_bytes(cbranch, &nodes[i][..]) {
Ok(entry) => entry,
_ => {
return Err("Invalid encoding");
} // error
},
));
}
Ok(MMRTree::new(t_len, peaks, extra)) Ok(MMRTree::new(t_len, peaks, extra))
} }