Files
brk/crates/brk_indexer/examples/indexer.rs
T
2025-08-02 16:59:22 +02:00

44 lines
1.2 KiB
Rust

use std::{
fs,
path::Path,
thread::sleep,
time::{Duration, Instant},
};
use brk_error::Result;
use brk_indexer::Indexer;
use brk_parser::Parser;
use brk_vecs::Exit;
fn main() -> Result<()> {
brk_logger::init(Some(Path::new(".log")));
// let bitcoin_dir = brk_structs::default_bitcoin_path();
let bitcoin_dir = Path::new("/Volumes/WD_BLACK1/bitcoin");
let outputs_dir = Path::new("./_outputs");
fs::create_dir_all(outputs_dir)?;
// let outputs_dir = brk_structs::default_brk_path().join("outputs");
// let outputs_dir = Path::new("/Volumes/WD_BLACK1/brk");
let rpc = Box::leak(Box::new(bitcoincore_rpc::Client::new(
"http://localhost:8332",
bitcoincore_rpc::Auth::CookieFile(bitcoin_dir.join(".cookie")),
)?));
let exit = Exit::new();
exit.set_ctrlc_handler();
let parser = Parser::new(bitcoin_dir.join("blocks"), outputs_dir.to_path_buf(), rpc);
fs::create_dir_all(outputs_dir)?;
let mut indexer = Indexer::forced_import(outputs_dir)?;
loop {
let i = Instant::now();
indexer.index(&parser, rpc, &exit, true)?;
dbg!(i.elapsed());
sleep(Duration::from_secs(5 * 60));
}
}