Bitcoin Block Header Package
A Rust library for working with Bitcoin block headers.
Overview
This package provides functionality for working with Bitcoin block headers, following the standard Bitcoin protocol specification.
Block Header Structure
A Bitcoin block header consists of 80 bytes containing:
- Version (4 bytes): Block version indicating the set of block validation rules to follow
- Previous Block Hash (32 bytes): Double SHA256 hash of the previous block's header
- Merkle Root (32 bytes): Hash of the root of the merkle tree of transactions
- Timestamp (4 bytes): Current timestamp as seconds since Unix epoch
- Difficulty Target/Bits (4 bytes): Compact format of the current difficulty target
- Nonce (4 bytes): Counter used for Proof of Work mining
Installation
Add this to your Cargo.toml:
[]
= { = "0.1.0", = "utxo_detective_block_header" }
Basic Usage
use BlockHeader;
// Create a block header from raw bytes
let header_bytes: = ;
let header = new?;
// Access header data
let version = header.version;
let prev_block = header.prev_blockhash;
let prev_block_hex = header.prev_blockhash_hex;
let merkle_root = header.merkle_root;
let merkle_root_hex = header.merkle_root_hex;
let timestamp = header.time;
let bits = header.bits;
let bits_hex = header.bits_hex;
let nonce = header.nonce;
// Calculate and access the block hash
let blockhash = header.blockhash;
let blockhash_hex = header.blockhash_hex;
Features
- Parse Bitcoin block headers from raw bytes
- Access standard block header fields
- Serialize block headers back to bytes
- Basic validation of header structure
License
This project is licensed under the MIT License.