From 3efe511cc6494d22de1baddb2b81e760e7eea93b Mon Sep 17 00:00:00 2001 From: Tamas Blummer Date: Sun, 11 Feb 2018 19:35:51 +0100 Subject: [PATCH] add difficulty calculation --- src/blockdata/block.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/blockdata/block.rs b/src/blockdata/block.rs index 3e6ac893..2a7bdedb 100644 --- a/src/blockdata/block.rs +++ b/src/blockdata/block.rs @@ -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.