From efb9bfa5deec58d5e92d0132448ebb284a4b8358 Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 16 Oct 2020 06:50:08 +1000 Subject: [PATCH] Merge pull request #1165 from teor2345/difficulty-tidy Tidy some difficulty code --- zebra-chain/src/work/difficulty.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/zebra-chain/src/work/difficulty.rs b/zebra-chain/src/work/difficulty.rs index 86f57def..bc38bd0e 100644 --- a/zebra-chain/src/work/difficulty.rs +++ b/zebra-chain/src/work/difficulty.rs @@ -236,10 +236,10 @@ impl CompactDifficulty { // `((2^256 - expanded - 1) / (expanded + 1)) + 1`, or let result = (!expanded.0 / (expanded.0 + 1)) + 1; if result <= u128::MAX.into() { - return Some(Work(result.as_u128())); + Work(result.as_u128()).into() + } else { + None } - - None } } @@ -316,14 +316,15 @@ impl PartialOrd for block::Hash { use Ordering::*; // Use the base implementation, but reverse the order. - match other.partial_cmp(self) { - Some(Less) => Some(Greater), - Some(Greater) => Some(Less), - Some(Equal) => Some(Equal), - None => unreachable!( - "Unexpected incomparable values: difficulties and hashes have a total order." - ), + match other + .partial_cmp(self) + .expect("difficulties and hashes have a total order") + { + Less => Greater, + Greater => Less, + Equal => Equal, } + .into() } }