bitcoin-block-parser

Crates.iobitcoin-block-parser
lib.rsbitcoin-block-parser
version0.5.3
created_at2024-09-13 18:26:12.981852+00
updated_at2025-01-01 03:42:52.280648+00
descriptionBlazing fast parser for bitcoin 'blocks' data with input amount and output spend tracking.
homepage
repositoryhttps://github.com/sumopool/bitcoin-block-parser
max_upload_size
id1374051
size74,863
Saigo Nanshu (sumopool)

documentation

https://docs.rs/bitcoin-block-parser

README

Bitcoin Block Parser

Crates.io Docs MIT licensed

Blazing fast parser for bitcoin blocks data with input amount and output spend tracking.

⚠️ The API is still evolving and should not be considered stable until release 1.0.0

Features

  • Parses blocks into the Rust bitcoin Block format for easier manipulation
  • Can track if any TxOut is spent or unspent for calculations on the UTXO set
  • Can track the TxOut of every TxIn for calculating metrics such as fee rates
  • Multithreaded in-memory parsing provides fast block parsing performance

Requirements / Benchmarks

  • You must be running a non-pruning bitcoin node (this is the default configuration)
  • We recommend using fast storage (e.g. NVMe) and a multithreaded CPU for best performance
  • See benchmarks below to understand how much RAM you may need:
Function Time Memory
BlockParser::parse()
Parses blocks
2m 55s 0.9 GB
UtxoParser::create_filter()
Create a new filter
15m 12s 2.6 GB
UtxoParser::parse()
Parse with existing filter
18m 30s 12.1 GB

Our benchmarks were run on NVMe storage with a 32-thread processor on 800,000 blocks.

Quick Usage

See BlockParser for details on how to parse blocks:

use bitcoin_block_parser::*;

// Initialize a logger (if you want to monitor parsing progress)
env_logger::builder().filter_level(log::LevelFilter::Info).init();

// Parse all blocks in the directory and map them to total_size
let parser = BlockParser::new("/home/user/.bitcoin/blocks/").unwrap();
for size in parser.parse(|block| block.total_size()) {
  // Do something with the block sizes
}

See UtxoParser for details on how to track inputs and outputs:

use bitcoin_block_parser::*;

// Load a filter file or create a new one for tracking output status
let parser = UtxoParser::new("/home/user/.bitcoin/blocks/", "filter.bin");
for txdata in parser.parse(|block| block.txdata).unwrap() {
  for tx in txdata {
    for (output, status) in tx.output() {
      // Do something with the output status
    }
    for (input, output) in tx.input() {
      // Do something with TxOut that are used in the inputs
    }
  }
}
Commit count: 30

cargo fmt