pub struct Target(/* private fields */);Expand description
A 256-bit proof-of-work target, big-endian.
Implementations§
Source§impl Target
impl Target
Sourcepub const fn from_be_bytes(bytes: [u8; 32]) -> Self
pub const fn from_be_bytes(bytes: [u8; 32]) -> Self
A target from its 32 big-endian bytes.
Sourcepub const fn to_be_bytes(self) -> [u8; 32]
pub const fn to_be_bytes(self) -> [u8; 32]
The 32 big-endian bytes.
Sourcepub fn from_hex(s: &str) -> Result<Self, Error>
pub fn from_hex(s: &str) -> Result<Self, Error>
A target from 64 hex characters, most significant first — the form a
chain document’s powLimit takes (SPEC 3).
use sidestr_header::Target;
let lim = Target::from_hex("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap();
assert_eq!(lim.to_compact(), 0x207f_ffff);Sourcepub fn from_compact(bits: u32) -> Result<Self, Error>
pub fn from_compact(bits: u32) -> Result<Self, Error>
Expands compact bits (Core’s SetCompact): the low 23 bits are the
mantissa, the top byte the size in bytes of the big-endian number the
mantissa is the leading three bytes of.
use sidestr_header::Target;
// Bitcoin's genesis bits.
let t = Target::from_compact(0x1d00_ffff).unwrap();
assert_eq!(hex::encode(t.to_be_bytes()),
"00000000ffff0000000000000000000000000000000000000000000000000000");
// A well-known Core example: 0x1b0404cb.
let t = Target::from_compact(0x1b04_04cb).unwrap();
assert_eq!(hex::encode(t.to_be_bytes()),
"00000000000404cb000000000000000000000000000000000000000000000000");Sourcepub fn to_compact(self) -> u32
pub fn to_compact(self) -> u32
Compact-encodes the target (Core’s GetCompact, the kernel’s
compactFromTarget), including the mantissa truncation that makes the
encoding lossy: from_compact(t.to_compact()) keeps only the three
most significant bytes of t.
use sidestr_header::Target;
assert_eq!(Target::from_compact(0x1d00_ffff).unwrap().to_compact(), 0x1d00_ffff);
assert_eq!(Target::MAX.to_compact(), 0x2100_ffff); // top byte 0xff would read as a sign bitTrait Implementations§
impl Copy for Target
impl Eq for Target
Source§impl Ord for Target
impl Ord for Target
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for Target
impl PartialOrd for Target
impl StructuralPartialEq for Target
Auto Trait Implementations§
impl Freeze for Target
impl RefUnwindSafe for Target
impl Send for Target
impl Sync for Target
impl Unpin for Target
impl UnsafeUnpin for Target
impl UnwindSafe for Target
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.