mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 07:09:59 -07:00
1.5 KiB
1.5 KiB
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 = Blocks::new(&rpc_client, &reader);
// Various range specifications
for block in blocks.range(Height::new(800_000), Height::new(800_100))? { ... }
for block in blocks.start(Height::new(840_000))? { ... }
for block in blocks.last(10)? { ... }
for block in blocks.after(Some(last_known_hash))? { ... }
Source Modes
// Auto-select (default)
let blocks = Blocks::new(&client, &reader);
// Force RPC only
let blocks = Blocks::new_rpc(&client);
// Force Reader only
let blocks = Blocks::new_reader(&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