mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
57 lines
1.6 KiB
Rust
57 lines
1.6 KiB
Rust
use std::{fs, path::Path};
|
|
|
|
use brk_computer::Computer;
|
|
use brk_error::Result;
|
|
use brk_indexer::Indexer;
|
|
use brk_query::{Params, ParamsOpt, Query};
|
|
use brk_reader::Reader;
|
|
use brk_rpc::{Auth, Client};
|
|
use brk_types::Index;
|
|
use vecdb::Exit;
|
|
|
|
pub fn main() -> Result<()> {
|
|
let bitcoin_dir = Path::new(&std::env::var("HOME").unwrap())
|
|
.join("Library")
|
|
.join("Application Support")
|
|
.join("Bitcoin");
|
|
// let bitcoin_dir = Path::new("/Volumes/WD_BLACK1/bitcoin");
|
|
|
|
let blocks_dir = bitcoin_dir.join("blocks");
|
|
|
|
let outputs_dir = Path::new(&std::env::var("HOME").unwrap()).join(".brk");
|
|
fs::create_dir_all(&outputs_dir)?;
|
|
// let outputs_dir = Path::new("/Volumes/WD_BLACK1/brk");
|
|
|
|
let client = Client::new(
|
|
"http://localhost:8332",
|
|
Auth::CookieFile(bitcoin_dir.join(".cookie")),
|
|
)?;
|
|
|
|
let outputs_dir = Path::new(&std::env::var("HOME").unwrap()).join(".brk");
|
|
// let outputs_dir = Path::new("../../_outputs");
|
|
|
|
let exit = Exit::new();
|
|
exit.set_ctrlc_handler();
|
|
|
|
let reader = Reader::new(blocks_dir, &client);
|
|
|
|
let indexer = Indexer::forced_import(&outputs_dir)?;
|
|
|
|
let computer = Computer::forced_import(&outputs_dir, &indexer, None)?;
|
|
|
|
let query = Query::build(&reader, &indexer, &computer);
|
|
|
|
dbg!(query.search_and_format(Params {
|
|
index: Index::Height,
|
|
metrics: vec!["date"].into(),
|
|
rest: ParamsOpt::default().set_from(-1),
|
|
})?);
|
|
dbg!(query.search_and_format(Params {
|
|
index: Index::Height,
|
|
metrics: vec!["date", "timestamp"].into(),
|
|
rest: ParamsOpt::default().set_from(-10).set_count(5),
|
|
})?);
|
|
|
|
Ok(())
|
|
}
|