BlockHashExt

Trait BlockHashExt 

Source
pub trait BlockHashExt: AsPtr<btck_BlockHash> + Display {
    // Provided method
    fn to_bytes(&self) -> [u8; 32] { ... }
}
Expand description

Common operations for block hashes, implemented by both owned and borrowed types.

This trait provides shared functionality for BlockHash and BlockHashRef, allowing code to work with either owned or borrowed block hashes.

§Examples

use bitcoinkernel::{prelude::*, BlockHash};

fn display_hash<H: BlockHashExt>(hash: &H) {
    let bytes = hash.to_bytes();
    println!("Hash bytes: {:?}", bytes);
}

let hash = BlockHash::from([1u8; 32]);
display_hash(&hash);

Provided Methods§

Source

fn to_bytes(&self) -> [u8; 32]

Serializes the block hash to raw bytes.

Returns the 32-byte representation of the block hash in internal byte order.

§Returns

A 32-byte array containing the block hash.

§Example
use bitcoinkernel::{prelude::*, BlockHash};

let hash = BlockHash::from([42u8; 32]);
let bytes = hash.to_bytes();
assert_eq!(bytes.len(), 32);

Implementors§