brk_iterator
Unified block iteration with automatic source selection.
What It Enables
Iterate over Bitcoin blocks with a simple API that automatically chooses between RPC (for small ranges) and direct blk file reading (for large scans). Handles reorgs gracefully.
Key Features
- Smart source selection: RPC for ≤10 blocks, Reader for larger ranges
- Flexible ranges: By height span, from start, to end, last N blocks, or after hash
- Reorg-safe: Iteration may end early if chain reorganizes
- Thread-safe: Clone and share freely
Core API
let blocks = new;
// Various range specifications
for block in blocks.range?
for block in blocks.start?
for block in blocks.last?
for block in blocks.after?
Source Modes
// Auto-select (default)
let blocks = new;
// Force RPC only
let blocks = new_rpc;
// Force Reader only
let blocks = new_reader;
Range Types
| Method | Description |
|---|---|
range(start, end) |
Inclusive height range |
start(height) |
From height to chain tip |
end(height) |
From genesis to height |
last(n) |
Last n blocks from tip |
after(hash) |
All blocks after given hash |
Built On
brk_errorfor error handlingbrk_readerfor direct blk file accessbrk_rpcfor RPC queriesbrk_typesforHeight,BlockHash