utxo_detective_block_header 0.1.0

Bitcoin block header parsing, validation, and utilities for blockchain analysis
Documentation
  • Coverage
  • 100%
    20 out of 20 items documented0 out of 17 items with examples
  • Size
  • Source code size: 10.92 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.79 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • utxo-detective

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:

[dependencies]
block_header = { version = "0.1.0", path = "utxo_detective_block_header" }

Basic Usage

use block_header::BlockHeader;

// Create a block header from raw bytes
let header_bytes: [u8; 80] = [/* ... */];
let header = BlockHeader::new(&header_bytes)?;

// 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.