#block-header #bitcoin #validation #header-parser #parser #blockchain

utxo_detective_block_header

Bitcoin block header parsing, validation, and utilities for blockchain analysis

1 unstable release

0.1.0 Dec 4, 2024

#8 in #block-header

Download history 121/week @ 2024-12-02 10/week @ 2024-12-09

131 downloads per month

MIT license

11KB
127 lines

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.

Dependencies

~46KB