Struct bitcoin::pow::Target

source ·
pub struct Target(_);
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.)

ref: https://en.bitcoin.it/wiki/Target

Implementations§

source§

impl Target

source

pub const ZERO: Target = _

When parsing nBits, Bitcoin Core converts a negative target threshold into a target of zero.

source

pub const MAX: Self = _

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.

ref: https://en.bitcoin.it/wiki/Target

source

pub const fn max_value() -> Self

The maximum possible target (see Target::MAX).

This is provided for consistency with Rust 1.41.1, newer code should use Target::MAX.

source

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

source

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.

source

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.

source

pub fn to_work(self) -> Work

Converts this Target to Work.

“Work” is defined as the work done to mine a block with this target value (recorded in the block header in compact form as nBits). This is not the same as the difficulty to mine a block with this target (see Self::difficulty).

source

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.

source

pub fn difficulty_float(&self) -> f64

Computes the popular “difficulty” measure for mining and returns a float value of f64.

See difficulty for details.

source§

impl Target

source

pub fn from_be_bytes(bytes: [u8; 32]) -> Target

Creates Self from a big-endian byte array.

source

pub fn from_le_bytes(bytes: [u8; 32]) -> Target

Creates Self from a little-endian byte array.

source

pub fn to_be_bytes(self) -> [u8; 32]

Converts self to a big-endian byte array.

source

pub fn to_le_bytes(self) -> [u8; 32]

Converts self to a little-endian byte array.

Trait Implementations§

source§

impl Clone for Target

source§

fn clone(&self) -> Target

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Target

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Target

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Target

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<CompactTarget> for Target

source§

fn from(c: CompactTarget) -> Self

Converts to this type from the input type.
source§

impl Hash for Target

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl LowerHex for Target

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl Ord for Target

source§

fn cmp(&self, other: &Target) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Target> for Target

source§

fn eq(&self, other: &Target) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Target> for Target

source§

fn partial_cmp(&self, other: &Target) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Target

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl UpperHex for Target

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl Copy for Target

source§

impl Eq for Target

source§

impl StructuralEq for Target

source§

impl StructuralPartialEq for Target

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,