pub struct CompactTarget(/* private fields */);Expand description
Encoding of 256-bit target as 32-bit float.
This is used to encode a target into the block header. Satoshi made this part of consensus code in the original version of Bitcoin, likely copying an idea from OpenSSL.
OpenSSL’s bignum (BN) type has an encoding, which is even called “compact” as in bitcoin, which is exactly this format.
§Note on order/equality
Usage of the ordering and equality traits for this type may be surprising. Converting between
CompactTarget and Target is lossy in both directions (there are multiple CompactTarget
values that map to the same Target value). Ordering and equality for this type are defined in
terms of the underlying u32.
Implementations§
Source§impl CompactTarget
impl CompactTarget
Sourcepub fn from_consensus(bits: u32) -> Self
pub fn from_consensus(bits: u32) -> Self
Constructs a new CompactTarget from a consensus encoded u32.
Sourcepub const fn to_consensus(self) -> u32
pub const fn to_consensus(self) -> u32
Returns the consensus encoded u32 representation of this CompactTarget.
Sourcepub fn to_hex(self) -> String
👎Deprecated since 1.0.0-rc.0: use format!("{var:x}") instead
pub fn to_hex(self) -> String
use format!("{var:x}") instead
Gets the hex representation of this CompactTarget.
Sourcepub fn from_hex(s: &str) -> Result<Self, PrefixedHexError>where
Self: Sized,
pub fn from_hex(s: &str) -> Result<Self, PrefixedHexError>where
Self: Sized,
Constructs a new CompactTarget from a prefixed hex string.
§Errors
- If the input string does not contain a
0x(or0X) prefix. - If the input string is not a valid hex encoding of a
u32.
Sourcepub fn from_unprefixed_hex(s: &str) -> Result<Self, UnprefixedHexError>where
Self: Sized,
pub fn from_unprefixed_hex(s: &str) -> Result<Self, UnprefixedHexError>where
Self: Sized,
Constructs a new CompactTarget from an unprefixed hex string.
§Errors
- If the input string contains a
0x(or0X) prefix. - If the input string is not a valid hex encoding of a
u32.
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for CompactTarget
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for CompactTarget
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl Binary for CompactTarget
impl Binary for CompactTarget
Source§impl Clone for CompactTarget
impl Clone for CompactTarget
Source§fn clone(&self) -> CompactTarget
fn clone(&self) -> CompactTarget
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CompactTarget
impl Debug for CompactTarget
Source§impl Decode for CompactTarget
Available on crate feature encoding only.
impl Decode for CompactTarget
encoding only.Source§impl<'de> Deserialize<'de> for CompactTarget
impl<'de> Deserialize<'de> for CompactTarget
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for CompactTarget
impl Display for CompactTarget
Source§impl Encode for CompactTarget
Available on crate feature encoding only.
impl Encode for CompactTarget
encoding only.Source§impl From<CompactTarget> for Target
impl From<CompactTarget> for Target
Source§fn from(c: CompactTarget) -> Self
fn from(c: CompactTarget) -> Self
Source§impl FromStr for CompactTarget
impl FromStr for CompactTarget
Source§impl Hash for CompactTarget
impl Hash for CompactTarget
Source§impl LowerHex for CompactTarget
impl LowerHex for CompactTarget
Source§impl Octal for CompactTarget
impl Octal for CompactTarget
Source§impl Ord for CompactTarget
impl Ord for CompactTarget
Source§fn cmp(&self, other: &CompactTarget) -> Ordering
fn cmp(&self, other: &CompactTarget) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for CompactTarget
impl PartialEq for CompactTarget
Source§fn eq(&self, other: &CompactTarget) -> bool
fn eq(&self, other: &CompactTarget) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for CompactTarget
impl PartialOrd for CompactTarget
Source§impl Serialize for CompactTarget
impl Serialize for CompactTarget
Source§impl TryFrom<&str> for CompactTarget
impl TryFrom<&str> for CompactTarget
Source§impl TryFrom<String> for CompactTarget
Available on crate feature alloc only.
impl TryFrom<String> for CompactTarget
alloc only.