global: snapshot + core: impl Display for bytes structs

This commit is contained in:
nym21
2025-03-04 12:29:19 +01:00
parent fc6f12fb22
commit 0d0edd7917
36 changed files with 782 additions and 331 deletions

View File

@@ -1,6 +1,7 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc = include_str!("../README.md")]
#![doc = "\n## Example\n\n```rust"]
#![doc = include_str!("main.rs")]
#![doc = include_str!("../examples/main.rs")]
#![doc = "```"]
use std::path::{Path, PathBuf};
@@ -23,9 +24,9 @@ pub struct Computer {
}
impl Computer {
pub fn new(computed_dir: &Path) -> Self {
pub fn new(computed_dir: PathBuf) -> Self {
Self {
path: computed_dir.to_owned(),
path: computed_dir,
vecs: None,
stores: None,
}
@@ -36,6 +37,8 @@ impl Computer {
Ok(())
}
/// Do NOT import multiple times are things will break !!!
/// Clone struct instead
pub fn import_stores(&mut self) -> color_eyre::Result<()> {
self.stores = Some(Stores::import(&self.path.join("stores"))?);
Ok(())
@@ -43,7 +46,12 @@ impl Computer {
}
impl Computer {
pub fn compute(&mut self, indexer: &mut Indexer, starting_indexes: Indexes, exit: &Exit) -> color_eyre::Result<()> {
pub fn compute(
&mut self,
indexer: &mut Indexer,
starting_indexes: Indexes,
exit: &Exit,
) -> color_eyre::Result<()> {
info!("Computing...");
let height_count = indexer.vecs().height_to_size.len();

View File

@@ -1,54 +0,0 @@
use std::{path::Path, thread::sleep, time::Duration};
use brk_computer::Computer;
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_parser::{
Parser,
rpc::{self, RpcApi},
};
use log::info;
pub 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(Path::new(bitcoin_dir).join(".cookie")),
)?));
let exit = Exit::new();
let parser = Parser::new(bitcoin_dir, rpc);
let outputs_dir = Path::new("../../_outputs");
let mut indexer = Indexer::new(&outputs_dir.join("indexed"))?;
indexer.import_stores()?;
indexer.import_vecs()?;
let mut computer = Computer::new(&outputs_dir.join("computed"));
computer.import_stores()?;
computer.import_vecs()?;
loop {
let block_count = rpc.get_block_count()?;
info!("{block_count} blocks found.");
let starting_indexes = indexer.index(&parser, rpc, &exit)?;
computer.compute(&mut indexer, starting_indexes, &exit)?;
info!("Waiting for new blocks...");
while block_count == rpc.get_block_count()? {
sleep(Duration::from_secs(1))
}
}
#[allow(unreachable_code)]
Ok(())
}