Crate brk_parser

Source
Expand description

§BRK Parser

A very fast and simple Rust library which reads raw block files (blkXXXXX.dat) from Bitcoin Core node and creates an iterator over all the requested blocks in sequential order (0, 1, 2, …).

The element returned by the iterator is a tuple which includes the:

  • Height: Height
  • Block: Block (from bitcoin-rust)
  • Block’s Hash: BlockHash (also from bitcoin-rust)

§Example

src/main.rs

§Requirements

Even though it reads blkXXXXX.dat files, it needs bitcoind to run with the RPC server to filter out block forks.

Peak memory should be around 500MB.

§Comparaison

biterbitcoin-explorer (deprecated)blocks_iterator
Runs with bitcoindYes ✅No ❌Yes ✅
Runs without bitcoindNo ❌Yes ✅Yes ✅
0..=855_0004mn 10s4mn 45s> 2h
800_000..=855_0000mn 52s (4mn 10s if first run)0mn 55s> 2h

Benchmarked on a Macbook Pro M3 Pro

§Example

use std::path::Path;

use bitcoincore_rpc::{Auth, Client};
use brk_core::Height;
use brk_parser::Parser;

fn main() {
    let i = std::time::Instant::now();

    let data_dir = Path::new("../../../bitcoin");
    let rpc = Box::leak(Box::new(
        Client::new(
            "http://localhost:8332",
            Auth::CookieFile(Path::new(data_dir).join(".cookie")),
        )
        .unwrap(),
    ));

    let start = None;
    let end = None;

    let parser = Parser::new(data_dir, rpc);

    parser.parse(start, end).iter().for_each(|(height, _block, hash)| {
        println!("{height}: {hash}");
    });

    parser.get(Height::new(0));
    parser.get(Height::new(840_000));

    dbg!(i.elapsed());
}

Re-exports§

pub use bitcoin;
pub use bitcoincore_rpc as rpc;

Structs§

Parser

Enums§

Error

Constants§

NUMBER_OF_UNSAFE_BLOCKS

Type Aliases§

Result