brk_reader
Streams Bitcoin blocks from Bitcoin Core's raw blk*.dat files in chain order.
Requirements
A running Bitcoin Core node with RPC access. The reader needs:
- The
blocks/directory (forblk*.datfiles) - RPC connection (to resolve block heights and filter orphan blocks)
Quick Start
let bitcoin_dir = default_bitcoin_path;
let client = new?;
let reader = new;
// Stream the entire chain
for block in reader.read
// Or a specific range (inclusive)
for block in reader.read
What You Get
Each ReadBlock gives you access to:
| Field | Description |
|---|---|
block.height() |
Block height |
block.hash() |
Block hash |
block.header |
Block header (timestamp, nonce, difficulty, ...) |
block.txdata |
All transactions |
block.coinbase_tag() |
Miner's coinbase tag |
block.metadata() |
Position in the blk file |
block.tx_metadata() |
Per-transaction blk file positions |
Reader is thread-safe and cheap to clone (Arc-backed).
How It Works
Three-thread pipeline connected by bounded channels:
blk*.dat ──► File Reader ──► Parser Pool ──► Orderer ──► Receiver<ReadBlock>
1 thread up to 4 1 thread
- File reader binary-searches to the starting blk file, scans for magic bytes, segments raw blocks
- Parser pool XOR-decodes and deserializes blocks in parallel, skips out-of-range blocks via header timestamp, filters orphans via RPC
- Orderer buffers out-of-order arrivals, validates
prev_blockhashcontinuity, emits blocks sequentially