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 {