replaced match with if to shorten the code

This commit is contained in:
debris 2016-02-27 19:27:34 +01:00
parent 1cc719d413
commit 1481f3f477

View File

@ -488,25 +488,24 @@ impl BlockChain {
hash: hash, hash: hash,
number: number, number: number,
total_difficulty: total_difficulty, total_difficulty: total_difficulty,
location: match is_new_best { location: if is_new_best {
false => BlockLocation::Branch, // on new best block we need to make sure that all ancestors
true => { // are moved to "canon chain"
// on new best block we need to make sure that all ancestors // find the route between old best block and the new one
// are moved to "canon chain" let best_hash = self.best_block_hash();
// find the route between old best block and the new one let route = self.tree_route(best_hash, parent_hash);
let best_hash = self.best_block_hash();
let route = self.tree_route(best_hash, parent_hash);
assert_eq!(number, parent_details.number + 1); assert_eq!(number, parent_details.number + 1);
match route.blocks.len() { match route.blocks.len() {
0 => BlockLocation::CanonChain, 0 => BlockLocation::CanonChain,
_ => BlockLocation::BranchBecomingCanonChain { _ => BlockLocation::BranchBecomingCanonChain {
ancestor: route.ancestor, ancestor: route.ancestor,
route: route.blocks.into_iter().skip(route.index).collect() route: route.blocks.into_iter().skip(route.index).collect()
}
} }
} }
} else {
BlockLocation::Branch
} }
} }
} }