Merge pull request #1165 from teor2345/difficulty-tidy
Tidy some difficulty code
This commit is contained in:
parent
de04e76564
commit
efb9bfa5de
|
@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue