From a00bd7cc4dd891858c05a688e72b6463b84f7d22 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 16 Jul 2024 08:42:28 +1000 Subject: [PATCH] Introduce CompactTargetExt trait In preparation for moving the `CompactTarget` type to `primitives` introduce an extension trait for code that will be left behind in `bitcoin`. --- bitcoin/src/pow.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bitcoin/src/pow.rs b/bitcoin/src/pow.rs index 2afc5b8c2..aa986a24b 100644 --- a/bitcoin/src/pow.rs +++ b/bitcoin/src/pow.rs @@ -15,6 +15,7 @@ use units::parse::{self, ParseIntError, PrefixedHexError, UnprefixedHexError}; use crate::block::{BlockHash, Header}; use crate::consensus::encode::{self, Decodable, Encodable}; +use crate::internal_macros::define_extension_trait; use crate::network::Params; /// Implement traits and methods shared by `Target` and `Work`. @@ -355,18 +356,17 @@ impl CompactTarget { pub fn to_consensus(self) -> u32 { self.0 } } -mod tmp { - use super::*; - - impl CompactTarget { +define_extension_trait! { + /// Extension functionality for the [`CompactTarget`] type. + pub trait CompactTargetExt impl for CompactTarget { /// Creates a `CompactTarget` from a prefixed hex string. - pub fn from_hex(s: &str) -> Result { + fn from_hex(s: &str) -> Result { let target = parse::hex_u32_prefixed(s)?; Ok(Self::from_consensus(target)) } /// Creates a `CompactTarget` from an unprefixed hex string. - pub fn from_unprefixed_hex(s: &str) -> Result { + fn from_unprefixed_hex(s: &str) -> Result { let target = parse::hex_u32_unprefixed(s)?; Ok(Self::from_consensus(target)) } @@ -393,7 +393,7 @@ mod tmp { /// # Returns /// /// The expected [`CompactTarget`] recalculation. - pub fn from_next_work_required( + fn from_next_work_required( last: CompactTarget, timespan: u64, params: impl AsRef, @@ -437,7 +437,7 @@ mod tmp { /// # Returns /// /// The expected [`CompactTarget`] recalculation. - pub fn from_header_difficulty_adjustment( + fn from_header_difficulty_adjustment( last_epoch_boundary: Header, current: Header, params: impl AsRef,