global: snapshot

This commit is contained in:
nym21
2025-11-09 22:57:06 +01:00
parent dc2e847f58
commit f6a2a0540b
58 changed files with 504 additions and 714 deletions

695
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -23,11 +23,17 @@ panic = "abort"
strip = true
overflow-checks = false
[profile.bloaty]
debug = true
lto = false
strip = false
inherits = "release"
[profile.dist]
inherits = "release"
[workspace.dependencies]
aide = { version = "0.15.2", features = ["axum-json", "axum-query"], package = "brk-aide" }
aide = { version = "0.16.0-alpha.1", features = ["axum-json", "axum-query"] }
axum = "0.8.6"
bitcoin = { version = "0.32.7", features = ["serde"] }
bitcoincore-rpc = "0.19.0"
@@ -73,8 +79,8 @@ serde_derive = "1.0.228"
serde_json = { version = "1.0.145", features = ["float_roundtrip"] }
sonic-rs = "0.5.6"
tokio = { version = "1.48.0", features = ["rt-multi-thread"] }
# vecdb = { path = "../seqdb/crates/vecdb", features = ["derive"] }
vecdb = { version = "0.3.15", features = ["derive"] }
vecdb = { path = "../seqdb/crates/vecdb", features = ["derive"] }
# vecdb = { version = "0.3.16", features = ["derive"] }
zerocopy = { version = "0.8.27", features = ["derive"] }
[workspace.metadata.release]

View File

@@ -34,7 +34,7 @@ pub use brk_indexer as indexer;
#[cfg(feature = "iterator")]
#[doc(inline)]
pub use brk_query as iterator;
pub use brk_iterator as iterator;
#[cfg(feature = "logger")]
#[doc(inline)]
@@ -58,7 +58,7 @@ pub use brk_reader as reader;
#[cfg(feature = "rpc")]
#[doc(inline)]
pub use brk_rpc as reader;
pub use brk_rpc as rpc;
#[cfg(feature = "server")]
#[doc(inline)]

View File

@@ -13,26 +13,19 @@ const AUTO_GENERATED_DISCLAIMER: &str = "//
// File auto-generated, any modifications will be overwritten
//";
#[allow(clippy::upper_case_acronyms)]
pub trait Bridge {
fn generate_js_files(&self, modules_path: &Path) -> io::Result<()>;
}
pub fn generate_js_files(query: &Query, modules_path: &Path) -> io::Result<()> {
let path = modules_path.join("brk-client");
impl Bridge for Query {
fn generate_js_files(&self, modules_path: &Path) -> io::Result<()> {
let path = modules_path.join("brk-client");
if !fs::exists(&path)? {
return Ok(());
}
let path = path.join("generated");
fs::create_dir_all(&path)?;
generate_version_file(&path)?;
generate_metrics_file(self, &path)?;
generate_pools_file(&path)
if !fs::exists(&path)? {
return Ok(());
}
let path = path.join("generated");
fs::create_dir_all(&path)?;
generate_version_file(&path)?;
generate_metrics_file(query, &path)?;
generate_pools_file(&path)
}
fn generate_version_file(parent: &Path) -> io::Result<()> {

View File

@@ -1,5 +1,5 @@
mod js;
pub use js::Bridge;
pub use js::*;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

View File

@@ -12,9 +12,7 @@ build = "build.rs"
[dependencies]
log = { workspace = true }
notify = "8.2.0"
rolldown = { version = "0.2.3", package = "brk_rolldown" }
# rolldown = "0.1.0"
# brk_rolldown = "0.2.3"
rolldown = { version = "0.3.0", package = "brk_rolldown" }
# brk_rolldown = { path = "../../../rolldown/crates/rolldown"}
sugar_path = "1.2.1"
tokio = { workspace = true }

View File

@@ -9,7 +9,7 @@ use brk_rpc::{Auth, Client};
use clap::Parser;
use serde::{Deserialize, Deserializer, Serialize};
use crate::{default_bitcoin_path, default_brk_path, dot_brk_path, website::Website};
use crate::{default_brk_path, dot_brk_path, website::Website};
const DOWNLOADS: &str = "downloads";
@@ -197,14 +197,14 @@ Finally, you can run the program with '-h' for help."
}
pub fn rpc(&self) -> Result<Client> {
Ok(Client::new(
Client::new(
&format!(
"http://{}:{}",
self.rpcconnect().unwrap_or(&"localhost".to_string()),
self.rpcport().unwrap_or(8332)
),
self.rpc_auth().unwrap(),
)?)
self.rpc_auth()?,
)
}
fn rpc_auth(&self) -> Result<Auth> {
@@ -233,7 +233,9 @@ Finally, you can run the program with '-h' for help."
pub fn bitcoindir(&self) -> PathBuf {
self.bitcoindir
.as_ref()
.map_or_else(default_bitcoin_path, |s| Self::fix_user_path(s.as_ref()))
.map_or_else(Client::default_bitcoin_path, |s| {
Self::fix_user_path(s.as_ref())
})
}
pub fn blocksdir(&self) -> PathBuf {

View File

@@ -8,13 +8,13 @@ use std::{
time::Duration,
};
use brk_binder::Bridge;
use brk_binder::generate_js_files;
use brk_bundler::bundle;
use brk_computer::Computer;
use brk_error::Result;
use brk_indexer::Indexer;
use brk_iterator::Blocks;
use brk_query::Query;
use brk_query::AsyncQuery;
use brk_reader::Reader;
use brk_server::{Server, VERSION};
use log::info;
@@ -57,7 +57,7 @@ pub fn run() -> color_eyre::Result<()> {
let mut computer = Computer::forced_import(&config.brkdir(), &indexer, config.fetcher())?;
let query = Query::build(&reader, &indexer, &computer);
let query = AsyncQuery::build(&reader, &indexer, &computer);
let website = config.website();
@@ -100,7 +100,7 @@ pub fn run() -> color_eyre::Result<()> {
modules_path = downloaded_modules_path;
}
query.generate_js_files(&modules_path)?;
generate_js_files(query.inner(), &modules_path)?;
Some(
bundle(

View File

@@ -1,7 +1,4 @@
use std::{
env,
path::{Path, PathBuf},
};
use std::path::{Path, PathBuf};
pub fn dot_brk_path() -> PathBuf {
let home = std::env::var("HOME").unwrap();

View File

@@ -5,7 +5,7 @@ use brk_error::Result;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
use brk_types::{Address, AddressBytes, OutputType, TxOutIndex, pools};
use vecdb::{AnyIterableVec, Exit, VecIteratorExtended};
use vecdb::{Exit, IterableVec, TypedVecIterator};
fn main() -> Result<()> {
brk_logger::init(Some(Path::new(".log")))?;

View File

@@ -7,7 +7,7 @@ use brk_traversable::Traversable;
use brk_types::{BlkPosition, Height, TxIndex, Version};
use vecdb::{
AnyStoredVec, AnyVec, CompressedVec, Database, Exit, GenericStoredVec, PAGE_SIZE,
VecIteratorExtended,
TypedVecIterator,
};
use super::Indexes;

View File

@@ -10,8 +10,8 @@ use brk_types::{
TxVersion, Version, WeekIndex, Weight, YearIndex,
};
use vecdb::{
AnyCloneableIterableVec, AnyIterableVec, Database, EagerVec, Exit, LazyVecFrom1, LazyVecFrom2,
LazyVecFrom3, PAGE_SIZE, StoredIndex, VecIteratorExtended,
Database, EagerVec, Exit, IterableCloneableVec, IterableVec, LazyVecFrom1, LazyVecFrom2,
LazyVecFrom3, PAGE_SIZE, StoredIndex, TypedVecIterator,
};
use crate::grouped::{

View File

@@ -3,7 +3,7 @@ use std::path::Path;
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Bitcoin, CheckedSub, Dollars, StoredF32, StoredF64, Version};
use vecdb::{Database, Exit, PAGE_SIZE, VecIteratorExtended};
use vecdb::{Database, Exit, PAGE_SIZE, TypedVecIterator};
use crate::grouped::ComputedVecsFromDateIndex;

View File

@@ -6,7 +6,7 @@ use brk_indexer::Indexer;
use brk_traversable::Traversable;
use brk_types::{DateIndex, Height, OHLCCents, Version};
use vecdb::{
AnyIterableVec, AnyStoredVec, AnyVec, Database, Exit, GenericStoredVec, PAGE_SIZE, RawVec,
AnyStoredVec, AnyVec, Database, Exit, GenericStoredVec, IterableVec, PAGE_SIZE, RawVec,
StoredIndex, VecIterator,
};

View File

@@ -2,7 +2,7 @@ use brk_error::{Error, Result};
use brk_traversable::Traversable;
use brk_types::{CheckedSub, StoredU64, Version};
use vecdb::{
AnyIterableVec, AnyStoredVec, AnyVec, Database, EagerVec, Exit, Format, GenericStoredVec,
AnyStoredVec, AnyVec, Database, EagerVec, Exit, Format, GenericStoredVec, IterableVec,
StoredIndex, StoredRaw,
};
@@ -204,7 +204,7 @@ where
pub fn extend(
&mut self,
max_from: I,
source: &impl AnyIterableVec<I, T>,
source: &impl IterableVec<I, T>,
exit: &Exit,
) -> Result<()> {
if self.cumulative.is_none() {
@@ -238,9 +238,9 @@ where
pub fn compute<I2>(
&mut self,
max_from: I,
source: &impl AnyIterableVec<I2, T>,
first_indexes: &impl AnyIterableVec<I, I2>,
count_indexes: &impl AnyIterableVec<I, StoredU64>,
source: &impl IterableVec<I2, T>,
first_indexes: &impl IterableVec<I, I2>,
count_indexes: &impl IterableVec<I, StoredU64>,
exit: &Exit,
) -> Result<()>
where
@@ -398,8 +398,8 @@ where
&mut self,
max_from: I,
source: &EagerVecsBuilder<I2, T>,
first_indexes: &impl AnyIterableVec<I, I2>,
count_indexes: &impl AnyIterableVec<I, StoredU64>,
first_indexes: &impl IterableVec<I, I2>,
count_indexes: &impl IterableVec<I, StoredU64>,
exit: &Exit,
) -> Result<()>
where

View File

@@ -1,8 +1,6 @@
use brk_traversable::Traversable;
use brk_types::Version;
use vecdb::{
AnyBoxedIterableVec, AnyCloneableIterableVec, FromCoarserIndex, LazyVecFrom2, StoredIndex,
};
use vecdb::{FromCoarserIndex, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2, StoredIndex};
use crate::grouped::{EagerVecsBuilder, VecBuilderOptions};
@@ -39,9 +37,9 @@ where
pub fn forced_import(
name: &str,
version: Version,
source: Option<AnyBoxedIterableVec<S1I, T>>,
source: Option<IterableBoxedVec<S1I, T>>,
source_extra: &EagerVecsBuilder<S1I, T>,
len_source: AnyBoxedIterableVec<I, S2T>,
len_source: IterableBoxedVec<I, S2T>,
options: LazyVecBuilderOptions,
) -> Self {
let only_one_active = options.is_only_one_active();

View File

@@ -4,7 +4,7 @@ use brk_traversable::Traversable;
use brk_types::{
DateIndex, DecadeIndex, MonthIndex, QuarterIndex, SemesterIndex, Version, WeekIndex, YearIndex,
};
use vecdb::{AnyCloneableIterableVec, AnyIterableVec, Database, EagerVec, Exit};
use vecdb::{AnyCollectableVec, Database, EagerVec, Exit, IterableCloneableVec, IterableVec};
use crate::{Indexes, grouped::LazyVecsBuilder, indexes};
@@ -128,7 +128,7 @@ where
&mut self,
starting_indexes: &Indexes,
exit: &Exit,
dateindex: Option<&impl AnyIterableVec<DateIndex, T>>,
dateindex: Option<&impl IterableVec<DateIndex, T>>,
) -> Result<()> {
if let Some(dateindex) = dateindex {
self.dateindex_extra
@@ -178,8 +178,8 @@ where
.unwrap()
}
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn vecdb::AnyCollectableVec> {
let mut regular_iter: Box<dyn Iterator<Item = &dyn vecdb::AnyCollectableVec>> =
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
let mut regular_iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
Box::new(self.dateindex_extra.iter_any_collectable());
regular_iter = Box::new(regular_iter.chain(self.weekindex.iter_any_collectable()));
regular_iter = Box::new(regular_iter.chain(self.monthindex.iter_any_collectable()));

View File

@@ -5,7 +5,7 @@ use brk_types::{
DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, SemesterIndex,
Version, WeekIndex, YearIndex,
};
use vecdb::{AnyCloneableIterableVec, AnyIterableVec, Database, EagerVec, Exit};
use vecdb::{AnyCollectableVec, Database, EagerVec, Exit, IterableCloneableVec, IterableVec};
use crate::{
Indexes,
@@ -152,7 +152,7 @@ where
indexes: &indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
height_vec: Option<&impl AnyIterableVec<Height, T>>,
height_vec: Option<&impl IterableVec<Height, T>>,
) -> Result<()> {
if let Some(height) = height_vec {
self.height_extra
@@ -239,8 +239,8 @@ where
.unwrap()
}
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn vecdb::AnyCollectableVec> {
let mut regular_iter: Box<dyn Iterator<Item = &dyn vecdb::AnyCollectableVec>> =
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
let mut regular_iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
Box::new(self.height_extra.iter_any_collectable());
regular_iter = Box::new(regular_iter.chain(self.dateindex.iter_any_collectable()));
regular_iter = Box::new(regular_iter.chain(self.weekindex.iter_any_collectable()));

View File

@@ -2,7 +2,7 @@ use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{DifficultyEpoch, Height, Version};
use vecdb::{Database, EagerVec, Exit};
use vecdb::{AnyCollectableVec, Database, EagerVec, Exit};
use crate::{Indexes, indexes};
@@ -110,8 +110,8 @@ where
.merge_branches()
.unwrap()
}
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn vecdb::AnyCollectableVec> {
let mut regular_iter: Box<dyn Iterator<Item = &dyn vecdb::AnyCollectableVec>> =
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
let mut regular_iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
Box::new(self.height.iter_any_collectable());
regular_iter = Box::new(regular_iter.chain(self.height_extra.iter_any_collectable()));
regular_iter = Box::new(regular_iter.chain(self.difficultyepoch.iter_any_collectable()));

View File

@@ -6,8 +6,8 @@ use brk_types::{
Sats, SemesterIndex, TxIndex, Version, WeekIndex, YearIndex,
};
use vecdb::{
AnyCloneableIterableVec, AnyVec, CollectableVec, Database, EagerVec, Exit, GenericStoredVec,
StoredIndex, VecIteratorExtended,
AnyCollectableVec, AnyVec, CollectableVec, Database, EagerVec, Exit, GenericStoredVec,
IterableCloneableVec, StoredIndex, TypedVecIterator,
};
use crate::{
@@ -521,8 +521,8 @@ where
.unwrap()
}
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn vecdb::AnyCollectableVec> {
let mut regular_iter: Box<dyn Iterator<Item = &dyn vecdb::AnyCollectableVec>> =
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
let mut regular_iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
Box::new(self.height.iter_any_collectable());
regular_iter = Box::new(regular_iter.chain(self.dateindex.iter_any_collectable()));
regular_iter = Box::new(regular_iter.chain(self.weekindex.iter_any_collectable()));

View File

@@ -2,8 +2,8 @@ use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Date, DateIndex, Dollars, StoredF32, Version};
use vecdb::{
AnyIterableVec, AnyStoredVec, AnyVec, CollectableVec, Database, EagerVec, Exit,
GenericStoredVec, StoredIndex, VecIteratorExtended,
AnyStoredVec, AnyVec, CollectableVec, Database, EagerVec, Exit, GenericStoredVec, IterableVec,
StoredIndex, TypedVecIterator,
};
use crate::{
@@ -306,7 +306,7 @@ impl ComputedRatioVecsFromDateIndex {
price: &price::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
price_opt: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
price_opt: Option<&impl IterableVec<DateIndex, Dollars>>,
) -> Result<()> {
let closes = price.timeindexes_to_price_close.dateindex.as_ref().unwrap();

View File

@@ -2,8 +2,8 @@ use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Date, DateIndex, Dollars, StoredF32, Version};
use vecdb::{
AnyIterableVec, AnyStoredVec, AnyVec, BoxedVecIterator, CollectableVec, Database, EagerVec,
Exit, GenericStoredVec, StoredIndex,
AnyStoredVec, AnyVec, BoxedVecIterator, CollectableVec, Database, EagerVec, Exit,
GenericStoredVec, IterableVec, StoredIndex,
};
use crate::{Indexes, grouped::source::Source, indexes};
@@ -422,7 +422,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
starting_indexes: &Indexes,
exit: &Exit,
source: &impl CollectableVec<DateIndex, StoredF32>,
price_opt: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
price_opt: Option<&impl IterableVec<DateIndex, Dollars>>,
) -> Result<()> {
let min_date = DateIndex::try_from(Date::MIN_RATIO).unwrap();
@@ -449,9 +449,9 @@ impl ComputedStandardDeviationVecsFromDateIndex {
&mut self,
starting_indexes: &Indexes,
exit: &Exit,
sma_opt: Option<&impl AnyIterableVec<DateIndex, StoredF32>>,
sma_opt: Option<&impl IterableVec<DateIndex, StoredF32>>,
source: &impl CollectableVec<DateIndex, StoredF32>,
price_opt: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
price_opt: Option<&impl IterableVec<DateIndex, Dollars>>,
) -> Result<()> {
let sma = sma_opt.unwrap_or_else(|| unsafe {
std::mem::transmute(&self.sma.as_ref().unwrap().dateindex)

View File

@@ -1,10 +1,10 @@
use vecdb::AnyBoxedIterableVec;
use vecdb::IterableBoxedVec;
#[derive(Clone)]
pub enum Source<I, T> {
Compute,
None,
Vec(AnyBoxedIterableVec<I, T>),
Vec(IterableBoxedVec<I, T>),
}
impl<I, T> Source<I, T> {
@@ -20,7 +20,7 @@ impl<I, T> Source<I, T> {
matches!(self, Self::Vec(_))
}
pub fn vec(self) -> Option<AnyBoxedIterableVec<I, T>> {
pub fn vec(self) -> Option<IterableBoxedVec<I, T>> {
match self {
Self::Vec(v) => Some(v),
_ => None,
@@ -35,16 +35,16 @@ impl<I, T> From<bool> for Source<I, T> {
}
}
impl<I, T> From<AnyBoxedIterableVec<I, T>> for Source<I, T> {
impl<I, T> From<IterableBoxedVec<I, T>> for Source<I, T> {
#[inline]
fn from(value: AnyBoxedIterableVec<I, T>) -> Self {
fn from(value: IterableBoxedVec<I, T>) -> Self {
Self::Vec(value)
}
}
impl<I, T> From<Option<AnyBoxedIterableVec<I, T>>> for Source<I, T> {
impl<I, T> From<Option<IterableBoxedVec<I, T>>> for Source<I, T> {
#[inline]
fn from(value: Option<AnyBoxedIterableVec<I, T>>) -> Self {
fn from(value: Option<IterableBoxedVec<I, T>>) -> Self {
if let Some(v) = value {
Self::Vec(v)
} else {

View File

@@ -3,8 +3,8 @@ use brk_indexer::Indexer;
use brk_traversable::Traversable;
use brk_types::{Bitcoin, Close, Dollars, Height, Sats, TxIndex, Version};
use vecdb::{
AnyCloneableIterableVec, CollectableVec, Database, Exit, LazyVecFrom1, LazyVecFrom3,
StoredIndex, StoredVec,
CollectableVec, Database, Exit, IterableCloneableVec, LazyVecFrom1, LazyVecFrom3, StoredIndex,
StoredVec,
};
use crate::{Indexes, grouped::Source, indexes, price};

View File

@@ -13,8 +13,8 @@ use brk_types::{
YearIndex,
};
use vecdb::{
AnyCloneableIterableVec, Database, EagerVec, Exit, LazyVecFrom1, LazyVecFrom2, PAGE_SIZE,
StoredIndex, VecIteratorExtended,
Database, EagerVec, Exit, IterableCloneableVec, LazyVecFrom1, LazyVecFrom2, PAGE_SIZE,
StoredIndex, TypedVecIterator,
};
const VERSION: Version = Version::ZERO;

View File

@@ -3,9 +3,7 @@ use std::{path::Path, thread};
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Date, DateIndex, Dollars, Height, Sats, StoredF32, StoredU16, Version};
use vecdb::{
Database, EagerVec, Exit, GenericStoredVec, PAGE_SIZE, StoredIndex, VecIteratorExtended,
};
use vecdb::{Database, EagerVec, Exit, GenericStoredVec, PAGE_SIZE, StoredIndex, TypedVecIterator};
use crate::{
grouped::{ComputedStandardDeviationVecsFromDateIndex, Source, StandardDeviationVecsOptions},

View File

@@ -7,8 +7,8 @@ use brk_traversable::Traversable;
use brk_types::{Address, AddressBytes, Height, OutputType, PoolId, Pools, TxOutIndex, pools};
use rayon::prelude::*;
use vecdb::{
AnyIterableVec, AnyStoredVec, AnyVec, Database, Exit, GenericStoredVec, PAGE_SIZE, RawVec,
StoredIndex, VecIteratorExtended, Version,
AnyStoredVec, AnyVec, Database, Exit, GenericStoredVec, IterableVec, PAGE_SIZE, RawVec,
StoredIndex, TypedVecIterator, Version,
};
mod vecs;

View File

@@ -1,7 +1,7 @@
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Height, PoolId, Pools, Sats, StoredF32, StoredU16, StoredU32};
use vecdb::{AnyIterableVec, Database, Exit, GenericStoredVec, StoredIndex, Version};
use vecdb::{Database, Exit, GenericStoredVec, IterableVec, StoredIndex, Version};
use crate::{
chain,
@@ -164,7 +164,7 @@ impl Vecs {
&mut self,
indexes: &indexes::Vecs,
starting_indexes: &Indexes,
height_to_pool: &impl AnyIterableVec<Height, PoolId>,
height_to_pool: &impl IterableVec<Height, PoolId>,
chain: &chain::Vecs,
price: Option<&price::Vecs>,
exit: &Exit,

View File

@@ -7,7 +7,7 @@ use brk_types::{
OHLCDollars, OHLCSats, Open, QuarterIndex, Sats, SemesterIndex, Version, WeekIndex, YearIndex,
};
use vecdb::{
AnyIterableVec, AnyStoredVec, AnyVec, Database, EagerVec, Exit, GenericStoredVec, PAGE_SIZE,
AnyStoredVec, AnyVec, Database, EagerVec, Exit, GenericStoredVec, IterableVec, PAGE_SIZE,
RawVec, StoredIndex,
};

View File

@@ -4,8 +4,8 @@ use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Bitcoin, DateIndex, Dollars, Height, StoredU64, Version};
use vecdb::{
AnyIterableVec, AnyStoredVec, AnyVec, Database, EagerVec, Exit, Format, GenericStoredVec,
VecIteratorExtended,
AnyStoredVec, AnyVec, Database, EagerVec, Exit, Format, GenericStoredVec, IterableVec,
TypedVecIterator,
};
use crate::{
@@ -216,12 +216,12 @@ impl CohortVecs for Vecs {
indexes: &indexes::Vecs,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
height_to_supply: &impl AnyIterableVec<Height, Bitcoin>,
dateindex_to_supply: &impl AnyIterableVec<DateIndex, Bitcoin>,
height_to_market_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_market_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
height_to_realized_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
height_to_supply: &impl IterableVec<Height, Bitcoin>,
dateindex_to_supply: &impl IterableVec<DateIndex, Bitcoin>,
height_to_market_cap: Option<&impl IterableVec<Height, Dollars>>,
dateindex_to_market_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
height_to_realized_cap: Option<&impl IterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
exit: &Exit,
) -> Result<()> {
self.inner.compute_rest_part2(

View File

@@ -5,7 +5,7 @@ use brk_grouper::{AddressGroups, ByAmountRange, ByGreatEqualAmount, ByLowerThanA
use brk_traversable::Traversable;
use brk_types::{Bitcoin, DateIndex, Dollars, Height, Version};
use derive_deref::{Deref, DerefMut};
use vecdb::{AnyIterableVec, Database, Exit, Format};
use vecdb::{Database, Exit, Format, IterableVec};
use crate::{
Indexes, indexes, price,
@@ -514,12 +514,12 @@ impl Vecs {
indexes: &indexes::Vecs,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
height_to_supply: &impl AnyIterableVec<Height, Bitcoin>,
dateindex_to_supply: &impl AnyIterableVec<DateIndex, Bitcoin>,
height_to_market_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_market_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
height_to_realized_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
height_to_supply: &impl IterableVec<Height, Bitcoin>,
dateindex_to_supply: &impl IterableVec<DateIndex, Bitcoin>,
height_to_market_cap: Option<&impl IterableVec<Height, Dollars>>,
dateindex_to_market_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
height_to_realized_cap: Option<&impl IterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
exit: &Exit,
) -> Result<()> {
self.0.iter_mut().map(Filtered::mut_t).try_for_each(|v| {

View File

@@ -1,7 +1,7 @@
use brk_grouper::ByAddressType;
use brk_types::Height;
use derive_deref::{Deref, DerefMut};
use vecdb::VecIteratorExtended;
use vecdb::TypedVecIterator;
use super::AddressTypeToHeightToAddressCount;

View File

@@ -4,8 +4,8 @@ use brk_types::{
Bitcoin, DateIndex, Dollars, Height, Sats, StoredF32, StoredF64, StoredU64, Version,
};
use vecdb::{
AnyCloneableIterableVec, AnyIterableVec, AnyStoredVec, AnyVec, Database, EagerVec, Exit,
Format, GenericStoredVec, VecIteratorExtended,
AnyStoredVec, AnyVec, Database, EagerVec, Exit, Format, GenericStoredVec, IterableCloneableVec,
IterableVec, TypedVecIterator,
};
use crate::{
@@ -2173,12 +2173,12 @@ impl Vecs {
indexes: &indexes::Vecs,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
height_to_supply: &impl AnyIterableVec<Height, Bitcoin>,
dateindex_to_supply: &impl AnyIterableVec<DateIndex, Bitcoin>,
height_to_market_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_market_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
height_to_realized_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
height_to_supply: &impl IterableVec<Height, Bitcoin>,
dateindex_to_supply: &impl IterableVec<DateIndex, Bitcoin>,
height_to_market_cap: Option<&impl IterableVec<Height, Dollars>>,
dateindex_to_market_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
height_to_realized_cap: Option<&impl IterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
exit: &Exit,
) -> Result<()> {
if let Some(v) = self.indexes_to_supply_rel_to_circulating_supply.as_mut() {

View File

@@ -16,9 +16,9 @@ use rayon::prelude::*;
use rustc_hash::FxHashMap;
use smallvec::SmallVec;
use vecdb::{
AnyCloneableIterableVec, AnyIterableVec, AnyStoredVec, AnyVec, BoxedVecIterator,
CollectableVec, Database, EagerVec, Exit, Format, GenericStoredVec, ImportOptions,
LazyVecFrom1, PAGE_SIZE, RawVec, Reader, Stamp, StoredIndex, VecIteratorExtended,
AnyStoredVec, AnyVec, BoxedVecIterator, CollectableVec, Database, EagerVec, Exit, Format,
GenericStoredVec, ImportOptions, IterableCloneableVec, IterableVec, LazyVecFrom1, PAGE_SIZE,
RawVec, Reader, Stamp, StoredIndex, TypedVecIterator,
};
use crate::{
@@ -782,8 +782,8 @@ impl Vecs {
let mut height_to_output_count_iter = height_to_output_count.into_iter();
let mut height_to_tx_count_iter = height_to_tx_count.into_iter();
let mut height_to_unclaimed_rewards_iter = height_to_unclaimed_rewards.into_iter();
let mut txindex_to_input_count_iter = txindex_to_input_count.boxed_iter();
let mut txindex_to_output_count_iter = txindex_to_output_count.boxed_iter();
let mut txindex_to_input_count_iter = txindex_to_input_count.iter();
let mut txindex_to_output_count_iter = txindex_to_output_count.iter();
let height_to_price_close_vec =
height_to_price_close.map(|height_to_price_close| height_to_price_close.collect());

View File

@@ -1,6 +1,6 @@
use brk_error::Result;
use brk_types::{Bitcoin, DateIndex, Dollars, Height, Version};
use vecdb::{AnyIterableVec, Exit};
use vecdb::{Exit, IterableVec};
use crate::{Indexes, indexes, price};
@@ -49,12 +49,12 @@ pub trait CohortVecs: DynCohortVecs {
indexes: &indexes::Vecs,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
height_to_supply: &impl AnyIterableVec<Height, Bitcoin>,
dateindex_to_supply: &impl AnyIterableVec<DateIndex, Bitcoin>,
height_to_market_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_market_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
height_to_realized_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
height_to_supply: &impl IterableVec<Height, Bitcoin>,
dateindex_to_supply: &impl IterableVec<DateIndex, Bitcoin>,
height_to_market_cap: Option<&impl IterableVec<Height, Dollars>>,
dateindex_to_market_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
height_to_realized_cap: Option<&impl IterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
exit: &Exit,
) -> Result<()>;
}

View File

@@ -3,7 +3,7 @@ use std::{ops::Deref, path::Path};
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Bitcoin, DateIndex, Dollars, Height, Version};
use vecdb::{AnyIterableVec, Database, Exit, Format};
use vecdb::{Database, Exit, Format, IterableVec};
use crate::{
Indexes, UTXOCohortState, indexes, price,
@@ -154,12 +154,12 @@ impl CohortVecs for Vecs {
indexes: &indexes::Vecs,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
height_to_supply: &impl AnyIterableVec<Height, Bitcoin>,
dateindex_to_supply: &impl AnyIterableVec<DateIndex, Bitcoin>,
height_to_market_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_market_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
height_to_realized_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
height_to_supply: &impl IterableVec<Height, Bitcoin>,
dateindex_to_supply: &impl IterableVec<DateIndex, Bitcoin>,
height_to_market_cap: Option<&impl IterableVec<Height, Dollars>>,
dateindex_to_market_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
height_to_realized_cap: Option<&impl IterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
exit: &Exit,
) -> Result<()> {
self.inner.compute_rest_part2(

View File

@@ -11,7 +11,7 @@ use brk_types::{
};
use derive_deref::{Deref, DerefMut};
use rustc_hash::FxHashMap;
use vecdb::{AnyIterableVec, Database, Exit, Format, StoredIndex};
use vecdb::{Database, Exit, Format, IterableVec, StoredIndex};
use crate::{
Indexes, indexes, price,
@@ -1718,12 +1718,12 @@ impl Vecs {
indexes: &indexes::Vecs,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
height_to_supply: &impl AnyIterableVec<Height, Bitcoin>,
dateindex_to_supply: &impl AnyIterableVec<DateIndex, Bitcoin>,
height_to_market_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_market_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
height_to_realized_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
height_to_supply: &impl IterableVec<Height, Bitcoin>,
dateindex_to_supply: &impl IterableVec<DateIndex, Bitcoin>,
height_to_market_cap: Option<&impl IterableVec<Height, Dollars>>,
dateindex_to_market_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
height_to_realized_cap: Option<&impl IterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl IterableVec<DateIndex, Dollars>>,
exit: &Exit,
) -> Result<()> {
self.iter_mut().map(Filtered::mut_t).try_for_each(|v| {

View File

@@ -1,7 +1,7 @@
use brk_error::Result;
use brk_types::{Bitcoin, CheckedSub, Close, Date, DateIndex, Dollars, Sats, StoredF32};
use vecdb::{
AnyIterableVec, AnyStoredVec, AnyVec, EagerVec, Exit, GenericStoredVec, StoredIndex, Version,
AnyStoredVec, AnyVec, EagerVec, Exit, GenericStoredVec, IterableVec, StoredIndex, Version,
};
const DCA_AMOUNT: Dollars = Dollars::mint(100.0);
@@ -10,7 +10,7 @@ pub trait ComputeDCAStackViaLen {
fn compute_dca_stack_via_len(
&mut self,
max_from: DateIndex,
closes: &impl AnyIterableVec<DateIndex, Close<Dollars>>,
closes: &impl IterableVec<DateIndex, Close<Dollars>>,
len: usize,
exit: &Exit,
) -> Result<()>;
@@ -18,7 +18,7 @@ pub trait ComputeDCAStackViaLen {
fn compute_dca_stack_via_from(
&mut self,
max_from: DateIndex,
closes: &impl AnyIterableVec<DateIndex, Close<Dollars>>,
closes: &impl IterableVec<DateIndex, Close<Dollars>>,
from: DateIndex,
exit: &Exit,
) -> Result<()>;
@@ -27,7 +27,7 @@ impl ComputeDCAStackViaLen for EagerVec<DateIndex, Sats> {
fn compute_dca_stack_via_len(
&mut self,
max_from: DateIndex,
closes: &impl AnyIterableVec<DateIndex, Close<Dollars>>,
closes: &impl IterableVec<DateIndex, Close<Dollars>>,
len: usize,
exit: &Exit,
) -> Result<()> {
@@ -82,7 +82,7 @@ impl ComputeDCAStackViaLen for EagerVec<DateIndex, Sats> {
fn compute_dca_stack_via_from(
&mut self,
max_from: DateIndex,
closes: &impl AnyIterableVec<DateIndex, Close<Dollars>>,
closes: &impl IterableVec<DateIndex, Close<Dollars>>,
from: DateIndex,
exit: &Exit,
) -> Result<()> {
@@ -130,7 +130,7 @@ pub trait ComputeDCAAveragePriceViaLen {
fn compute_dca_avg_price_via_len(
&mut self,
max_from: DateIndex,
stacks: &impl AnyIterableVec<DateIndex, Sats>,
stacks: &impl IterableVec<DateIndex, Sats>,
len: usize,
exit: &Exit,
) -> Result<()>;
@@ -138,7 +138,7 @@ pub trait ComputeDCAAveragePriceViaLen {
fn compute_dca_avg_price_via_from(
&mut self,
max_from: DateIndex,
stacks: &impl AnyIterableVec<DateIndex, Sats>,
stacks: &impl IterableVec<DateIndex, Sats>,
from: DateIndex,
exit: &Exit,
) -> Result<()>;
@@ -147,7 +147,7 @@ impl ComputeDCAAveragePriceViaLen for EagerVec<DateIndex, Dollars> {
fn compute_dca_avg_price_via_len(
&mut self,
max_from: DateIndex,
stacks: &impl AnyIterableVec<DateIndex, Sats>,
stacks: &impl IterableVec<DateIndex, Sats>,
len: usize,
exit: &Exit,
) -> Result<()> {
@@ -185,7 +185,7 @@ impl ComputeDCAAveragePriceViaLen for EagerVec<DateIndex, Dollars> {
fn compute_dca_avg_price_via_from(
&mut self,
max_from: DateIndex,
stacks: &impl AnyIterableVec<DateIndex, Sats>,
stacks: &impl IterableVec<DateIndex, Sats>,
from: DateIndex,
exit: &Exit,
) -> Result<()> {
@@ -219,7 +219,7 @@ pub trait ComputeFromSats<I> {
fn compute_from_sats(
&mut self,
max_from: I,
sats: &impl AnyIterableVec<I, Sats>,
sats: &impl IterableVec<I, Sats>,
exit: &Exit,
) -> Result<()>;
}
@@ -230,7 +230,7 @@ where
fn compute_from_sats(
&mut self,
max_from: I,
sats: &impl AnyIterableVec<I, Sats>,
sats: &impl IterableVec<I, Sats>,
exit: &Exit,
) -> Result<()> {
self.validate_computed_version_or_reset(
@@ -256,8 +256,8 @@ pub trait ComputeFromBitcoin<I> {
fn compute_from_bitcoin(
&mut self,
max_from: I,
bitcoin: &impl AnyIterableVec<I, Bitcoin>,
price: &impl AnyIterableVec<I, Close<Dollars>>,
bitcoin: &impl IterableVec<I, Bitcoin>,
price: &impl IterableVec<I, Close<Dollars>>,
exit: &Exit,
) -> Result<()>;
}
@@ -268,8 +268,8 @@ where
fn compute_from_bitcoin(
&mut self,
max_from: I,
bitcoin: &impl AnyIterableVec<I, Bitcoin>,
price: &impl AnyIterableVec<I, Close<Dollars>>,
bitcoin: &impl IterableVec<I, Bitcoin>,
price: &impl IterableVec<I, Close<Dollars>>,
exit: &Exit,
) -> Result<()> {
self.validate_computed_version_or_reset(
@@ -298,8 +298,8 @@ pub trait ComputeDrawdown<I> {
fn compute_drawdown(
&mut self,
max_from: I,
close: &impl AnyIterableVec<I, Close<Dollars>>,
ath: &impl AnyIterableVec<I, Dollars>,
close: &impl IterableVec<I, Close<Dollars>>,
ath: &impl IterableVec<I, Dollars>,
exit: &Exit,
) -> Result<()>;
}
@@ -310,8 +310,8 @@ where
fn compute_drawdown(
&mut self,
max_from: I,
close: &impl AnyIterableVec<I, Close<Dollars>>,
ath: &impl AnyIterableVec<I, Dollars>,
close: &impl IterableVec<I, Close<Dollars>>,
ath: &impl IterableVec<I, Dollars>,
exit: &Exit,
) -> Result<()> {
self.validate_computed_version_or_reset(

View File

@@ -1,5 +1,6 @@
use brk_traversable::Traversable;
use rayon::prelude::*;
use vecdb::AnyCollectableVec;
use crate::Filtered;
@@ -77,14 +78,14 @@ where
)
}
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn vecdb::AnyCollectableVec> {
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
[
Box::new(self.ge_amount.iter_any_collectable())
as Box<dyn Iterator<Item = &dyn vecdb::AnyCollectableVec>>,
as Box<dyn Iterator<Item = &dyn AnyCollectableVec>>,
Box::new(self.amount_range.iter_any_collectable())
as Box<dyn Iterator<Item = &dyn vecdb::AnyCollectableVec>>,
as Box<dyn Iterator<Item = &dyn AnyCollectableVec>>,
Box::new(self.lt_amount.iter_any_collectable())
as Box<dyn Iterator<Item = &dyn vecdb::AnyCollectableVec>>,
as Box<dyn Iterator<Item = &dyn AnyCollectableVec>>,
]
.into_iter()
.flatten()

View File

@@ -2,14 +2,12 @@
MBP M3 Pro
0..920750
Range: ~0..920_000
Time: 13h 6mn (checked) / 12h 20mn (unchecked)
Time: ~10h30mn
RAM:
Peak: ~12GB
After auto compaction: ~6.5GB
Peak: ~11GB
At the end: ~6.5GB
storage: 223GB
mode: checked

View File

@@ -5,7 +5,7 @@ use brk_types::{
P2WPKHAddressIndex, P2WSHAddressIndex, TxInIndex, TxIndex, TxOutIndex, TypeIndex,
UnknownOutputIndex,
};
use vecdb::{AnyIterableVec, AnyStoredIterableVec, GenericStoredVec, StoredIndex, StoredRaw};
use vecdb::{GenericStoredVec, IterableStoredVec, IterableVec, StoredIndex, StoredRaw};
use crate::{Stores, Vecs};
@@ -219,8 +219,8 @@ impl From<(Height, &mut Vecs, &Stores)> for Indexes {
}
pub fn starting_index<I, T>(
height_to_index: &impl AnyStoredIterableVec<Height, I>,
index_to_else: &impl AnyIterableVec<I, T>,
height_to_index: &impl IterableStoredVec<Height, I>,
index_to_else: &impl IterableVec<I, T>,
starting_height: Height,
) -> Option<I>
where

View File

@@ -15,7 +15,7 @@ use brk_types::{
use log::{error, info};
use rayon::prelude::*;
use rustc_hash::{FxHashMap, FxHashSet};
use vecdb::{AnyVec, Exit, GenericStoredVec, Reader, VecIteratorExtended};
use vecdb::{AnyVec, Exit, GenericStoredVec, Reader, TypedVecIterator};
mod indexes;
mod stores_v2;
// mod stores_v3;
@@ -117,8 +117,6 @@ impl Indexer {
let i = Instant::now();
vecs.flush(height)?;
info!("Flushed vecs in {}s", i.elapsed().as_secs());
let i = Instant::now();
info!("Flushed db in {}s", i.elapsed().as_secs());
Ok(())
};

View File

@@ -10,7 +10,7 @@ use brk_types::{
};
use fjall2::{CompressionType as Compression, PersistMode, TransactionalKeyspace};
use rayon::prelude::*;
use vecdb::{AnyVec, GenericStoredVec, StoredIndex, VecIterator, VecIteratorExtended};
use vecdb::{AnyVec, GenericStoredVec, StoredIndex, TypedVecIterator, VecIterator};
use crate::Indexes;

View File

@@ -9,7 +9,7 @@ use brk_types::{
};
use fjall3::{Database, PersistMode};
use rayon::prelude::*;
use vecdb::{AnyVec, GenericStoredVec, StoredIndex, VecIterator, VecIteratorExtended};
use vecdb::{AnyVec, GenericStoredVec, StoredIndex, TypedVecIterator, VecIterator};
use crate::Indexes;

View File

@@ -10,7 +10,6 @@ rust-version.workspace = true
build = "build.rs"
[dependencies]
bitcoin = { workspace = true }
brk_error = { workspace = true }
brk_reader = { workspace = true }
brk_rpc = { workspace = true }

View File

@@ -16,9 +16,8 @@ brk_rmcp = { version = "0.8.0", features = [
"transport-worker",
"transport-streamable-http-server",
] }
brk_types = { workspace = true }
log = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
[package.metadata.cargo-machete]

View File

@@ -8,9 +8,8 @@ use brk_rmcp::{
service::RequestContext,
tool, tool_handler, tool_router,
};
use brk_types::Metric;
use log::info;
use schemars::JsonSchema;
use serde::Deserialize;
pub mod route;
@@ -97,11 +96,11 @@ The list will be empty if the vec id isn't correct.
")]
async fn get_vecid_to_indexes(
&self,
Parameters(param): Parameters<IdParam>,
Parameters(metric): Parameters<Metric>,
) -> Result<CallToolResult, McpError> {
info!("mcp: get_vecid_to_indexes");
Ok(CallToolResult::success(vec![
Content::json(self.query.metric_to_indexes(param.id).await).unwrap(),
Content::json(self.query.metric_to_indexes(metric).await).unwrap(),
]))
}
@@ -170,8 +169,3 @@ An 'Index' (or indexes) is the timeframe of a dataset.
Ok(self.get_info())
}
}
#[derive(Debug, Deserialize, JsonSchema)]
pub struct IdParam {
pub id: String,
}

View File

@@ -10,7 +10,6 @@ rust-version.workspace = true
build = "build.rs"
[dependencies]
bitcoin = { workspace = true }
brk_error = { workspace = true }
brk_rpc = { workspace = true }
brk_types = { workspace = true }

View File

@@ -21,10 +21,14 @@ use crate::{
pub struct AsyncQuery(Query);
impl AsyncQuery {
pub async fn build(reader: &Reader, indexer: &Indexer, computer: &Computer) -> Self {
pub fn build(reader: &Reader, indexer: &Indexer, computer: &Computer) -> Self {
Self(Query::build(reader, indexer, computer))
}
pub fn inner(&self) -> &Query {
&self.0
}
pub async fn get_height(&self) -> Height {
self.0.get_height()
}
@@ -104,7 +108,7 @@ impl AsyncQuery {
self.0.get_index_to_vecids(paginated_index)
}
pub async fn metric_to_indexes(&self, metric: String) -> Option<&Vec<Index>> {
pub async fn metric_to_indexes(&self, metric: Metric) -> Option<&Vec<Index>> {
self.0.metric_to_indexes(metric)
}

View File

@@ -6,7 +6,7 @@ use brk_types::{
Address, AddressBytes, AddressChainStats, AddressHash, AddressMempoolStats, AddressStats,
AnyAddressDataIndexEnum, OutputType,
};
use vecdb::{AnyIterableVec, VecIteratorExtended};
use vecdb::{IterableVec, TypedVecIterator};
use crate::Query;

View File

@@ -8,7 +8,7 @@ use bitcoin::consensus::Decodable;
use brk_error::{Error, Result};
use brk_reader::XORIndex;
use brk_types::{Transaction, Txid, TxidPath, TxidPrefix};
use vecdb::VecIteratorExtended;
use vecdb::TypedVecIterator;
use crate::Query;

View File

@@ -120,15 +120,65 @@ impl Query {
// .collect::<Result<Vec<_>>>()
}
fn columns_to_csv(
columns: &[&&dyn AnyCollectableVec],
from: Option<i64>,
to: Option<i64>,
) -> Result<String> {
if columns.is_empty() {
return Ok(String::new());
}
let num_rows = columns[0].range_count(from, to);
let num_cols = columns.len();
let estimated_size = num_cols * 10 + num_rows * num_cols * 15;
let mut csv = String::with_capacity(estimated_size);
// Write headers from column names
for (idx, col) in columns.iter().enumerate() {
if idx > 0 {
csv.push(',');
}
csv.push_str(col.name());
}
csv.push('\n');
let mut iters: Vec<_> = columns
.iter()
.map(|col| col.iter_range_strings(from, to))
.collect();
for _ in 0..num_rows {
for (index, iter) in iters.iter_mut().enumerate() {
if index > 0 {
csv.push(',');
}
if let Some(field) = iter.next() {
if field.contains(',') {
csv.push('"');
csv.push_str(&field);
csv.push('"');
} else {
csv.push_str(&field);
}
}
}
csv.push('\n');
}
Ok(csv)
}
pub fn format(
&self,
metrics: Vec<(String, &&dyn AnyCollectableVec)>,
metrics: Vec<&&dyn AnyCollectableVec>,
params: &ParamsOpt,
) -> Result<Output> {
let from = params.from().map(|from| {
metrics
.iter()
.map(|(_, v)| v.i64_to_usize(from))
.map(|v| v.i64_to_usize(from))
.min()
.unwrap_or_default()
});
@@ -136,7 +186,7 @@ impl Query {
let to = params.to().map(|to| {
metrics
.iter()
.map(|(_, v)| v.i64_to_usize(to))
.map(|v| v.i64_to_usize(to))
.min()
.unwrap_or_default()
});
@@ -144,56 +194,15 @@ impl Query {
let format = params.format();
Ok(match format {
Format::CSV => {
let headers = metrics
.iter()
.map(|(id, _)| id.as_str())
.collect::<Vec<_>>();
let mut values = metrics
.iter()
.map(|(_, vec)| vec.collect_range_string(from, to))
.collect::<Vec<_>>();
if values.is_empty() {
return Ok(Output::CSV(headers.join(",")));
}
let first_len = values[0].len();
let estimated_size = (headers.len() + values.len() * first_len) * 15;
let mut csv = String::with_capacity(estimated_size);
csv.push_str(&headers.join(","));
csv.push('\n');
for col_index in 0..first_len {
let mut first = true;
for vec in &mut values {
if col_index < vec.len() {
if !first {
csv.push(',');
}
first = false;
let field = std::mem::take(&mut vec[col_index]);
if field.contains(',') {
csv.push('"');
csv.push_str(&field);
csv.push('"');
} else {
csv.push_str(&field);
}
}
}
csv.push('\n');
}
Output::CSV(csv)
}
Format::CSV => Output::CSV(Self::columns_to_csv(
&metrics,
from.map(|v| v as i64),
to.map(|v| v as i64),
)?),
Format::JSON => {
let mut values = metrics
.iter()
.map(|(_, vec)| vec.collect_range_json_bytes(from, to))
.map(|vec| vec.collect_range_json_bytes(from, to))
.collect::<Vec<_>>();
if values.is_empty() {
@@ -253,7 +262,7 @@ impl Query {
self.vecs().index_to_ids(paginated_index)
}
pub fn metric_to_indexes(&self, metric: String) -> Option<&Vec<Index>> {
pub fn metric_to_indexes(&self, metric: Metric) -> Option<&Vec<Index>> {
self.vecs().metric_to_indexes(metric)
}

View File

@@ -148,7 +148,7 @@ impl<'a> Vecs<'a> {
}
}
pub fn metric_to_indexes(&self, metric: String) -> Option<&Vec<Index>> {
pub fn metric_to_indexes(&self, metric: Metric) -> Option<&Vec<Index>> {
self.metric_to_indexes
.get(metric.replace("-", "_").as_str())
}

View File

@@ -12,7 +12,6 @@ build = "build.rs"
[dependencies]
aide = { workspace = true }
axum = { workspace = true }
bitcoin = { workspace = true }
brk_computer = { workspace = true }
brk_error = { workspace = true }
brk_fetcher = { workspace = true }
@@ -30,7 +29,6 @@ jiff = { workspace = true }
log = { workspace = true }
quick_cache = "0.6.18"
schemars = { workspace = true }
serde = { workspace = true }
sonic-rs = { workspace = true }
tokio = { workspace = true }
tower-http = { version = "0.6.6", features = ["compression-full", "trace"] }

View File

@@ -10,7 +10,7 @@ use brk_error::Result;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
use brk_iterator::Blocks;
use brk_query::Query;
use brk_query::AsyncQuery;
use brk_reader::Reader;
use brk_rpc::{Auth, Client};
use brk_server::Server;
@@ -53,7 +53,7 @@ fn run() -> Result<()> {
let exit = Exit::new();
exit.set_ctrlc_handler();
let query = Query::build(&reader, &indexer, &computer);
let query = AsyncQuery::build(&reader, &indexer, &computer);
let future = async move {
let server = Server::new(&query, None);

View File

@@ -59,7 +59,7 @@ impl ApiMetricsRoutes for ApiRouter<AppState> {
if headers.has_etag(etag) {
return Response::new_not_modified();
}
state.get_indexes().await.to_json_response(etag)
Response::new_json( state.get_indexes().await, etag)
},
|op| op
.metrics_tag()
@@ -148,10 +148,11 @@ impl ApiMetricsRoutes for ApiRouter<AppState> {
if headers.has_etag(etag) {
return Response::new_not_modified();
}
if let Some(indexes) = state.metric_to_indexes(metric.clone()) {
if let Some(indexes) = state.metric_to_indexes(metric.clone()).await {
return Response::new_json(indexes, etag)
}
let value = if let Some(first) = state.match_metric(metric, Limit::MIN).await?.first() {
// REMOVE UNWRAP !!
let value = if let Some(first) = state.match_metric(metric.clone(), Limit::MIN).await.unwrap().first() {
format!("Could not find '{metric}', did you mean '{first}' ?")
} else {
format!("Could not find '{metric}'.")

View File

@@ -16,9 +16,6 @@ brk_error = { workspace = true }
brk_types = { workspace = true }
byteview6 = { version = "=0.6.1", package = "byteview" }
byteview8 = { version = "~0.8.0", package = "byteview" }
candystore = "0.5.5"
fjall2 = { workspace = true }
fjall3 = { workspace = true }
log = { workspace = true }
parking_lot = { workspace = true }
rustc-hash = { workspace = true }

View File

@@ -4,7 +4,7 @@ use derive_deref::Deref;
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(Debug, Deref, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Deref, Deserialize, JsonSchema)]
pub struct Metric {
/// Metric name
#[schemars(example = &"price_close", example = &"market_cap", example = &"realized_price")]