bcloop 0.1.0

A tool for processing Bitcoin-like blockchain data
Documentation
use clap::{Parser, Subcommand};
use utxodump::{WithError, utxodump, utxohex160};

mod utxodump;

#[derive(Subcommand)]
enum Commands {
  /// Dump UTXO data
  Utxodump {
    /// Path to the blockchain data
    blocks_dir: String,
    /// Output file for the UTXO dump
    outfile: String,
  },
  Utxo160 {
    /// Path to the UTXO file
    utxofile: String,
  },
}

/// Blockchain utility tool
#[derive(Parser)]
#[command(name = "bcloop")]
struct Cli {
  #[command(subcommand)]
  command: Commands,
}

fn main() -> WithError {
  // when one core doing I/O, the other core can do the processing
  let cpu_count = std::thread::available_parallelism()?.get();
  rayon::ThreadPoolBuilder::new().num_threads(cpu_count * 2).build_global()?;

  let cli = Cli::parse();
  match cli.command {
    Commands::Utxodump { blocks_dir, outfile } => utxodump(&blocks_dir, &outfile)?,
    Commands::Utxo160 { utxofile } => utxohex160(&utxofile)?,
  }

  Ok(())
}