Trait HeaderExt

Source
pub trait HeaderExt {
    // Required methods
    fn calculate_median_time_past(
        &self,
        chain: &impl BlockchainInterface,
    ) -> Result<u32, HeaderExtError>;
    fn calculate_chain_work(
        &self,
        chain: &impl BlockchainInterface,
    ) -> Result<Work, HeaderExtError>;
    fn get_next_block_hash(
        &self,
        chain: &impl BlockchainInterface,
    ) -> Result<Option<BlockHash>, HeaderExtError>;
    fn get_previous_block_header(
        &self,
        chain: &impl BlockchainInterface,
    ) -> Result<Header, HeaderExtError>;
    fn get_bits_hex(&self) -> String;
    fn get_confirmations(
        &self,
        chain: &impl BlockchainInterface,
    ) -> Result<u32, HeaderExtError>;
    fn get_difficulty(&self) -> f64;
    fn get_height(
        &self,
        chain: &impl BlockchainInterface,
    ) -> Result<u32, HeaderExtError>;
    fn get_target_hex(&self) -> String;
    fn get_version_hex(&self) -> String;
}
Expand description

Provides additional methods for working with [Header] objects,

Required Methods§

Source

fn calculate_median_time_past( &self, chain: &impl BlockchainInterface, ) -> Result<u32, HeaderExtError>

Calculates the Median Time Past (MTP) for the block.

Source

fn calculate_chain_work( &self, chain: &impl BlockchainInterface, ) -> Result<Work, HeaderExtError>

Calculates the total accumulated chain work up to the current block.

Source

fn get_next_block_hash( &self, chain: &impl BlockchainInterface, ) -> Result<Option<BlockHash>, HeaderExtError>

Retrieves the hash of the next block in the chain, if it exists.

Returns None if the block is the tip of the chain.

Source

fn get_previous_block_header( &self, chain: &impl BlockchainInterface, ) -> Result<Header, HeaderExtError>

Retrieves the header of the previous block in the chain.

Source

fn get_bits_hex(&self) -> String

Returns the block’s “bits” field as a hexadecimal string.

Source

fn get_confirmations( &self, chain: &impl BlockchainInterface, ) -> Result<u32, HeaderExtError>

Calculates the number of confirmations for the current block.

Source

fn get_difficulty(&self) -> f64

Returns the block’s difficulty as a floating-point number.

Source

fn get_height( &self, chain: &impl BlockchainInterface, ) -> Result<u32, HeaderExtError>

Retrieves the height of the block in the blockchain.

Source

fn get_target_hex(&self) -> String

Returns the block’s target as a hexadecimal string.

In rust-bitcoin, calling to_string on Target returns the value in decimal because it wraps a U256, which defaults to decimal string conversion. However, Bitcoin Core represents targets in hexadecimal. This method ensures the target is returned in hexadecimal format, consistent with Bitcoin Core.

Source

fn get_version_hex(&self) -> String

Returns the block’s version as a hexadecimal string.

Bitcoin Core represents the block version as a 32-bit unsigned integer (u32) in hexadecimal format. This method ensures the version is returned as a properly formatted hexadecimal string, consistent with Bitcoin Core.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl HeaderExt for Header

Implementors§