mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
46 lines
1.1 KiB
Rust
46 lines
1.1 KiB
Rust
use std::{path::Path, thread::sleep, time::Duration};
|
|
|
|
use brk_exit::Exit;
|
|
use brk_indexer::{Indexer, rpc::RpcApi};
|
|
use brk_parser::{
|
|
Parser,
|
|
rpc::{self},
|
|
};
|
|
use log::info;
|
|
|
|
fn main() -> color_eyre::Result<()> {
|
|
color_eyre::install()?;
|
|
|
|
brk_logger::init(Some(Path::new(".log")));
|
|
|
|
let bitcoin_dir = Path::new("../../../bitcoin");
|
|
let rpc = Box::leak(Box::new(rpc::Client::new(
|
|
"http://localhost:8332",
|
|
rpc::Auth::CookieFile(bitcoin_dir.join(".cookie")),
|
|
)?));
|
|
let exit = Exit::new();
|
|
|
|
let parser = Parser::new(bitcoin_dir.to_owned(), rpc);
|
|
|
|
let mut indexer = Indexer::new(Path::new("../../_outputs/indexed").to_owned())?;
|
|
indexer.import_stores()?;
|
|
indexer.import_vecs()?;
|
|
|
|
loop {
|
|
let block_count = rpc.get_block_count()?;
|
|
|
|
info!("{block_count} blocks found.");
|
|
|
|
indexer.index(&parser, rpc, &exit)?;
|
|
|
|
info!("Waiting for new blocks...");
|
|
|
|
while block_count == rpc.get_block_count()? {
|
|
sleep(Duration::from_secs(1))
|
|
}
|
|
}
|
|
|
|
#[allow(unreachable_code)]
|
|
Ok(())
|
|
}
|