Struct Target
pub struct Target(/* private fields */);
Expand description
A 256 bit integer representing target.
The SHA-256 hash of a block’s header must be lower than or equal to the current target for the
block to be accepted by the network. The lower the target, the more difficult it is to generate
a block. (See also Work
.)
Implementations§
§impl Target
impl Target
pub const ZERO: Target
pub const ZERO: Target
When parsing nBits, Bitcoin Core converts a negative target threshold into a target of zero.
pub const MAX: Target
pub const MAX: Target
The maximum possible target.
This value is used to calculate difficulty, which is defined as how difficult the current target makes it to find a block relative to how difficult it would be at the highest possible target. Remember highest target == lowest difficulty.
pub const fn max_value() -> Target
pub const fn max_value() -> Target
The maximum possible target (see Target::MAX
).
This is provided for consistency with Rust 1.41.1, newer code should use Target::MAX
.
pub fn from_compact(c: CompactTarget) -> Target
pub fn from_compact(c: CompactTarget) -> Target
Computes the Target
value from a compact representation.
ref: https://developer.bitcoin.org/reference/block_chain.html#target-nbits
pub fn to_compact_lossy(self) -> CompactTarget
pub fn to_compact_lossy(self) -> CompactTarget
Computes the compact value from a Target
representation.
The compact form is by definition lossy, this means that
t == Target::from_compact(t.to_compact_lossy())
does not always hold.
pub fn is_met_by(&self, hash: BlockHash) -> bool
pub fn is_met_by(&self, hash: BlockHash) -> bool
Returns true if block hash is less than or equal to this Target
.
Proof-of-work validity for a block requires the hash of the block to be less than or equal to the target.
pub fn difficulty(&self) -> u128
pub fn difficulty(&self) -> u128
Computes the popular “difficulty” measure for mining.
Difficulty represents how difficult the current target makes it to find a block, relative to how difficult it would be at the highest possible target (highest target == lowest difficulty).
For example, a difficulty of 6,695,826 means that at a given hash rate, it will, on average, take ~6.6 million times as long to find a valid block as it would at a difficulty of 1, or alternatively, it will take, again on average, ~6.6 million times as many hashes to find a valid block
§Note
Difficulty is calculated using the following algorithm max / current
where max is
defined for the Bitcoin network and current
is the current target for this block. As
such, a low target implies a high difficulty. Since Target
is represented as a 256 bit
integer but difficulty()
returns only 128 bits this means for targets below approximately
0xffff_ffff_ffff_ffff_ffff_ffff
difficulty()
will saturate at u128::MAX
.
pub fn difficulty_float(&self) -> f64
pub fn difficulty_float(&self) -> f64
Computes the popular “difficulty” measure for mining and returns a float value of f64.
See difficulty
for details.
pub fn min_difficulty_transition_threshold(&self) -> Target
pub fn min_difficulty_transition_threshold(&self) -> Target
Computes the minimum valid Target
threshold allowed for a block in which a difficulty
adjustment occurs.
The difficulty can only decrease or increase by a factor of 4 max on each difficulty adjustment period.
pub fn max_difficulty_transition_threshold(&self) -> Target
pub fn max_difficulty_transition_threshold(&self) -> Target
Computes the maximum valid Target
threshold allowed for a block in which a difficulty
adjustment occurs.
The difficulty can only decrease or increase by a factor of 4 max on each difficulty adjustment period.
§impl Target
impl Target
pub fn from_be_bytes(bytes: [u8; 32]) -> Target
pub fn from_be_bytes(bytes: [u8; 32]) -> Target
Creates Self
from a big-endian byte array.
pub fn from_le_bytes(bytes: [u8; 32]) -> Target
pub fn from_le_bytes(bytes: [u8; 32]) -> Target
Creates Self
from a little-endian byte array.
pub fn to_be_bytes(self) -> [u8; 32]
pub fn to_be_bytes(self) -> [u8; 32]
Converts self
to a big-endian byte array.
pub fn to_le_bytes(self) -> [u8; 32]
pub fn to_le_bytes(self) -> [u8; 32]
Converts self
to a little-endian byte array.
Trait Implementations§
§impl<'de> Deserialize<'de> for Target
impl<'de> Deserialize<'de> for Target
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Target, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Target, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl From<CompactTarget> for Target
impl From<CompactTarget> for Target
§fn from(c: CompactTarget) -> Target
fn from(c: CompactTarget) -> Target
§impl Ord for Target
impl Ord for Target
§impl PartialOrd for Target
impl PartialOrd for Target
§impl Serialize for Target
impl Serialize for Target
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for Target
impl Eq 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 UnwindSafe for Target
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<T> Downcast for Twhere
T: AsAny + ?Sized,
impl<T> Downcast for Twhere
T: AsAny + ?Sized,
§fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
Any
.§fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
Any
.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
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.