Cleanup slice verification

This commit is contained in:
Greg Fitzgerald 2018-02-14 13:02:39 -07:00
parent d23fda1936
commit 8ff8e90c5e
1 changed files with 2 additions and 8 deletions

View File

@ -49,13 +49,7 @@ impl Tick {
/// assert!(!verify_slice(&vec![Tick::new(0, 0), Tick::new(1, 0)], 0)); // lazy inductive case, bad
/// ```
pub fn verify_slice(ticks: &[Tick], seed: u64) -> bool {
// Verify the first item against the seed.
match ticks.first() {
None => return true,
Some(x) if !x.verify(seed) => return false,
Some(_) => (),
}
// Verify all follow items using the hash in the item before it.
let mut tick_pairs = ticks.iter().zip(ticks.iter().skip(1));
let genesis = [Tick { hash: seed, n: 0 }];
let mut tick_pairs = genesis.iter().chain(ticks).zip(ticks);
tick_pairs.all(|(x, x1)| x1.verify(x.hash))
}