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 fn to_consensus(self) -> u32
pub fn to_consensus(self) -> u32
Returns the consensus encoded u32
representation of this CompactTarget
.
Trait Implementations§
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 more