add difficulty calculation
This commit is contained in:
parent
19f96fe62c
commit
3efe511cc6
|
@ -28,7 +28,9 @@ use util::hash::Sha256dHash;
|
||||||
use util::uint::Uint256;
|
use util::uint::Uint256;
|
||||||
use network::encodable::VarInt;
|
use network::encodable::VarInt;
|
||||||
use network::serialize::BitcoinHash;
|
use network::serialize::BitcoinHash;
|
||||||
|
use network::constants::Network;
|
||||||
use blockdata::transaction::Transaction;
|
use blockdata::transaction::Transaction;
|
||||||
|
use blockdata::constants::max_target;
|
||||||
|
|
||||||
/// A block header, which contains all the block's information except
|
/// A block header, which contains all the block's information except
|
||||||
/// the actual transactions
|
/// 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
|
/// 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
|
/// is correct, but does not verify that the transactions are valid or encoded
|
||||||
/// correctly.
|
/// correctly.
|
||||||
|
|
Loading…
Reference in New Issue