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.
This commit is contained in:
Tobin C. Harding 2024-08-12 20:12:01 +10:00
parent 22d5646f7b
commit 578143c09e
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 8 additions and 6 deletions

View File

@ -347,6 +347,14 @@ do_impl!(Target);
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct CompactTarget(u32); 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 { impl CompactTarget {
/// Creates a `CompactTarget` from a prefixed hex string. /// Creates a `CompactTarget` from a prefixed hex string.
pub fn from_hex(s: &str) -> Result<Self, PrefixedHexError> { pub fn from_hex(s: &str) -> Result<Self, PrefixedHexError> {
@ -435,12 +443,6 @@ impl CompactTarget {
let bits = current.bits; let bits = current.bits;
CompactTarget::from_next_work_required(bits, timespan.into(), params) 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<CompactTarget> for Target { impl From<CompactTarget> for Target {