Merge pull request #1165 from teor2345/difficulty-tidy

Tidy some difficulty code
This commit is contained in:
teor 2020-10-16 06:50:08 +10:00 committed by GitHub
parent de04e76564
commit efb9bfa5de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 10 deletions

View File

@ -236,10 +236,10 @@ impl CompactDifficulty {
// `((2^256 - expanded - 1) / (expanded + 1)) + 1`, or // `((2^256 - expanded - 1) / (expanded + 1)) + 1`, or
let result = (!expanded.0 / (expanded.0 + 1)) + 1; let result = (!expanded.0 / (expanded.0 + 1)) + 1;
if result <= u128::MAX.into() { 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<ExpandedDifficulty> for block::Hash {
use Ordering::*; use Ordering::*;
// Use the base implementation, but reverse the order. // Use the base implementation, but reverse the order.
match other.partial_cmp(self) { match other
Some(Less) => Some(Greater), .partial_cmp(self)
Some(Greater) => Some(Less), .expect("difficulties and hashes have a total order")
Some(Equal) => Some(Equal), {
None => unreachable!( Less => Greater,
"Unexpected incomparable values: difficulties and hashes have a total order." Greater => Less,
), Equal => Equal,
} }
.into()
} }
} }