Make Parser::new the only entrypoint

This commit is contained in:
deadmanoz
2025-07-04 12:15:32 +08:00
parent 870c70180f
commit fa1e5aaa7f
8 changed files with 18 additions and 19 deletions

View File

@@ -21,7 +21,7 @@ pub fn run() -> color_eyre::Result<()> {
let exit = Exit::new();
let parser = if config.process() && rpc.is_some() {
Some(brk_parser::Parser::new_with_outputs_dir(
Some(brk_parser::Parser::new(
config.blocksdir(),
config.outputsdir(),
rpc.unwrap(),

View File

@@ -25,7 +25,7 @@ pub fn main() -> color_eyre::Result<()> {
thread::Builder::new()
.stack_size(32 * 1024 * 1024)
.spawn(move || -> color_eyre::Result<()> {
let parser = Parser::new(bitcoin_dir.join("blocks"), rpc);
let parser = Parser::new(bitcoin_dir.join("blocks"), default_brk_path(), rpc);
let _outputs_dir = default_brk_path().join("outputs");
let outputs_dir = _outputs_dir.as_path();

View File

@@ -1,6 +1,6 @@
use std::{path::Path, time::Instant};
use brk_core::default_bitcoin_path;
use brk_core::{default_bitcoin_path, default_brk_path};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_parser::Parser;
@@ -13,6 +13,7 @@ fn main() -> color_eyre::Result<()> {
brk_logger::init(Some(Path::new(".log")));
let bitcoin_dir = default_bitcoin_path();
let brk_dir = default_brk_path();
let rpc = Box::leak(Box::new(bitcoincore_rpc::Client::new(
"http://localhost:8332",
@@ -20,7 +21,7 @@ fn main() -> color_eyre::Result<()> {
)?));
let exit = Exit::new();
let parser = Parser::new(bitcoin_dir.join("blocks"), rpc);
let parser = Parser::new(bitcoin_dir.join("blocks"), brk_dir, rpc);
let outputs = Path::new("../../_outputs");

View File

@@ -1,11 +1,12 @@
use bitcoincore_rpc::{Auth, Client};
use brk_core::{Height, default_bitcoin_path};
use brk_core::{Height, default_bitcoin_path, default_brk_path};
use brk_parser::Parser;
fn main() {
let i = std::time::Instant::now();
let bitcoin_dir = default_bitcoin_path();
let brk_dir = default_brk_path();
let rpc = Box::leak(Box::new(
Client::new(
@@ -18,7 +19,7 @@ fn main() {
let start = None;
let end = None;
let parser = Parser::new(bitcoin_dir.join("blocks"), rpc);
let parser = Parser::new(bitcoin_dir.join("blocks"), brk_dir, rpc);
parser
.parse(start, end)

View File

@@ -1,11 +1,12 @@
use bitcoincore_rpc::{Auth, Client};
use brk_core::{Height, OutputType, default_bitcoin_path};
use brk_core::{Height, OutputType, default_bitcoin_path, default_brk_path};
use brk_parser::Parser;
fn main() {
let i = std::time::Instant::now();
let bitcoin_dir = default_bitcoin_path();
let brk_dir = default_brk_path();
let rpc = Box::leak(Box::new(
Client::new(
@@ -18,7 +19,7 @@ fn main() {
// let start = None;
// let end = None;
let parser = Parser::new(bitcoin_dir.join("blocks"), rpc);
let parser = Parser::new(bitcoin_dir.join("blocks"), brk_dir, rpc);
// parser
// .parse(start, end)

View File

@@ -5,7 +5,7 @@ use std::{
path::{Path, PathBuf},
};
use crate::{BlkIndexToBlkPath, Height, blk_recap::BlkRecap};
use crate::{blk_recap::BlkRecap, BlkIndexToBlkPath, Height};
#[derive(Debug)]
pub struct BlkIndexToBlkRecap {

View File

@@ -43,18 +43,13 @@ pub struct Parser {
}
impl Parser {
pub fn new(blocks_dir: PathBuf, rpc: &'static bitcoincore_rpc::Client) -> Self {
// For backward compatibility, use blocks_dir as outputs_dir
pub fn new(blocks_dir: PathBuf, brk_dir: PathBuf, rpc: &'static bitcoincore_rpc::Client) -> Self {
Self {
outputs_dir: blocks_dir.clone(),
blocks_dir,
blocks_dir,
outputs_dir: brk_dir,
rpc
}
}
pub fn new_with_outputs_dir(blocks_dir: PathBuf, outputs_dir: PathBuf, rpc: &'static bitcoincore_rpc::Client) -> Self {
Self { blocks_dir, outputs_dir, rpc }
}
pub fn get(&self, height: Height) -> Block {
self.parse(Some(height), Some(height))

View File

@@ -2,7 +2,7 @@ use std::{path::Path, thread::sleep, time::Duration};
use bitcoincore_rpc::RpcApi;
use brk_computer::Computer;
use brk_core::default_bitcoin_path;
use brk_core::{default_bitcoin_path, default_brk_path};
use brk_exit::Exit;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
@@ -18,6 +18,7 @@ pub fn main() -> color_eyre::Result<()> {
let process = true;
let bitcoin_dir = default_bitcoin_path();
let brk_dir = default_brk_path();
let rpc = Box::leak(Box::new(bitcoincore_rpc::Client::new(
"http://localhost:8332",
@@ -25,7 +26,7 @@ pub fn main() -> color_eyre::Result<()> {
)?));
let exit = Exit::new();
let parser = Parser::new(bitcoin_dir.join("blocks"), rpc);
let parser = Parser::new(bitcoin_dir.join("blocks"), brk_dir, rpc);
let outputs_dir = Path::new("../../_outputs");