Skip to content

Commit a00bd7c

Browse files
committed
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`.
1 parent 100ce03 commit a00bd7c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

bitcoin/src/pow.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use units::parse::{self, ParseIntError, PrefixedHexError, UnprefixedHexError};
1515

1616
use crate::block::{BlockHash, Header};
1717
use crate::consensus::encode::{self, Decodable, Encodable};
18+
use crate::internal_macros::define_extension_trait;
1819
use crate::network::Params;
1920

2021
/// Implement traits and methods shared by `Target` and `Work`.
@@ -355,18 +356,17 @@ impl CompactTarget {
355356
pub fn to_consensus(self) -> u32 { self.0 }
356357
}
357358

358-
mod tmp {
359-
use super::*;
360-
361-
impl CompactTarget {
359+
define_extension_trait! {
360+
/// Extension functionality for the [`CompactTarget`] type.
361+
pub trait CompactTargetExt impl for CompactTarget {
362362
/// Creates a `CompactTarget` from a prefixed hex string.
363-
pub fn from_hex(s: &str) -> Result<Self, PrefixedHexError> {
363+
fn from_hex(s: &str) -> Result<CompactTarget, PrefixedHexError> {
364364
let target = parse::hex_u32_prefixed(s)?;
365365
Ok(Self::from_consensus(target))
366366
}
367367

368368
/// Creates a `CompactTarget` from an unprefixed hex string.
369-
pub fn from_unprefixed_hex(s: &str) -> Result<Self, UnprefixedHexError> {
369+
fn from_unprefixed_hex(s: &str) -> Result<CompactTarget, UnprefixedHexError> {
370370
let target = parse::hex_u32_unprefixed(s)?;
371371
Ok(Self::from_consensus(target))
372372
}
@@ -393,7 +393,7 @@ mod tmp {
393393
/// # Returns
394394
///
395395
/// The expected [`CompactTarget`] recalculation.
396-
pub fn from_next_work_required(
396+
fn from_next_work_required(
397397
last: CompactTarget,
398398
timespan: u64,
399399
params: impl AsRef<Params>,
@@ -437,7 +437,7 @@ mod tmp {
437437
/// # Returns
438438
///
439439
/// The expected [`CompactTarget`] recalculation.
440-
pub fn from_header_difficulty_adjustment(
440+
fn from_header_difficulty_adjustment(
441441
last_epoch_boundary: Header,
442442
current: Header,
443443
params: impl AsRef<Params>,

0 commit comments

Comments
 (0)