Merge pull request #44 from tamasblummer/add_difficulty2
Add difficulty calculation
This commit is contained in:
commit
71bce7b067
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue