pub struct BlockHeader {
    pub version: i32,
    pub prev_blockhash: BlockHash,
    pub merkle_root: TxMerkleNode,
    pub time: u32,
    pub bits: u32,
    pub nonce: u32,
}
Expand description

Bitcoin block header.

Contains all the block’s information except the actual transactions, but including a root of a merkle tree commiting to all transactions in the block.

Bitcoin Core References

Fields

version: i32

Originally protocol version, but repurposed for soft-fork signaling.

Relevant BIPs
prev_blockhash: BlockHash

Reference to the previous block in the chain.

merkle_root: TxMerkleNode

The root hash of the merkle tree of transactions in the block.

time: u32

The timestamp of the block, as claimed by the miner.

bits: u32

The target value below which the blockhash must lie, encoded as a a float (with well-defined rounding, of course).

nonce: u32

The nonce, selected to obtain a low enough blockhash.

Implementations

Returns the block hash.

Computes the target [0, T] that a blockhash must land in to be valid.

Computes the target value in Uint256 format, from a compact representation.

use bitcoin::blockdata::block::BlockHeader;

assert_eq!(0x1d00ffff,
    BlockHeader::compact_target_from_u256(
        &BlockHeader::u256_from_compact_target(0x1d00ffff)
    )
);

Computes the target value in float format from Uint256 format.

Computes the popular “difficulty” measure for mining.

Checks that the proof-of-work for the block is valid, returning the block hash.

Returns the total work of the block.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Decode Self from a size-limited reader. Read more
Decode an object with a well-defined format. Read more
Deserialize this value from the given Serde deserializer. Read more
Encode an object with a well-defined format. Returns the number of bytes written on success. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.