From 578143c09ec84dfe127d5df1f1326e61be5d1646 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 12 Aug 2024 20:12:01 +1000 Subject: [PATCH] Separate CompactTarget impl blocks In preparation for adding an `CompactTargetExt` trait move the primitives methods to a separate impl block. Refactor only, no logic changes. --- bitcoin/src/pow.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bitcoin/src/pow.rs b/bitcoin/src/pow.rs index a9c403220..bbd812faa 100644 --- a/bitcoin/src/pow.rs +++ b/bitcoin/src/pow.rs @@ -347,6 +347,14 @@ do_impl!(Target); #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct CompactTarget(u32); +impl CompactTarget { + /// Creates a [`CompactTarget`] from a consensus encoded `u32`. + pub fn from_consensus(bits: u32) -> Self { Self(bits) } + + /// Returns the consensus encoded `u32` representation of this [`CompactTarget`]. + pub fn to_consensus(self) -> u32 { self.0 } +} + impl CompactTarget { /// Creates a `CompactTarget` from a prefixed hex string. pub fn from_hex(s: &str) -> Result { @@ -435,12 +443,6 @@ impl CompactTarget { let bits = current.bits; CompactTarget::from_next_work_required(bits, timespan.into(), params) } - - /// Creates a [`CompactTarget`] from a consensus encoded `u32`. - pub fn from_consensus(bits: u32) -> Self { Self(bits) } - - /// Returns the consensus encoded `u32` representation of this [`CompactTarget`]. - pub fn to_consensus(self) -> u32 { self.0 } } impl From for Target {