Minor: move raw_difficulty to Proof

This commit is contained in:
Ignotus Peverell 2018-09-19 18:30:52 +00:00
parent 521ce901e4
commit 7b6e219b5b
No known key found for this signature in database
GPG key ID: 99CD25F39F8F8211

View file

@ -60,7 +60,7 @@ impl Difficulty {
let shift = proof.cuckoo_sizeshift; let shift = proof.cuckoo_sizeshift;
let adjust_factor = (1 << (shift - global::ref_sizeshift()) as u64) * (shift as u64 - 1); let adjust_factor = (1 << (shift - global::ref_sizeshift()) as u64) * (shift as u64 - 1);
Difficulty::from_num(Difficulty::raw_difficulty(proof) * adjust_factor) Difficulty::from_num(proof.raw_difficulty() * adjust_factor)
} }
/// Same as `from_proof_adjusted` but instead of an adjustment based on /// Same as `from_proof_adjusted` but instead of an adjustment based on
@ -68,11 +68,7 @@ impl Difficulty {
/// to scale one PoW against the other. /// to scale one PoW against the other.
pub fn from_proof_scaled(proof: &Proof, scaling: u64) -> Difficulty { pub fn from_proof_scaled(proof: &Proof, scaling: u64) -> Difficulty {
// Scaling between 2 proof of work algos // Scaling between 2 proof of work algos
Difficulty::from_num(Difficulty::raw_difficulty(proof) * scaling) Difficulty::from_num(proof.raw_difficulty() * scaling)
}
fn raw_difficulty(proof: &Proof) -> u64 {
<u64>::max_value() / proof.hash().to_u64()
} }
/// Converts the difficulty into a u64 /// Converts the difficulty into a u64
@ -344,6 +340,11 @@ impl Proof {
pub fn proof_size(&self) -> usize { pub fn proof_size(&self) -> usize {
self.nonces.len() self.nonces.len()
} }
/// Difficulty achieved by this proof
fn raw_difficulty(&self) -> u64 {
<u64>::max_value() / self.hash().to_u64()
}
} }
impl Readable for Proof { impl Readable for Proof {