Skip to main content

Crate blockchain_zc_parser

Crate blockchain_zc_parser 

Source
Expand description

§blockchain-zc-parser

A zero-copy, allocation-free parser for Bitcoin blockchain binary data.

§Design goals

GoalHow
Zero-copyAll parsed structures borrow &'a [u8] from the input — no memcpy.
No allocCompatible with #![no_std] — no heap allocations required.
Streamingblock::BlockTxIter and transaction::TransactionParser parse lazily via callbacks.
Safeunsafe only for pointer-arithmetic inside cursor after bounds checks.
FastA single block header parse requires only ~10 integer reads from a contiguous buffer.

§Supported formats

  • Bitcoin block headers (80 bytes)
  • Legacy and SegWit (BIP 141) transactions
  • Bitcoin script (scriptPubKey / scriptSig), including pattern matching for P2PKH, P2SH, P2WPKH, P2WSH, P2TR, P2PK, OP_RETURN
  • Raw block files (blkNNNNN.dat) written by Bitcoin Core

§Quick start

use blockchain_zc_parser::{
    block::BlockHeader,
    cursor::Cursor,
};

// Any &[u8] — memory-mapped file, network buffer, test fixture, …
let raw: &[u8] = &[0u8; 80]; // placeholder
let mut cursor = Cursor::new(raw);
// let header = BlockHeader::parse(&mut cursor)?;

§Safety

The crate contains a small amount of unsafe code inside cursor. Every unsafe block is immediately preceded by a comment explaining the invariant that makes it sound. The invariant is always a prior bounds- check performed by safe Rust code.

Re-exports§

pub use block::BlkFileIter;
pub use block::BlockHeader;
pub use block::BlockTxIter;
pub use cursor::Cursor;
pub use error::ParseError;
pub use error::ParseResult;
pub use hash::Hash20;
pub use hash::Hash32;
pub use script::Instruction;
pub use script::Instructions;
pub use script::Script;
pub use script::ScriptType;
pub use transaction::OutPoint;
pub use transaction::TransactionParser;
pub use transaction::TxInput;
pub use transaction::TxOutput;

Modules§

block
Bitcoin block header and full block parsing — zero-copy.
cursor
Zero-copy cursor over a byte slice.
error
Parse error types.
hash
Hash types used throughout the blockchain data structures.
script
Bitcoin script parsing — zero-copy, no alloc.
transaction
Bitcoin transaction parsing — zero-copy, no alloc.