From 02a2b43b2b0729aa7b18afbdc90be8654a959790 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 30 Sep 2022 09:16:56 +1000 Subject: [PATCH] Remove Default impl for Target and Work A zero default value for `Target` and `Work` has no significance and/or usecase, remove the derived `Default` implementation. Includes making `Target::ZERO` public. --- bitcoin/src/blockdata/block.rs | 2 +- bitcoin/src/pow.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs index 1dd8a290..1fa7bc1b 100644 --- a/bitcoin/src/blockdata/block.rs +++ b/bitcoin/src/blockdata/block.rs @@ -513,7 +513,7 @@ mod tests { assert_eq!(some_header.validate_pow(some_header.target()).unwrap(), some_header.block_hash()); // test with zero target - match some_header.validate_pow(Target::default()) { + match some_header.validate_pow(Target::ZERO) { Err(BlockBadTarget) => (), _ => panic!("unexpected result from validate_pow"), } diff --git a/bitcoin/src/pow.rs b/bitcoin/src/pow.rs index c1bd127c..f267d349 100644 --- a/bitcoin/src/pow.rs +++ b/bitcoin/src/pow.rs @@ -90,7 +90,7 @@ macro_rules! do_impl { /// Work is a measure of how difficult it is to find a hash below a given [`Target`]. /// /// ref: -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] pub struct Work(U256); @@ -130,14 +130,14 @@ impl Sub for Work { /// a block. (See also [`Work`].) /// /// ref: -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] pub struct Target(U256); impl Target { - // When parsing nBits, Bitcoin Core converts a negative target threshold into a target of zero. - const ZERO: Target = Target(U256::ZERO); + /// When parsing nBits, Bitcoin Core converts a negative target threshold into a target of zero. + pub const ZERO: Target = Target(U256::ZERO); /// The maximum possible target. /// /// This value is used to calculate difficulty, which is defined as how difficult the current