mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-22 08:28:10 -07:00
global: snapshot
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use std::{collections::BTreeMap, fs, io};
|
||||
|
||||
use brk_vec::AnyJsonStorableVec;
|
||||
use brk_vec::AnyStorableVec;
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
|
||||
use crate::WEBSITE_DEV_PATH;
|
||||
@@ -12,7 +12,7 @@ pub struct VecIdToIndexToVec(BTreeMap<String, IndexToVec>);
|
||||
|
||||
impl VecIdToIndexToVec {
|
||||
// Not the most performant or type safe but only built once so that's okay
|
||||
pub fn insert(&mut self, vec: &'static dyn AnyJsonStorableVec) {
|
||||
pub fn insert(&mut self, vec: &'static dyn AnyStorableVec) {
|
||||
let file_name = vec.file_name();
|
||||
let split = file_name.split("_to_").collect::<Vec<_>>();
|
||||
if split.len() != 2 {
|
||||
@@ -75,4 +75,4 @@ impl VecIdToIndexToVec {
|
||||
}
|
||||
|
||||
#[derive(Default, Deref, DerefMut)]
|
||||
pub struct IndexToVec(BTreeMap<Index, &'static dyn AnyJsonStorableVec>);
|
||||
pub struct IndexToVec(BTreeMap<Index, &'static dyn AnyStorableVec>);
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#![doc = include_str!("../README.md")]
|
||||
#![doc = "\n## Example\n\n```rust"]
|
||||
#![doc = include_str!("main.rs")]
|
||||
#![doc = "```"]
|
||||
|
||||
use std::time::Instant;
|
||||
|
||||
@@ -6,7 +9,6 @@ use api::{ApiRoutes, VecIdToIndexToVec};
|
||||
use axum::{Json, Router, http::StatusCode, routing::get, serve};
|
||||
use brk_computer::Computer;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::STATELESS;
|
||||
use color_eyre::owo_colors::OwoColorize;
|
||||
use files::FilesRoutes;
|
||||
use log::{error, info};
|
||||
@@ -20,22 +22,19 @@ mod traits;
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
vecs: &'static VecIdToIndexToVec,
|
||||
indexer: &'static Indexer<STATELESS>,
|
||||
computer: &'static Computer<STATELESS>,
|
||||
indexer: &'static Indexer,
|
||||
computer: &'static Computer,
|
||||
}
|
||||
|
||||
pub const WEBSITE_DEV_PATH: &str = "../../websites/kibo.money/";
|
||||
|
||||
pub async fn main(indexer: Indexer<STATELESS>, computer: Computer<STATELESS>) -> color_eyre::Result<()> {
|
||||
pub async fn main(indexer: Indexer, computer: Computer) -> color_eyre::Result<()> {
|
||||
let indexer = Box::leak(Box::new(indexer));
|
||||
let computer = Box::leak(Box::new(computer));
|
||||
let vecs = Box::leak(Box::new(VecIdToIndexToVec::default()));
|
||||
|
||||
indexer
|
||||
.vecs
|
||||
.as_any_json_vecs()
|
||||
.into_iter()
|
||||
.for_each(|vec| vecs.insert(vec));
|
||||
indexer.vecs.as_any_vecs().into_iter().for_each(|vec| vecs.insert(vec));
|
||||
computer.vecs.as_any_vecs().into_iter().for_each(|vec| vecs.insert(vec));
|
||||
|
||||
vecs.generate_dts_file()?;
|
||||
|
||||
|
||||
@@ -1,20 +1,62 @@
|
||||
use std::path::Path;
|
||||
use std::{path::Path, thread::sleep, time::Duration};
|
||||
|
||||
use brk_computer::Computer;
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::STATELESS;
|
||||
use brk_parser::{
|
||||
Parser,
|
||||
rpc::{self, RpcApi},
|
||||
};
|
||||
use log::info;
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn main() -> color_eyre::Result<()> {
|
||||
pub fn main() -> color_eyre::Result<()> {
|
||||
color_eyre::install()?;
|
||||
|
||||
brk_logger::init(None);
|
||||
brk_logger::init(Some(Path::new(".log")));
|
||||
|
||||
let path = Path::new("../../_outputs");
|
||||
let indexer: Indexer<STATELESS> = Indexer::import(&path.join("indexes"))?;
|
||||
let computer: Computer<STATELESS> = Computer::import(&path.join("computed"))?;
|
||||
let data_dir = Path::new("../../../bitcoin");
|
||||
let rpc = Box::leak(Box::new(rpc::Client::new(
|
||||
"http://localhost:8332",
|
||||
rpc::Auth::CookieFile(Path::new(data_dir).join(".cookie")),
|
||||
)?));
|
||||
let exit = Exit::new();
|
||||
|
||||
brk_server::main(indexer, computer).await.unwrap();
|
||||
let parser = Parser::new(data_dir, rpc);
|
||||
|
||||
Ok(())
|
||||
let outputs_dir = Path::new("../../_outputs");
|
||||
|
||||
let mut indexer = Indexer::import(&outputs_dir.join("indexed"))?;
|
||||
|
||||
let mut computer = Computer::import(&outputs_dir.join("computed"))?;
|
||||
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()?
|
||||
.block_on(async {
|
||||
let served_indexer = indexer.clone();
|
||||
let served_computer = computer.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
brk_server::main(served_indexer, served_computer).await.unwrap();
|
||||
});
|
||||
|
||||
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(())
|
||||
}) as color_eyre::Result<()>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user