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
format!("{var:x}") insteadGets 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 · 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 Decodable for CompactTarget
Available on crate feature encoding only.
impl Decodable 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 Encodable for CompactTarget
Available on crate feature encoding only.
impl Encodable for CompactTarget
encoding only.