main/
main.rs

1use std::{fs, path::Path};
2
3use brk_computer::Computer;
4use brk_error::Result;
5use brk_indexer::Indexer;
6use brk_interface::{Index, Interface, Params, ParamsOpt};
7use brk_parser::Parser;
8use vecdb::Exit;
9
10pub fn main() -> Result<()> {
11    let bitcoin_dir = Path::new(&std::env::var("HOME").unwrap())
12        .join("Library")
13        .join("Application Support")
14        .join("Bitcoin");
15    // let bitcoin_dir = Path::new("/Volumes/WD_BLACK1/bitcoin");
16
17    let blocks_dir = bitcoin_dir.join("blocks");
18
19    let outputs_dir = Path::new(&std::env::var("HOME").unwrap()).join(".brk");
20    fs::create_dir_all(&outputs_dir)?;
21    // let outputs_dir = Path::new("/Volumes/WD_BLACK1/brk");
22
23    let rpc = Box::leak(Box::new(bitcoincore_rpc::Client::new(
24        "http://localhost:8332",
25        bitcoincore_rpc::Auth::CookieFile(bitcoin_dir.join(".cookie")),
26    )?));
27
28    let exit = Exit::new();
29    exit.set_ctrlc_handler();
30
31    let parser = Parser::new(blocks_dir, rpc);
32
33    let indexer = Indexer::forced_import(&outputs_dir)?;
34
35    let computer = Computer::forced_import(&outputs_dir, &indexer, None)?;
36
37    let interface = Interface::build(&parser, &indexer, &computer);
38
39    dbg!(interface.search_and_format(Params {
40        index: Index::Height,
41        metrics: vec!["date"].into(),
42        rest: ParamsOpt::default().set_from(-1),
43    })?);
44    dbg!(interface.search_and_format(Params {
45        index: Index::Height,
46        metrics: vec!["date", "timestamp"].into(),
47        rest: ParamsOpt::default().set_from(-10).set_count(5),
48    })?);
49
50    Ok(())
51}