add difficulty calculation

This commit is contained in:
Tamas Blummer 2018-02-11 19:35:51 +01:00
parent 19f96fe62c
commit 3efe511cc6
1 changed files with 7 additions and 0 deletions

View File

@ -28,7 +28,9 @@ use util::hash::Sha256dHash;
use util::uint::Uint256;
use network::encodable::VarInt;
use network::serialize::BitcoinHash;
use network::constants::Network;
use blockdata::transaction::Transaction;
use blockdata::constants::max_target;
/// A block header, which contains all the block's information except
/// the actual transactions
@ -94,6 +96,11 @@ impl BlockHeader {
}
}
/// Compute the popular "difficulty" measure for mining
pub fn difficulty (&self, network: Network) -> u64 {
(max_target(network) / self.target()).low_u64()
}
/// Performs an SPV validation of a block, which confirms that the proof-of-work
/// is correct, but does not verify that the transactions are valid or encoded
/// correctly.