diff --git a/Cargo.lock b/Cargo.lock index bdcacd37e..dc77b0c9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -710,6 +710,7 @@ dependencies = [ "jiff", "log", "owo-colors", + "parking_lot", ] [[package]] diff --git a/crates/brk_bencher/src/lib.rs b/crates/brk_bencher/src/lib.rs index cd634ed7b..77ffd7344 100644 --- a/crates/brk_bencher/src/lib.rs +++ b/crates/brk_bencher/src/lib.rs @@ -15,6 +15,7 @@ use brk_error::Result; pub struct Bencher { bench_dir: PathBuf, + monitored_path: PathBuf, stop_flag: Arc, monitor_thread: Option>>, } @@ -22,7 +23,7 @@ pub struct Bencher { impl Bencher { /// Create a new bencher for the given crate name /// Creates directory structure: workspace_root/benches/{crate_name}/{timestamp}/ - pub fn new(crate_name: &str, workspace_root: &Path) -> Result { + pub fn new(crate_name: &str, workspace_root: &Path, monitored_path: &Path) -> Result { let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs(); let bench_dir = workspace_root @@ -34,18 +35,36 @@ impl Bencher { Ok(Self { bench_dir, + monitored_path: monitored_path.to_path_buf(), stop_flag: Arc::new(AtomicBool::new(false)), monitor_thread: None, }) } /// Create a bencher using CARGO_MANIFEST_DIR to find workspace root - pub fn from_cargo_env() -> Result { - let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR")) - .parent() - .ok_or("Failed to find workspace root")?; - let crate_name = env!("CARGO_PKG_NAME"); - Self::new(crate_name, workspace_root) + pub fn from_cargo_env(crate_name: &str, monitored_path: &Path) -> Result { + let mut current = std::env::current_dir() + .map_err(|e| format!("Failed to get current directory: {}", e)) + .unwrap(); + + let workspace_root = loop { + let cargo_toml = current.join("Cargo.toml"); + if cargo_toml.exists() { + let contents = std::fs::read_to_string(&cargo_toml) + .map_err(|e| format!("Failed to read Cargo.toml: {}", e)) + .unwrap(); + if contents.contains("[workspace]") { + break current; + } + } + + current = current + .parent() + .ok_or("Workspace root not found")? + .to_path_buf(); + }; + + Self::new(crate_name, &workspace_root, monitored_path) } /// Start monitoring disk usage and memory footprint @@ -56,8 +75,10 @@ impl Bencher { let stop_flag = self.stop_flag.clone(); let bench_dir = self.bench_dir.clone(); + let monitored_path = self.monitored_path.clone(); - let handle = thread::spawn(move || monitor_resources(&bench_dir, stop_flag)); + let handle = + thread::spawn(move || monitor_resources(&monitored_path, &bench_dir, stop_flag)); self.monitor_thread = Some(handle); Ok(()) @@ -189,7 +210,11 @@ fn get_memory_usage(pid: u32) -> Result<(f64, f64)> { } } -fn monitor_resources(bench_dir: &Path, stop_flag: Arc) -> Result<()> { +fn monitor_resources( + monitored_path: &Path, + bench_dir: &Path, + stop_flag: Arc, +) -> Result<()> { let disk_file = bench_dir.join("disk_usage.csv"); let memory_file = bench_dir.join("memory_footprint.csv"); @@ -210,23 +235,21 @@ fn monitor_resources(bench_dir: &Path, stop_flag: Arc) -> Result<()> // Get disk usage if let Ok(output) = Command::new("du") - .args(["-sh", bench_dir.to_str().unwrap()]) + .args(["-sh", monitored_path.to_str().unwrap()]) .output() && let Ok(stdout) = String::from_utf8(output.stdout) && let Some(size_str) = stdout.split_whitespace().next() && let Some(size_mb) = parse_du_output(size_str) { writeln!(disk_writer, "{},{}", elapsed_ms, size_mb)?; - disk_writer.flush()?; } // Get memory footprint (cross-platform) if let Ok((footprint, peak)) = get_memory_usage(pid) { writeln!(memory_writer, "{},{},{}", elapsed_ms, footprint, peak)?; - memory_writer.flush()?; } - thread::sleep(Duration::from_secs(1)); + thread::sleep(Duration::from_secs(5)); } Ok(()) diff --git a/crates/brk_bencher_visualizer/src/lib.rs b/crates/brk_bencher_visualizer/src/lib.rs index 56dadde14..4efb89a9a 100644 --- a/crates/brk_bencher_visualizer/src/lib.rs +++ b/crates/brk_bencher_visualizer/src/lib.rs @@ -18,6 +18,18 @@ struct BenchmarkRun { data: Vec, } +// Dark theme colors +const BG_COLOR: RGBColor = RGBColor(18, 18, 24); +const TEXT_COLOR: RGBColor = RGBColor(230, 230, 240); +const CHART_COLORS: [RGBColor; 6] = [ + RGBColor(255, 99, 132), // Pink/Red + RGBColor(54, 162, 235), // Blue + RGBColor(75, 192, 192), // Teal + RGBColor(255, 206, 86), // Yellow + RGBColor(153, 102, 255), // Purple + RGBColor(255, 159, 64), // Orange +]; + pub struct Visualizer { workspace_root: PathBuf, } @@ -32,6 +44,7 @@ impl Visualizer { pub fn from_cargo_env() -> Result { let workspace_root = Path::new(env!("CARGO_MANIFEST_DIR")) .parent() + .and_then(|p| p.parent()) .ok_or("Failed to find workspace root")? .to_path_buf(); Ok(Self { workspace_root }) @@ -141,10 +154,10 @@ impl Visualizer { crate_name: &str, runs: &[BenchmarkRun], ) -> Result<()> { - let output_path = crate_path.join("disk_usage_chart.png"); + let output_path = crate_path.join("disk_usage_chart.svg"); - let root = BitMapBackend::new(&output_path, (1200, 800)).into_drawing_area(); - root.fill(&WHITE)?; + let root = SVGBackend::new(&output_path, (1200, 700)).into_drawing_area(); + root.fill(&BG_COLOR)?; let max_time = runs .iter() @@ -157,40 +170,59 @@ impl Visualizer { .flat_map(|r| r.data.iter().map(|d| d.value)) .fold(0.0_f64, f64::max); + // Convert to seconds and GB + let max_time_s = (max_time as f64) / 1000.0; + let max_value_gb = max_value / 1024.0; + let mut chart = ChartBuilder::on(&root) .caption( - format!("{} - Disk Usage", crate_name), - ("sans-serif", 40).into_font(), + format!("{} — Disk Usage", crate_name), + ("SF Mono", 24).into_font().color(&TEXT_COLOR), ) - .margin(10) - .x_label_area_size(40) - .y_label_area_size(60) - .build_cartesian_2d(0u64..max_time, 0.0..max_value * 1.1)?; + .margin(20) + .x_label_area_size(55) + .y_label_area_size(75) + .build_cartesian_2d(0.0..max_time_s * 1.05, 0.0..max_value_gb * 1.1)?; chart .configure_mesh() - .x_desc("Time (ms)") - .y_desc("Disk Usage (MB)") + .disable_mesh() + .x_desc("Time (s)") + .y_desc("Disk Usage (GB)") + .x_label_offset(10) + .y_label_offset(10) + .x_label_formatter(&|x| format!("{:.1}", x)) + .y_label_formatter(&|y| format!("{:.2}", y)) + .x_labels(8) + .y_labels(6) + .x_label_style(("SF Mono", 16).into_font().color(&TEXT_COLOR.mix(0.7))) + .y_label_style(("SF Mono", 16).into_font().color(&TEXT_COLOR.mix(0.7))) + .axis_style(TEXT_COLOR.mix(0.3)) .draw()?; - let colors = [&RED, &BLUE, &GREEN, &CYAN, &MAGENTA, &YELLOW]; - for (idx, run) in runs.iter().enumerate() { - let color = colors[idx % colors.len()]; + let color = CHART_COLORS[idx % CHART_COLORS.len()]; chart .draw_series(LineSeries::new( - run.data.iter().map(|d| (d.timestamp_ms, d.value)), - color, + run.data + .iter() + .map(|d| (d.timestamp_ms as f64 / 1000.0, d.value / 1024.0)), + color.stroke_width(2), ))? .label(&run.run_id) - .legend(move |(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], color)); + .legend(move |(x, y)| { + PathElement::new(vec![(x, y), (x + 20, y)], color.stroke_width(2)) + }); } chart .configure_series_labels() - .background_style(WHITE.mix(0.8)) - .border_style(BLACK) + .position(SeriesLabelPosition::UpperLeft) + .label_font(("SF Mono", 16).into_font().color(&TEXT_COLOR.mix(0.9))) + .background_style(BG_COLOR.mix(0.98)) + .border_style(BG_COLOR) + .margin(10) .draw()?; root.present()?; @@ -205,10 +237,10 @@ impl Visualizer { crate_name: &str, runs: &[BenchmarkRun], ) -> Result<()> { - let output_path = crate_path.join("memory_footprint_chart.png"); + let output_path = crate_path.join("memory_footprint_chart.svg"); - let root = BitMapBackend::new(&output_path, (1200, 800)).into_drawing_area(); - root.fill(&WHITE)?; + let root = SVGBackend::new(&output_path, (1200, 700)).into_drawing_area(); + root.fill(&BG_COLOR)?; // Read memory CSV files which have 3 columns: timestamp, footprint, peak let mut enhanced_runs = Vec::new(); @@ -259,55 +291,87 @@ impl Visualizer { .flat_map(|(_, f, p)| f.iter().chain(p.iter()).map(|d| d.value)) .fold(0.0_f64, f64::max); + // Convert to seconds and GB + let max_time_s = (max_time as f64) / 1000.0; + let max_value_gb = max_value / 1024.0; + let mut chart = ChartBuilder::on(&root) .caption( - format!("{} - Memory Footprint", crate_name), - ("sans-serif", 40).into_font(), + format!("{} — Memory Footprint", crate_name), + ("SF Mono", 24).into_font().color(&TEXT_COLOR), ) - .margin(10) - .x_label_area_size(40) - .y_label_area_size(60) - .build_cartesian_2d(0u64..max_time, 0.0..max_value * 1.1)?; + .margin(20) + .x_label_area_size(55) + .y_label_area_size(75) + .build_cartesian_2d(0.0..max_time_s * 1.05, 0.0..max_value_gb * 1.1)?; chart .configure_mesh() - .x_desc("Time (ms)") - .y_desc("Memory (MB)") + .disable_mesh() + .x_desc("Time (s)") + .y_desc("Memory (GB)") + .x_label_offset(10) + .y_label_offset(10) + .x_label_formatter(&|x| format!("{:.1}", x)) + .y_label_formatter(&|y| format!("{:.2}", y)) + .x_labels(8) + .y_labels(6) + .x_label_style(("SF Mono", 16).into_font().color(&TEXT_COLOR.mix(0.7))) + .y_label_style(("SF Mono", 16).into_font().color(&TEXT_COLOR.mix(0.7))) + .axis_style(TEXT_COLOR.mix(0.3)) .draw()?; - let colors = [&RED, &BLUE, &GREEN, &CYAN, &MAGENTA, &YELLOW]; - for (idx, (run_id, footprint_data, peak_data)) in enhanced_runs.iter().enumerate() { - let color = colors[idx % colors.len()]; + let color = CHART_COLORS[idx % CHART_COLORS.len()]; // Draw footprint line (solid) chart .draw_series(LineSeries::new( - footprint_data.iter().map(|d| (d.timestamp_ms, d.value)), - color, + footprint_data + .iter() + .map(|d| (d.timestamp_ms as f64 / 1000.0, d.value / 1024.0)), + color.stroke_width(2), ))? .label(format!("{} (current)", run_id)) - .legend(move |(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], color)); + .legend(move |(x, y)| { + PathElement::new(vec![(x, y), (x + 20, y)], color.stroke_width(2)) + }); - // Draw peak line (dashed) + // Draw peak line (dashed, slightly transparent) + let dashed_color = color.mix(0.5); chart - .draw_series(LineSeries::new( - peak_data.iter().map(|d| (d.timestamp_ms, d.value)), - color.stroke_width(2).filled(), - ))? + .draw_series( + peak_data + .iter() + .map(|d| (d.timestamp_ms as f64 / 1000.0, d.value / 1024.0)) + .zip( + peak_data + .iter() + .skip(1) + .map(|d| (d.timestamp_ms as f64 / 1000.0, d.value / 1024.0)), + ) + .enumerate() + .filter(|(i, _)| i % 2 == 0) // Create dashed effect + .map(|(_, (p1, p2))| { + PathElement::new(vec![p1, p2], dashed_color.stroke_width(2)) + }), + )? .label(format!("{} (peak)", run_id)) .legend(move |(x, y)| { PathElement::new( vec![(x, y), (x + 10, y), (x + 20, y)], - color.stroke_width(2), + dashed_color.stroke_width(2), ) }); } chart .configure_series_labels() - .background_style(WHITE.mix(0.8)) - .border_style(BLACK) + .position(SeriesLabelPosition::UpperLeft) + .label_font(("SF Mono", 16).into_font().color(&TEXT_COLOR.mix(0.9))) + .background_style(BG_COLOR.mix(0.98)) + .border_style(BG_COLOR) + .margin(10) .draw()?; root.present()?; diff --git a/crates/brk_computer/src/chain.rs b/crates/brk_computer/src/chain.rs index d67250022..3f0e1a5d8 100644 --- a/crates/brk_computer/src/chain.rs +++ b/crates/brk_computer/src/chain.rs @@ -11,7 +11,7 @@ use brk_types::{ }; use vecdb::{ Database, EagerVec, Exit, IterableCloneableVec, IterableVec, LazyVecFrom1, LazyVecFrom2, - LazyVecFrom3, PAGE_SIZE, StoredIndex, TypedVecIterator, + LazyVecFrom3, PAGE_SIZE, TypedVecIterator, VecIndex, }; use crate::grouped::{ diff --git a/crates/brk_computer/src/fetched.rs b/crates/brk_computer/src/fetched.rs index 13eababa9..3eb0c3254 100644 --- a/crates/brk_computer/src/fetched.rs +++ b/crates/brk_computer/src/fetched.rs @@ -7,7 +7,7 @@ use brk_traversable::Traversable; use brk_types::{DateIndex, Height, OHLCCents, Version}; use vecdb::{ AnyStoredVec, AnyVec, Database, Exit, GenericStoredVec, IterableVec, PAGE_SIZE, RawVec, - StoredIndex, VecIterator, + VecIndex, VecIterator, }; use super::{Indexes, indexes}; diff --git a/crates/brk_computer/src/grouped/builder_eager.rs b/crates/brk_computer/src/grouped/builder_eager.rs index 4076b25de..332a0ffed 100644 --- a/crates/brk_computer/src/grouped/builder_eager.rs +++ b/crates/brk_computer/src/grouped/builder_eager.rs @@ -3,7 +3,7 @@ use brk_traversable::Traversable; use brk_types::{CheckedSub, StoredU64, Version}; use vecdb::{ AnyStoredVec, AnyVec, Database, EagerVec, Exit, Format, GenericStoredVec, IterableVec, - StoredIndex, StoredRaw, + VecIndex, VecValue, }; use crate::utils::get_percentile; @@ -13,7 +13,7 @@ use super::ComputedType; #[derive(Clone, Debug, Traversable)] pub struct EagerVecsBuilder where - I: StoredIndex, + I: VecIndex, T: ComputedType, { pub first: Option>>, @@ -34,7 +34,7 @@ const VERSION: Version = Version::ZERO; impl EagerVecsBuilder where - I: StoredIndex, + I: VecIndex, T: ComputedType, { pub fn forced_import_compressed( @@ -244,7 +244,7 @@ where exit: &Exit, ) -> Result<()> where - I2: StoredIndex + StoredRaw + CheckedSub, + I2: VecIndex + VecValue + CheckedSub, { self.validate_computed_version_or_reset( source.version() + first_indexes.version() + count_indexes.version(), @@ -403,7 +403,7 @@ where exit: &Exit, ) -> Result<()> where - I2: StoredIndex + StoredRaw + CheckedSub, + I2: VecIndex + VecValue + CheckedSub, { if self.pct90.is_some() || self.pct75.is_some() diff --git a/crates/brk_computer/src/grouped/builder_lazy.rs b/crates/brk_computer/src/grouped/builder_lazy.rs index 804bc1d45..1b30fc6e0 100644 --- a/crates/brk_computer/src/grouped/builder_lazy.rs +++ b/crates/brk_computer/src/grouped/builder_lazy.rs @@ -1,6 +1,6 @@ use brk_traversable::Traversable; use brk_types::Version; -use vecdb::{FromCoarserIndex, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2, StoredIndex}; +use vecdb::{FromCoarserIndex, IterableBoxedVec, IterableCloneableVec, LazyVecFrom2, VecIndex}; use crate::grouped::{EagerVecsBuilder, VecBuilderOptions}; @@ -10,9 +10,9 @@ use super::ComputedType; #[derive(Clone, Traversable)] pub struct LazyVecsBuilder where - I: StoredIndex, + I: VecIndex, T: ComputedType, - S1I: StoredIndex, + S1I: VecIndex, S2T: ComputedType, { pub first: Option>>, @@ -28,9 +28,9 @@ const VERSION: Version = Version::ZERO; impl LazyVecsBuilder where - I: StoredIndex, + I: VecIndex, T: ComputedType + 'static, - S1I: StoredIndex + 'static + FromCoarserIndex, + S1I: VecIndex + 'static + FromCoarserIndex, S2T: ComputedType, { #[allow(clippy::too_many_arguments)] diff --git a/crates/brk_computer/src/grouped/computed.rs b/crates/brk_computer/src/grouped/computed.rs index 7b7e3bad8..aeff1a3ac 100644 --- a/crates/brk_computer/src/grouped/computed.rs +++ b/crates/brk_computer/src/grouped/computed.rs @@ -1,23 +1,25 @@ use std::ops::{Add, AddAssign, Div}; -use vecdb::StoredCompressed; +use vecdb::{Compressable, Formattable}; pub trait ComputedType where - Self: StoredCompressed - + From - + Div - + Add - + AddAssign - + Ord, -{ -} -impl ComputedType for T where - T: StoredCompressed + Self: Compressable + From + Div + Add + AddAssign + Ord + + Formattable, +{ +} +impl ComputedType for T where + T: Compressable + + From + + Div + + Add + + AddAssign + + Ord + + Formattable { } diff --git a/crates/brk_computer/src/grouped/from_txindex.rs b/crates/brk_computer/src/grouped/from_txindex.rs index d61b5f7b9..3a74b94d9 100644 --- a/crates/brk_computer/src/grouped/from_txindex.rs +++ b/crates/brk_computer/src/grouped/from_txindex.rs @@ -7,7 +7,7 @@ use brk_types::{ }; use vecdb::{ AnyVec, AnyWritableVec, CollectableVec, Database, EagerVec, Exit, GenericStoredVec, - IterableCloneableVec, StoredIndex, TypedVecIterator, + IterableCloneableVec, TypedVecIterator, VecIndex, }; use crate::{ diff --git a/crates/brk_computer/src/grouped/ratio_from_dateindex.rs b/crates/brk_computer/src/grouped/ratio_from_dateindex.rs index 5aaf58083..43a38acdd 100644 --- a/crates/brk_computer/src/grouped/ratio_from_dateindex.rs +++ b/crates/brk_computer/src/grouped/ratio_from_dateindex.rs @@ -3,7 +3,7 @@ use brk_traversable::Traversable; use brk_types::{Date, DateIndex, Dollars, StoredF32, Version}; use vecdb::{ AnyStoredVec, AnyVec, CollectableVec, Database, EagerVec, Exit, GenericStoredVec, IterableVec, - StoredIndex, TypedVecIterator, + TypedVecIterator, VecIndex, }; use crate::{ diff --git a/crates/brk_computer/src/grouped/sd_from_dateindex.rs b/crates/brk_computer/src/grouped/sd_from_dateindex.rs index 1916144c3..38e1eeca0 100644 --- a/crates/brk_computer/src/grouped/sd_from_dateindex.rs +++ b/crates/brk_computer/src/grouped/sd_from_dateindex.rs @@ -3,7 +3,7 @@ use brk_traversable::Traversable; use brk_types::{Date, DateIndex, Dollars, StoredF32, Version}; use vecdb::{ AnyStoredVec, AnyVec, BoxedVecIterator, CollectableVec, Database, EagerVec, Exit, - GenericStoredVec, IterableVec, StoredIndex, + GenericStoredVec, IterableVec, VecIndex, }; use crate::{Indexes, grouped::source::Source, indexes}; diff --git a/crates/brk_computer/src/grouped/value_from_txindex.rs b/crates/brk_computer/src/grouped/value_from_txindex.rs index 4bcf24352..aaacacd0f 100644 --- a/crates/brk_computer/src/grouped/value_from_txindex.rs +++ b/crates/brk_computer/src/grouped/value_from_txindex.rs @@ -3,8 +3,8 @@ use brk_indexer::Indexer; use brk_traversable::Traversable; use brk_types::{Bitcoin, Close, Dollars, Height, Sats, TxIndex, Version}; use vecdb::{ - CollectableVec, Database, Exit, IterableCloneableVec, LazyVecFrom1, LazyVecFrom3, StoredIndex, - StoredVec, + CollectableVec, Database, Exit, IterableCloneableVec, LazyVecFrom1, LazyVecFrom3, StoredVec, + VecIndex, }; use crate::{Indexes, grouped::Source, indexes, price}; diff --git a/crates/brk_computer/src/indexes.rs b/crates/brk_computer/src/indexes.rs index 3e58f5a99..d9608402e 100644 --- a/crates/brk_computer/src/indexes.rs +++ b/crates/brk_computer/src/indexes.rs @@ -14,7 +14,7 @@ use brk_types::{ }; use vecdb::{ Database, EagerVec, Exit, IterableCloneableVec, LazyVecFrom1, LazyVecFrom2, PAGE_SIZE, - StoredIndex, TypedVecIterator, + TypedVecIterator, VecIndex, }; const VERSION: Version = Version::ZERO; diff --git a/crates/brk_computer/src/market.rs b/crates/brk_computer/src/market.rs index 67e55a2e0..784458c00 100644 --- a/crates/brk_computer/src/market.rs +++ b/crates/brk_computer/src/market.rs @@ -3,7 +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, TypedVecIterator}; +use vecdb::{Database, EagerVec, Exit, GenericStoredVec, PAGE_SIZE, TypedVecIterator, VecIndex}; use crate::{ grouped::{ComputedStandardDeviationVecsFromDateIndex, Source, StandardDeviationVecsOptions}, diff --git a/crates/brk_computer/src/pools/mod.rs b/crates/brk_computer/src/pools/mod.rs index b0a4f85b4..ba7dd4f53 100644 --- a/crates/brk_computer/src/pools/mod.rs +++ b/crates/brk_computer/src/pools/mod.rs @@ -8,7 +8,7 @@ use brk_types::{Address, AddressBytes, Height, OutputType, PoolId, Pools, TxOutI use rayon::prelude::*; use vecdb::{ AnyStoredVec, AnyVec, Database, Exit, GenericStoredVec, IterableVec, PAGE_SIZE, RawVec, - StoredIndex, TypedVecIterator, Version, + TypedVecIterator, VecIndex, Version, }; mod vecs; diff --git a/crates/brk_computer/src/pools/vecs.rs b/crates/brk_computer/src/pools/vecs.rs index 25129d9f1..50b23e547 100644 --- a/crates/brk_computer/src/pools/vecs.rs +++ b/crates/brk_computer/src/pools/vecs.rs @@ -1,7 +1,7 @@ use brk_error::Result; use brk_traversable::Traversable; use brk_types::{Height, PoolId, Pools, Sats, StoredF32, StoredU16, StoredU32}; -use vecdb::{Database, Exit, GenericStoredVec, IterableVec, StoredIndex, Version}; +use vecdb::{Database, Exit, GenericStoredVec, IterableVec, VecIndex, Version}; use crate::{ chain, diff --git a/crates/brk_computer/src/price.rs b/crates/brk_computer/src/price.rs index 09ab7b202..03ecb06f6 100644 --- a/crates/brk_computer/src/price.rs +++ b/crates/brk_computer/src/price.rs @@ -8,7 +8,7 @@ use brk_types::{ }; use vecdb::{ AnyStoredVec, AnyVec, Database, EagerVec, Exit, GenericStoredVec, IterableVec, PAGE_SIZE, - RawVec, StoredIndex, + RawVec, VecIndex, }; use crate::{fetched, grouped::Source}; diff --git a/crates/brk_computer/src/stateful/mod.rs b/crates/brk_computer/src/stateful/mod.rs index 8ec6b686a..2f62667eb 100644 --- a/crates/brk_computer/src/stateful/mod.rs +++ b/crates/brk_computer/src/stateful/mod.rs @@ -18,7 +18,7 @@ use smallvec::SmallVec; use vecdb::{ AnyStoredVec, AnyVec, BoxedVecIterator, CollectableVec, Database, EagerVec, Exit, Format, GenericStoredVec, ImportOptions, IterableCloneableVec, IterableVec, LazyVecFrom1, PAGE_SIZE, - RawVec, Reader, Stamp, StoredIndex, TypedVecIterator, + RawVec, Reader, Stamp, TypedVecIterator, VecIndex, }; use crate::{ diff --git a/crates/brk_computer/src/stateful/range_map.rs b/crates/brk_computer/src/stateful/range_map.rs index 7ba972c9c..f9e800a36 100644 --- a/crates/brk_computer/src/stateful/range_map.rs +++ b/crates/brk_computer/src/stateful/range_map.rs @@ -1,14 +1,14 @@ use std::collections::BTreeMap; -use vecdb::{CompressedVec, RawVec, StoredCompressed, StoredIndex, StoredRaw}; +use vecdb::{Compressable, CompressedVec, RawVec, VecIndex, VecValue}; #[derive(Debug)] pub struct RangeMap(BTreeMap); impl RangeMap where - I: StoredIndex, - T: StoredIndex, + I: VecIndex, + T: VecIndex, { pub fn get(&self, key: I) -> Option<&T> { self.0.range(..=key).next_back().map(|(&min, value)| { @@ -22,8 +22,8 @@ where impl From<&RawVec> for RangeMap where - I: StoredIndex, - T: StoredIndex + StoredRaw, + I: VecIndex, + T: VecIndex + VecValue, { #[inline] fn from(vec: &RawVec) -> Self { @@ -38,8 +38,8 @@ where impl From<&CompressedVec> for RangeMap where - I: StoredIndex, - T: StoredIndex + StoredCompressed, + I: VecIndex, + T: VecIndex + Compressable, { #[inline] fn from(vec: &CompressedVec) -> Self { diff --git a/crates/brk_computer/src/stateful/utxo_cohorts.rs b/crates/brk_computer/src/stateful/utxo_cohorts.rs index 7bb9efd16..9257b4431 100644 --- a/crates/brk_computer/src/stateful/utxo_cohorts.rs +++ b/crates/brk_computer/src/stateful/utxo_cohorts.rs @@ -11,7 +11,7 @@ use brk_types::{ }; use derive_deref::{Deref, DerefMut}; use rustc_hash::FxHashMap; -use vecdb::{Database, Exit, Format, IterableVec, StoredIndex}; +use vecdb::{Database, Exit, Format, IterableVec, VecIndex}; use crate::{ Indexes, indexes, price, diff --git a/crates/brk_computer/src/states/supply.rs b/crates/brk_computer/src/states/supply.rs index 63792042c..99abddfcf 100644 --- a/crates/brk_computer/src/states/supply.rs +++ b/crates/brk_computer/src/states/supply.rs @@ -2,6 +2,7 @@ use std::ops::{Add, AddAssign, SubAssign}; use brk_types::{CheckedSub, LoadedAddressData, Sats}; use serde::Serialize; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; #[derive(Debug, Default, Clone, FromBytes, Immutable, IntoBytes, KnownLayout, Serialize)] @@ -55,3 +56,10 @@ impl std::fmt::Display for SupplyState { write!(f, "utxos: {}, value: {}", self.utxo_count, self.value) } } + +impl Formattable for SupplyState { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} diff --git a/crates/brk_computer/src/traits.rs b/crates/brk_computer/src/traits.rs index c48ca0547..3cace9c11 100644 --- a/crates/brk_computer/src/traits.rs +++ b/crates/brk_computer/src/traits.rs @@ -1,7 +1,7 @@ use brk_error::Result; use brk_types::{Bitcoin, CheckedSub, Close, Date, DateIndex, Dollars, Sats, StoredF32}; use vecdb::{ - AnyStoredVec, AnyVec, EagerVec, Exit, GenericStoredVec, IterableVec, StoredIndex, Version, + AnyStoredVec, AnyVec, EagerVec, Exit, GenericStoredVec, IterableVec, VecIndex, Version, }; const DCA_AMOUNT: Dollars = Dollars::mint(100.0); @@ -225,7 +225,7 @@ pub trait ComputeFromSats { } impl ComputeFromSats for EagerVec where - I: StoredIndex, + I: VecIndex, { fn compute_from_sats( &mut self, @@ -263,7 +263,7 @@ pub trait ComputeFromBitcoin { } impl ComputeFromBitcoin for EagerVec where - I: StoredIndex, + I: VecIndex, { fn compute_from_bitcoin( &mut self, @@ -305,7 +305,7 @@ pub trait ComputeDrawdown { } impl ComputeDrawdown for EagerVec where - I: StoredIndex, + I: VecIndex, { fn compute_drawdown( &mut self, diff --git a/crates/brk_indexer/examples/indexer_bench.rs b/crates/brk_indexer/examples/indexer_bench.rs index c112e6218..5f9e288a3 100644 --- a/crates/brk_indexer/examples/indexer_bench.rs +++ b/crates/brk_indexer/examples/indexer_bench.rs @@ -34,13 +34,16 @@ fn main() -> Result<()> { let exit = Exit::new(); exit.set_ctrlc_handler(); - let mut bencher = Bencher::from_cargo_env()?; + let mut bencher = + Bencher::from_cargo_env(env!("CARGO_PKG_NAME"), &outputs_dir.join("indexed/stores"))?; bencher.start()?; let i = Instant::now(); indexer.checked_index(&blocks, &client, &exit)?; dbg!(i.elapsed()); + drop(indexer); + // Stop and finalize bencher.stop()?; diff --git a/crates/brk_indexer/examples/indexer_single_vs_multi.rs b/crates/brk_indexer/examples/indexer_single_vs_multi.rs index bc7eabe02..1395ec01d 100644 --- a/crates/brk_indexer/examples/indexer_single_vs_multi.rs +++ b/crates/brk_indexer/examples/indexer_single_vs_multi.rs @@ -9,7 +9,7 @@ use brk_error::Result; use brk_indexer::Indexer; use brk_types::TxInIndex; use rayon::prelude::*; -use vecdb::{AnyVec, GenericStoredVec, StoredIndex}; +use vecdb::{AnyVec, GenericStoredVec, VecIndex}; fn main() -> Result<()> { brk_logger::init(Some(Path::new(".log")))?; diff --git a/crates/brk_indexer/src/indexes.rs b/crates/brk_indexer/src/indexes.rs index 801ed843a..555349526 100644 --- a/crates/brk_indexer/src/indexes.rs +++ b/crates/brk_indexer/src/indexes.rs @@ -6,7 +6,7 @@ use brk_types::{ UnknownOutputIndex, }; use log::debug; -use vecdb::{GenericStoredVec, IterableStoredVec, IterableVec, StoredIndex, StoredRaw}; +use vecdb::{GenericStoredVec, IterableStoredVec, IterableVec, VecIndex, VecValue}; use crate::{Stores, Vecs}; @@ -227,8 +227,8 @@ pub fn starting_index( starting_height: Height, ) -> Option where - I: StoredRaw + StoredIndex + From, - T: StoredRaw, + I: VecValue + VecIndex + From, + T: VecValue, { let h = Height::from(height_to_index.stamp()); if h.is_zero() { diff --git a/crates/brk_indexer/src/stores_v2.rs b/crates/brk_indexer/src/stores_v2.rs index b642befe7..9deda2125 100644 --- a/crates/brk_indexer/src/stores_v2.rs +++ b/crates/brk_indexer/src/stores_v2.rs @@ -10,7 +10,7 @@ use brk_types::{ }; use fjall2::{CompressionType as Compression, PersistMode, TransactionalKeyspace}; use rayon::prelude::*; -use vecdb::{AnyVec, GenericStoredVec, StoredIndex, TypedVecIterator, VecIterator}; +use vecdb::{AnyVec, GenericStoredVec, TypedVecIterator, VecIndex, VecIterator}; use crate::Indexes; diff --git a/crates/brk_indexer/src/stores_v3.rs b/crates/brk_indexer/src/stores_v3.rs index e927e03d1..6f63594b1 100644 --- a/crates/brk_indexer/src/stores_v3.rs +++ b/crates/brk_indexer/src/stores_v3.rs @@ -8,9 +8,9 @@ use brk_types::{ OutPoint, OutputType, StoredString, TxIndex, TxOutIndex, TxidPrefix, TypeIndex, Unit, Version, Vout, }; -use fjall3::{Database, PersistMode}; +use fjall3::{Database, PersistMode, WriteBatch}; use rayon::prelude::*; -use vecdb::{AnyVec, GenericStoredVec, StoredIndex, TypedVecIterator, VecIterator}; +use vecdb::{AnyVec, GenericStoredVec, TypedVecIterator, VecIndex, VecIterator}; use crate::Indexes; @@ -158,13 +158,10 @@ impl Stores { } pub fn commit(&mut self, height: Height) -> Result<()> { - [ + let items = [ &mut self.blockhashprefix_to_height as &mut dyn AnyStore, &mut self.height_to_coinbase_tag, &mut self.txidprefix_to_txindex, - // &mut self.addresshash_to_typeindex - // &mut self.addresstype_to_addressindex_and_txindex, - // &mut self.addresstype_to_addressindex_and_unspentoutpoint, ] .into_par_iter() .chain( @@ -182,7 +179,19 @@ impl Stores { .par_iter_mut() .map(|s| s as &mut dyn AnyStore), ) // Changed from par_iter_mut() - .try_for_each(|store| store.commit(height))?; + .map(|store| { + let items = store.take_all_f3(); + store.export_meta_if_needed(height)?; + Ok(items) + }) + .collect::>>()?; + + let capacity = items.iter().map(|v| v.len()).sum(); + let mut batch = WriteBatch::with_capacity(self.database.clone(), capacity); + items.into_iter().for_each(|items| { + batch.ingest(items); + }); + batch.commit()?; self.database .persist(PersistMode::SyncAll) diff --git a/crates/brk_logger/Cargo.toml b/crates/brk_logger/Cargo.toml index 66a0a90e7..e7db1a85b 100644 --- a/crates/brk_logger/Cargo.toml +++ b/crates/brk_logger/Cargo.toml @@ -14,3 +14,4 @@ env_logger = "0.11.8" jiff = { workspace = true } log = { workspace = true } owo-colors = "4.2.3" +parking_lot = { workspace = true } diff --git a/crates/brk_logger/src/lib.rs b/crates/brk_logger/src/lib.rs index 652af75ff..c1ced63d4 100644 --- a/crates/brk_logger/src/lib.rs +++ b/crates/brk_logger/src/lib.rs @@ -5,26 +5,27 @@ use std::{ fs::{self, OpenOptions}, io::{self, Write}, path::Path, + sync::OnceLock, }; use env_logger::{Builder, Env}; use jiff::{Timestamp, tz}; pub use owo_colors::OwoColorize; +use parking_lot::Mutex; + +static LOG_FILE: OnceLock> = OnceLock::new(); #[inline] pub fn init(path: Option<&Path>) -> io::Result<()> { - let file = path.map(|path| { + if let Some(path) = path { let _ = fs::remove_file(path); - OpenOptions::new() - .create(true) - .append(true) - .open(path) - .unwrap() - }); + let file = OpenOptions::new().create(true).append(true).open(path)?; + LOG_FILE.set(Mutex::new(file)).ok(); + } Builder::from_env(Env::default().default_filter_or( - // "info,bitcoin=off,bitcoincore-rpc=off,fjall=off,lsm-tree=off,rolldown=off,rolldown=off,rmcp=off,brk_rmcp=off,tracing=off,aide=off,brk_aide=off", - "debug,bitcoin=off,bitcoincore-rpc=off,rolldown=off,rolldown=off,rmcp=off,brk_rmcp=off,tracing=off,aide=off,brk_aide=off", + "info,bitcoin=off,bitcoincore-rpc=off,fjall=off,lsm-tree=off,rolldown=off,rolldown=off,rmcp=off,brk_rmcp=off,tracing=off,aide=off,brk_aide=off", + // "debug,fjall=trace,bitcoin=off,bitcoincore-rpc=off,rolldown=off,rolldown=off,rmcp=off,brk_rmcp=off,tracing=off,aide=off,brk_aide=off", )) .format(move |buf, record| { let date_time = Timestamp::now() @@ -37,15 +38,8 @@ pub fn init(path: Option<&Path>) -> io::Result<()> { let dash = "-"; let args = record.args(); - if let Some(file) = file.as_ref() { - let _ = write( - file.try_clone().unwrap(), - &date_time, - target, - &level, - dash, - args, - ); + if let Some(file) = LOG_FILE.get() { + let _ = write(&mut *file.lock(), &date_time, target, &level, dash, args); } let colored_date_time = date_time.bright_black(); diff --git a/crates/brk_query/src/lib.rs b/crates/brk_query/src/lib.rs index 2c32e76b0..2b73c34d3 100644 --- a/crates/brk_query/src/lib.rs +++ b/crates/brk_query/src/lib.rs @@ -155,22 +155,7 @@ impl Query { if index > 0 { csv.push(','); } - - // Check if we need CSV escaping - let start_pos = csv.len(); - - if writer.write_next(&mut csv)? { - let end_pos = csv.len(); - - // If contains comma, rewrite with quotes - if csv[start_pos..end_pos].contains(',') { - let value = csv[start_pos..end_pos].to_string(); // Only allocate if needed - csv.truncate(start_pos); - csv.push('"'); - csv.push_str(&value); - csv.push('"'); - } - } + writer.write_next(&mut csv)?; } csv.push('\n'); } diff --git a/crates/brk_store/src/any.rs b/crates/brk_store/src/any.rs index f1946386a..74eb2b245 100644 --- a/crates/brk_store/src/any.rs +++ b/crates/brk_store/src/any.rs @@ -1,6 +1,7 @@ use brk_error::Result; use brk_types::{Height, Version}; use fjall2::{InnerItem, PartitionHandle}; +use fjall3::Item; pub trait AnyStore: Send + Sync { fn name(&self) -> &'static str; @@ -11,6 +12,6 @@ pub trait AnyStore: Send + Sync { fn export_meta_if_needed(&mut self, height: Height) -> Result<()>; fn partition(&self) -> &PartitionHandle; fn take_all_f2(&mut self) -> Vec; - fn commit(&mut self) -> Result<()>; + fn take_all_f3(&mut self) -> Vec; // fn take_all_f3(&mut self) -> Box>; } diff --git a/crates/brk_store/src/fjall_v2/mod.rs b/crates/brk_store/src/fjall_v2/mod.rs index 9eceb5f64..76365a2ea 100644 --- a/crates/brk_store/src/fjall_v2/mod.rs +++ b/crates/brk_store/src/fjall_v2/mod.rs @@ -192,9 +192,9 @@ where items.into_iter().map(InnerItem::from).collect() } - // fn take_all_f3(&mut self) -> Box> { - // Box::new([].into_iter()) - // } + fn take_all_f3(&mut self) -> Vec { + panic!() + } fn export_meta_if_needed(&mut self, height: Height) -> Result<()> { if self.has(height) { @@ -204,43 +204,6 @@ where Ok(()) } - fn commit(&mut self) -> Result<()> { - if self.puts.is_empty() && self.dels.is_empty() { - return Ok(()); - } - - // if self.mode.is_unique_push_only() { - // if !self.dels.is_empty() { - // unreachable!(); - // } - // let mut puts = mem::take(&mut self.puts).into_iter().collect::>(); - // puts.sort_unstable_by(|(k1, _), (k2, _)| k1.cmp(k2)); - // dbg!(&puts); - // self.partition.ingest( - // puts.into_iter() - // .map(|(k, v)| (ByteView::from(k), ByteView::from(v))), - // )?; - // } else { - let mut items = mem::take(&mut self.puts) - .into_iter() - .map(|(key, value)| Item::Value { key, value }) - .chain( - mem::take(&mut self.dels) - .into_iter() - .map(|key| Item::Tomb(key)), - ) - .collect::>(); - items.sort_unstable(); - - // self.keyspace.inner().batch().commit_partition( - // self.partition.inner(), - // items.into_iter().map(InnerItem::from).collect::>(), - // )?; - // } - - Ok(()) - } - fn name(&self) -> &'static str { self.name } diff --git a/crates/brk_store/src/fjall_v3/mod.rs b/crates/brk_store/src/fjall_v3/mod.rs index 401b34aec..e021fd0eb 100644 --- a/crates/brk_store/src/fjall_v3/mod.rs +++ b/crates/brk_store/src/fjall_v3/mod.rs @@ -4,10 +4,7 @@ use brk_error::Result; use brk_types::{Height, Version}; use byteview8::ByteView; use fjall3::{ - Database, - Keyspace, - KeyspaceCreateOptions, - // ValueType, + Database, Keyspace, KeyspaceCreateOptions, ValueType, config::{BloomConstructionPolicy, FilterPolicy, FilterPolicyEntry, PinningPolicy}, }; @@ -22,7 +19,6 @@ use crate::any::AnyStore; pub struct StoreFjallV3 { meta: StoreMeta, name: &'static str, - database: Database, keyspace: Keyspace, puts: FxHashMap, dels: FxHashSet, @@ -67,7 +63,6 @@ where Ok(Self { meta, name: Box::leak(Box::new(name.to_string())), - database: database.clone(), keyspace, puts: FxHashMap::default(), dels: FxHashSet::default(), @@ -188,37 +183,7 @@ where panic!() } - // fn take_all_f3(&mut self) -> Box> { - // Box::new([].into_iter()) - // } - - fn export_meta_if_needed(&mut self, height: Height) -> Result<()> { - if self.has(height) { - return Ok(()); - } - self.meta.export(height)?; - Ok(()) - } - - fn commit(&mut self) -> Result<()> { - if self.puts.is_empty() && self.dels.is_empty() { - return Ok(()); - } - - // if self.mode.is_push_only() { - // if !self.dels.is_empty() { - // unreachable!(); - // } - // let mut puts = mem::take(&mut self.puts).into_iter().collect::>(); - // puts.sort_unstable_by(|(k1, _), (k2, _)| k1.cmp(k2)); - // // dbg!(&puts); - // self.keyspace.ingest( - // puts.into_iter() - // .map(|(k, v)| (ByteView::from(k), ByteView::from(v))), - // )?; - // } else { - let mut batch = self.database.batch(); - // let mut batch = self.database.inner().batch(); + fn take_all_f3(&mut self) -> Vec { let mut items = mem::take(&mut self.puts) .into_iter() .map(|(key, value)| Item::Value { key, value }) @@ -229,31 +194,17 @@ where ) .collect::>(); items.sort_unstable(); - items.into_iter().for_each(|item| match item { - Item::Value { key, value } => { - batch.insert(&self.keyspace, ByteView::from(key), ByteView::from(value)) - } - Item::Tomb(key) => batch.remove(&self.keyspace, ByteView::from(key)), - }); - batch.commit()?; - // } - - // batch.ingest( - // items - // .into_iter() - // .map(|i| i.fjalled(&self.keyspace)) - // .collect::>(), - // ); - // batch.commit_keyspace(&self.keyspace)?; - // batch.ingest( - // items - // .into_iter() - // .map(|i| i.fjalled(&self.keyspace)) - // .collect::>(), - // ); - // batch.commit_keyspace(&self.keyspace)?; - // batch.commit_keyspace(self.keyspace.inner())?; + items + .into_iter() + .map(|v| v.fjalled(&self.keyspace)) + .collect() + } + fn export_meta_if_needed(&mut self, height: Height) -> Result<()> { + if self.has(height) { + return Ok(()); + } + self.meta.export(height)?; Ok(()) } @@ -278,7 +229,7 @@ where } } -enum Item { +pub enum Item { Value { key: K, value: V }, Tomb(K), } @@ -310,28 +261,28 @@ impl Item { } } - // pub fn fjalled(self, keyspace: &Keyspace) -> fjall3::Item - // where - // K: Into, - // V: Into, - // { - // let keyspace_id = keyspace.id; - // // let keyspace_id = keyspace.inner().id; - // match self { - // Item::Value { key, value } => fjall3::Item { - // keyspace_id, - // key: key.into().into(), - // value: value.into().into(), - // value_type: ValueType::Value, - // }, - // Item::Tomb(key) => fjall3::Item { - // keyspace_id, - // key: key.into().into(), - // value: [].into(), - // value_type: ValueType::Tombstone, - // }, - // } - // } + pub fn fjalled(self, keyspace: &Keyspace) -> fjall3::Item + where + K: Into, + V: Into, + { + let keyspace_id = keyspace.id; + // let keyspace_id = keyspace.inner().id; + match self { + Item::Value { key, value } => fjall3::Item { + keyspace_id, + key: key.into().into(), + value: value.into().into(), + value_type: ValueType::Value, + }, + Item::Tomb(key) => fjall3::Item { + keyspace_id, + key: key.into().into(), + value: [].into(), + value_type: ValueType::Tombstone, + }, + } + } } #[derive(Debug, Clone, Copy)] diff --git a/crates/brk_traversable/src/lib.rs b/crates/brk_traversable/src/lib.rs index cba90737a..2c59b6bd9 100644 --- a/crates/brk_traversable/src/lib.rs +++ b/crates/brk_traversable/src/lib.rs @@ -5,8 +5,8 @@ pub use brk_types::TreeNode; #[cfg(feature = "derive")] pub use brk_traversable_derive::Traversable; use vecdb::{ - AnyVec, AnyWritableVec, CompressedVec, ComputedVec, EagerVec, LazyVecFrom1, LazyVecFrom2, - LazyVecFrom3, RawVec, StoredCompressed, StoredIndex, StoredRaw, StoredVec, + AnyVec, AnyWritableVec, Compressable, CompressedVec, ComputedVec, EagerVec, Formattable, + LazyVecFrom1, LazyVecFrom2, LazyVecFrom3, RawVec, StoredVec, VecIndex, VecValue, }; pub trait Traversable { @@ -16,8 +16,8 @@ pub trait Traversable { impl Traversable for RawVec where - I: StoredIndex, - T: StoredRaw, + I: VecIndex, + T: VecValue + Formattable, { fn iter_any_writable(&self) -> impl Iterator { std::iter::once(self as &dyn AnyWritableVec) @@ -30,8 +30,8 @@ where impl Traversable for CompressedVec where - I: StoredIndex, - T: StoredCompressed, + I: VecIndex, + T: Compressable + Formattable, { fn iter_any_writable(&self) -> impl Iterator { std::iter::once(self as &dyn AnyWritableVec) @@ -44,8 +44,8 @@ where impl Traversable for StoredVec where - I: StoredIndex, - T: StoredCompressed, + I: VecIndex, + T: Compressable + Formattable, { fn iter_any_writable(&self) -> impl Iterator { std::iter::once(self as &dyn AnyWritableVec) @@ -58,8 +58,8 @@ where impl Traversable for EagerVec where - I: StoredIndex, - T: StoredCompressed, + I: VecIndex, + T: Compressable + Formattable, { fn iter_any_writable(&self) -> impl Iterator { std::iter::once(self as &dyn AnyWritableVec) @@ -72,10 +72,10 @@ where impl Traversable for LazyVecFrom1 where - I: StoredIndex, - T: StoredRaw, - S1I: StoredIndex, - S1T: StoredRaw, + I: VecIndex, + T: VecValue + Formattable, + S1I: VecIndex, + S1T: VecValue, { fn iter_any_writable(&self) -> impl Iterator { std::iter::once(self as &dyn AnyWritableVec) @@ -88,12 +88,12 @@ where impl Traversable for LazyVecFrom2 where - I: StoredIndex, - T: StoredRaw, - S1I: StoredIndex, - S1T: StoredRaw, - S2I: StoredIndex, - S2T: StoredRaw, + I: VecIndex, + T: VecValue + Formattable, + S1I: VecIndex, + S1T: VecValue, + S2I: VecIndex, + S2T: VecValue, { fn iter_any_writable(&self) -> impl Iterator { std::iter::once(self as &dyn AnyWritableVec) @@ -107,14 +107,14 @@ where impl Traversable for LazyVecFrom3 where - I: StoredIndex, - T: StoredRaw, - S1I: StoredIndex, - S1T: StoredRaw, - S2I: StoredIndex, - S2T: StoredRaw, - S3I: StoredIndex, - S3T: StoredRaw, + I: VecIndex, + T: VecValue + Formattable, + S1I: VecIndex, + S1T: VecValue, + S2I: VecIndex, + S2T: VecValue, + S3I: VecIndex, + S3T: VecValue, { fn iter_any_writable(&self) -> impl Iterator { std::iter::once(self as &dyn AnyWritableVec) @@ -128,14 +128,14 @@ where impl Traversable for ComputedVec where - I: StoredIndex, - T: StoredCompressed, - S1I: StoredIndex, - S1T: StoredCompressed, - S2I: StoredIndex, - S2T: StoredCompressed, - S3I: StoredIndex, - S3T: StoredCompressed, + I: VecIndex, + T: Compressable + Formattable, + S1I: VecIndex, + S1T: Compressable, + S2I: VecIndex, + S2T: Compressable, + S3I: VecIndex, + S3T: Compressable, { fn iter_any_writable(&self) -> impl Iterator { std::iter::once(self as &dyn AnyWritableVec) diff --git a/crates/brk_types/README.md b/crates/brk_types/README.md index c8d19b35e..15ba96d60 100644 --- a/crates/brk_types/README.md +++ b/crates/brk_types/README.md @@ -244,7 +244,7 @@ Storage types provide space optimization: **Financial Types**: Multi-denomination OHLC support with automatic conversions \ **Address System**: Complete Bitcoin script type classification with 280 enum variants \ **Time Indexing**: Hierarchical calendar system from daily to decade-level granularity \ -**Storage Integration**: `vecdb::StoredCompressed` traits for efficient database operations \ +**Storage Integration**: `vecdb::Compressable` traits for efficient database operations \ **Architecture**: Type-driven design prioritizing memory efficiency and domain correctness --- diff --git a/crates/brk_types/src/addressbytes.rs b/crates/brk_types/src/addressbytes.rs index aedbea463..467b032c4 100644 --- a/crates/brk_types/src/addressbytes.rs +++ b/crates/brk_types/src/addressbytes.rs @@ -1,5 +1,3 @@ -use std::fmt; - use bitcoin::ScriptBuf; use brk_error::Error; @@ -39,12 +37,6 @@ impl AddressBytes { } } -impl fmt::Display for AddressBytes { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(&super::Address::try_from(self).unwrap().to_string()) - } -} - impl TryFrom<&ScriptBuf> for AddressBytes { type Error = Error; fn try_from(script: &ScriptBuf) -> Result { diff --git a/crates/brk_types/src/anyaddressindex.rs b/crates/brk_types/src/anyaddressindex.rs index 1f492b81d..33249fff4 100644 --- a/crates/brk_types/src/anyaddressindex.rs +++ b/crates/brk_types/src/anyaddressindex.rs @@ -1,4 +1,5 @@ use serde::Serialize; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{EmptyAddressIndex, LoadedAddressIndex, TypeIndex}; @@ -48,6 +49,13 @@ impl std::fmt::Display for AnyAddressIndex { } } +impl Formattable for AnyAddressIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} + #[derive(Debug, Serialize)] #[serde(rename_all = "lowercase")] pub enum AnyAddressDataIndexEnum { diff --git a/crates/brk_types/src/bitcoin.rs b/crates/brk_types/src/bitcoin.rs index 6d32669ad..bb11e6048 100644 --- a/crates/brk_types/src/bitcoin.rs +++ b/crates/brk_types/src/bitcoin.rs @@ -4,7 +4,7 @@ use std::{ }; use serde::Serialize; -use vecdb::{CheckedSub, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{Sats, StoredF64}; @@ -19,7 +19,7 @@ use super::{Sats, StoredF64}; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct Bitcoin(f64); @@ -150,3 +150,10 @@ impl std::fmt::Display for Bitcoin { f.write_str(str) } } + +impl Formattable for Bitcoin { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/blkposition.rs b/crates/brk_types/src/blkposition.rs index 22cbb42d8..a84ed1535 100644 --- a/crates/brk_types/src/blkposition.rs +++ b/crates/brk_types/src/blkposition.rs @@ -1,11 +1,11 @@ use std::ops::Add; use serde::Serialize; -use vecdb::StoredCompressed; +use vecdb::{Compressable, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; #[derive( - Debug, Clone, Copy, Serialize, FromBytes, Immutable, IntoBytes, KnownLayout, StoredCompressed, + Debug, Clone, Copy, Serialize, FromBytes, Immutable, IntoBytes, KnownLayout, Compressable, )] pub struct BlkPosition(u64); @@ -37,3 +37,10 @@ impl std::fmt::Display for BlkPosition { f.write_str(str) } } + +impl Formattable for BlkPosition { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/blockhash.rs b/crates/brk_types/src/blockhash.rs index 04de16ef2..3db545758 100644 --- a/crates/brk_types/src/blockhash.rs +++ b/crates/brk_types/src/blockhash.rs @@ -5,6 +5,7 @@ use brk_error::Error; use derive_deref::Deref; use schemars::JsonSchema; use serde::{Serialize, Serializer}; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; /// Block hash @@ -70,3 +71,10 @@ impl Serialize for BlockHash { serializer.serialize_str(&self.to_string()) } } + +impl Formattable for BlockHash { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/cents.rs b/crates/brk_types/src/cents.rs index 33f60a6e3..6b9a47515 100644 --- a/crates/brk_types/src/cents.rs +++ b/crates/brk_types/src/cents.rs @@ -1,7 +1,7 @@ use std::ops::{Add, Div, Mul}; use serde::Serialize; -use vecdb::{CheckedSub, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::Dollars; @@ -20,7 +20,7 @@ use super::Dollars; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct Cents(i64); @@ -183,3 +183,10 @@ impl std::fmt::Display for Cents { f.write_str(str) } } + +impl Formattable for Cents { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/date.rs b/crates/brk_types/src/date.rs index af6de7ab6..70ac3180b 100644 --- a/crates/brk_types/src/date.rs +++ b/crates/brk_types/src/date.rs @@ -1,6 +1,6 @@ use jiff::{Span, Zoned, civil::Date as Date_, tz::TimeZone}; use serde::{Serialize, Serializer}; -use vecdb::StoredCompressed; +use vecdb::{Compressable, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::ONE_DAY_IN_SEC_F64; @@ -19,7 +19,7 @@ use super::{DateIndex, Timestamp}; Immutable, IntoBytes, KnownLayout, - StoredCompressed, + Compressable, )] pub struct Date(u32); @@ -121,6 +121,15 @@ impl From for Date { } } +impl Serialize for Date { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_str(&self.to_string()) + } +} + impl std::fmt::Display for Date { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut buf = itoa::Buffer::new(); @@ -144,11 +153,9 @@ impl std::fmt::Display for Date { } } -impl Serialize for Date { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - serializer.serialize_str(&self.to_string()) +impl Formattable for Date { + #[inline(always)] + fn may_need_escaping() -> bool { + false } } diff --git a/crates/brk_types/src/dateindex.rs b/crates/brk_types/src/dateindex.rs index 9374447c3..ea707e116 100644 --- a/crates/brk_types/src/dateindex.rs +++ b/crates/brk_types/src/dateindex.rs @@ -3,7 +3,7 @@ use std::ops::{Add, Rem}; use brk_error::Error; use jiff::Span; use serde::Serialize; -use vecdb::{CheckedSub, FromCoarserIndex, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, FromCoarserIndex, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{DecadeIndex, MonthIndex, QuarterIndex, SemesterIndex, WeekIndex, YearIndex}; @@ -24,7 +24,7 @@ use super::Date; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct DateIndex(u16); @@ -98,24 +98,6 @@ impl Rem for DateIndex { } } -impl std::fmt::Display for DateIndex { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut buf = itoa::Buffer::new(); - let str = buf.format(self.0); - f.write_str(str) - } -} - -impl PrintableIndex for DateIndex { - fn to_string() -> &'static str { - "dateindex" - } - - fn to_possible_strings() -> &'static [&'static str] { - &["d", "date", "dateindex"] - } -} - impl FromCoarserIndex for DateIndex { fn min_from(coarser: WeekIndex) -> usize { let coarser = usize::from(coarser); @@ -247,3 +229,28 @@ impl FromCoarserIndex for DateIndex { .into() } } + +impl PrintableIndex for DateIndex { + fn to_string() -> &'static str { + "dateindex" + } + + fn to_possible_strings() -> &'static [&'static str] { + &["d", "date", "dateindex"] + } +} + +impl std::fmt::Display for DateIndex { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut buf = itoa::Buffer::new(); + let str = buf.format(self.0); + f.write_str(str) + } +} + +impl Formattable for DateIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/decadeindex.rs b/crates/brk_types/src/decadeindex.rs index f78206706..b93ee7069 100644 --- a/crates/brk_types/src/decadeindex.rs +++ b/crates/brk_types/src/decadeindex.rs @@ -4,7 +4,7 @@ use std::{ }; use serde::{Deserialize, Serialize}; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{Date, DateIndex, YearIndex}; @@ -24,7 +24,7 @@ use super::{Date, DateIndex, YearIndex}; Immutable, IntoBytes, KnownLayout, - StoredCompressed, + Compressable, )] pub struct DecadeIndex(u16); @@ -138,3 +138,10 @@ impl std::fmt::Display for DecadeIndex { f.write_str(str) } } + +impl Formattable for DecadeIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/difficultyepoch.rs b/crates/brk_types/src/difficultyepoch.rs index 12f374e54..82522cf8e 100644 --- a/crates/brk_types/src/difficultyepoch.rs +++ b/crates/brk_types/src/difficultyepoch.rs @@ -4,7 +4,7 @@ use std::{ }; use serde::{Deserialize, Serialize}; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::Height; @@ -26,7 +26,7 @@ pub const BLOCKS_PER_DIFF_EPOCHS: u32 = 2016; Immutable, IntoBytes, KnownLayout, - StoredCompressed, + Compressable, )] pub struct DifficultyEpoch(u16); @@ -110,3 +110,10 @@ impl std::fmt::Display for DifficultyEpoch { f.write_str(str) } } + +impl Formattable for DifficultyEpoch { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/dollars.rs b/crates/brk_types/src/dollars.rs index 036d1f15c..f4265ddd3 100644 --- a/crates/brk_types/src/dollars.rs +++ b/crates/brk_types/src/dollars.rs @@ -8,7 +8,7 @@ use std::{ use derive_deref::Deref; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use vecdb::{CheckedSub, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{Low, Open}; @@ -27,7 +27,7 @@ use super::{Bitcoin, Cents, Close, High, Sats, StoredF32, StoredF64}; KnownLayout, Serialize, Deserialize, - StoredCompressed, + Compressable, JsonSchema, )] pub struct Dollars(f64); @@ -408,3 +408,10 @@ impl std::fmt::Display for Dollars { f.write_str(str) } } + +impl Formattable for Dollars { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/emptyaddressdata.rs b/crates/brk_types/src/emptyaddressdata.rs index f48d5d467..a9e0e20bb 100644 --- a/crates/brk_types/src/emptyaddressdata.rs +++ b/crates/brk_types/src/emptyaddressdata.rs @@ -1,4 +1,5 @@ use serde::Serialize; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{LoadedAddressData, Sats}; @@ -46,3 +47,10 @@ impl std::fmt::Display for EmptyAddressData { ) } } + +impl Formattable for EmptyAddressData { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} diff --git a/crates/brk_types/src/emptyaddressindex.rs b/crates/brk_types/src/emptyaddressindex.rs index eada35e28..2d1fcbabc 100644 --- a/crates/brk_types/src/emptyaddressindex.rs +++ b/crates/brk_types/src/emptyaddressindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::Deref; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -22,7 +22,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct EmptyAddressIndex(TypeIndex); @@ -81,3 +81,10 @@ impl std::fmt::Display for EmptyAddressIndex { self.0.fmt(f) } } + +impl Formattable for EmptyAddressIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/emptyoutputindex.rs b/crates/brk_types/src/emptyoutputindex.rs index d9ff8b2fa..cb7c71215 100644 --- a/crates/brk_types/src/emptyoutputindex.rs +++ b/crates/brk_types/src/emptyoutputindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -23,7 +23,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct EmptyOutputIndex(TypeIndex); impl From for EmptyOutputIndex { @@ -78,3 +78,10 @@ impl std::fmt::Display for EmptyOutputIndex { self.0.fmt(f) } } + +impl Formattable for EmptyOutputIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/feerate.rs b/crates/brk_types/src/feerate.rs index 399a97c95..486906def 100644 --- a/crates/brk_types/src/feerate.rs +++ b/crates/brk_types/src/feerate.rs @@ -4,13 +4,13 @@ use std::{ }; use serde::Serialize; -use vecdb::StoredCompressed; +use vecdb::{Compressable, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{Sats, StoredU64}; #[derive( - Debug, Clone, Copy, Serialize, FromBytes, Immutable, IntoBytes, KnownLayout, StoredCompressed, + Debug, Clone, Copy, Serialize, FromBytes, Immutable, IntoBytes, KnownLayout, Compressable, )] pub struct FeeRate(f64); @@ -102,3 +102,10 @@ impl std::fmt::Display for FeeRate { f.write_str(str) } } + +impl Formattable for FeeRate { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/halvingepoch.rs b/crates/brk_types/src/halvingepoch.rs index 621e02860..8db87ed8e 100644 --- a/crates/brk_types/src/halvingepoch.rs +++ b/crates/brk_types/src/halvingepoch.rs @@ -4,7 +4,7 @@ use std::{ }; use serde::{Deserialize, Serialize}; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::Height; @@ -26,7 +26,7 @@ pub const BLOCKS_PER_HALVING: u32 = 210_000; Immutable, IntoBytes, KnownLayout, - StoredCompressed, + Compressable, )] pub struct HalvingEpoch(u16); @@ -116,3 +116,10 @@ impl std::fmt::Display for HalvingEpoch { f.write_str(str) } } + +impl Formattable for HalvingEpoch { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/height.rs b/crates/brk_types/src/height.rs index 6240b23f1..91174ca00 100644 --- a/crates/brk_types/src/height.rs +++ b/crates/brk_types/src/height.rs @@ -7,7 +7,7 @@ use byteview::ByteView; use derive_deref::Deref; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use vecdb::{CheckedSub, PrintableIndex, Stamp, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex, Stamp}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{BLOCKS_PER_DIFF_EPOCHS, BLOCKS_PER_HALVING, copy_first_4bytes}; @@ -31,7 +31,7 @@ use super::StoredU64; Immutable, IntoBytes, KnownLayout, - StoredCompressed, + Compressable, JsonSchema, Hash, )] @@ -278,3 +278,10 @@ impl std::fmt::Display for Height { f.write_str(str) } } + +impl Formattable for Height { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/loadedaddressdata.rs b/crates/brk_types/src/loadedaddressdata.rs index f91d9fe48..41f5f2c6f 100644 --- a/crates/brk_types/src/loadedaddressdata.rs +++ b/crates/brk_types/src/loadedaddressdata.rs @@ -1,6 +1,6 @@ use brk_error::{Error, Result}; use serde::Serialize; -use vecdb::CheckedSub; +use vecdb::{CheckedSub, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{Bitcoin, Dollars, EmptyAddressData, Sats}; @@ -139,3 +139,10 @@ impl std::fmt::Display for LoadedAddressData { ) } } + +impl Formattable for LoadedAddressData { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} diff --git a/crates/brk_types/src/loadedaddressindex.rs b/crates/brk_types/src/loadedaddressindex.rs index 6ad82e5b0..13e351bcd 100644 --- a/crates/brk_types/src/loadedaddressindex.rs +++ b/crates/brk_types/src/loadedaddressindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::Deref; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -22,7 +22,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct LoadedAddressIndex(TypeIndex); @@ -77,3 +77,10 @@ impl std::fmt::Display for LoadedAddressIndex { self.0.fmt(f) } } + +impl Formattable for LoadedAddressIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/monthindex.rs b/crates/brk_types/src/monthindex.rs index 2a05dfed1..a52d0e6c0 100644 --- a/crates/brk_types/src/monthindex.rs +++ b/crates/brk_types/src/monthindex.rs @@ -4,7 +4,7 @@ use std::{ }; use serde::{Deserialize, Serialize}; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{Date, DateIndex, YearIndex}; @@ -24,7 +24,7 @@ use super::{Date, DateIndex, YearIndex}; Immutable, IntoBytes, KnownLayout, - StoredCompressed, + Compressable, )] pub struct MonthIndex(u16); @@ -129,3 +129,10 @@ impl std::fmt::Display for MonthIndex { f.write_str(str) } } + +impl Formattable for MonthIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/ohlc.rs b/crates/brk_types/src/ohlc.rs index 13720947d..a35aa83b8 100644 --- a/crates/brk_types/src/ohlc.rs +++ b/crates/brk_types/src/ohlc.rs @@ -1,11 +1,12 @@ use std::{ + fmt::Display, iter::Sum, ops::{Add, AddAssign, Div}, }; use derive_deref::{Deref, DerefMut}; use serde::{Serialize, Serializer, ser::SerializeTuple}; -use vecdb::StoredCompressed; +use vecdb::{Compressable, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::StoredF64; @@ -59,7 +60,7 @@ impl Serialize for OHLCCents { } } -impl std::fmt::Display for OHLCCents { +impl Display for OHLCCents { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, @@ -69,6 +70,13 @@ impl std::fmt::Display for OHLCCents { } } +impl Formattable for OHLCCents { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} + #[derive(Debug, Default, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)] #[repr(C)] pub struct OHLCDollars { @@ -135,7 +143,7 @@ impl From<&OHLCCents> for OHLCDollars { } } -impl std::fmt::Display for OHLCDollars { +impl Display for OHLCDollars { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, @@ -145,6 +153,13 @@ impl std::fmt::Display for OHLCDollars { } } +impl Formattable for OHLCDollars { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} + #[derive(Debug, Default, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)] #[repr(C)] pub struct OHLCSats { @@ -192,7 +207,7 @@ impl From> for OHLCSats { } } -impl std::fmt::Display for OHLCSats { +impl Display for OHLCSats { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, @@ -202,6 +217,13 @@ impl std::fmt::Display for OHLCSats { } } +impl Formattable for OHLCSats { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} + #[derive( Debug, Default, @@ -218,7 +240,7 @@ impl std::fmt::Display for OHLCSats { Deref, DerefMut, Serialize, - StoredCompressed, + Compressable, )] #[repr(transparent)] pub struct Open(T); @@ -315,15 +337,25 @@ where } } -impl std::fmt::Display for Open +impl Display for Open where - T: std::fmt::Display, + T: Display, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.0.fmt(f) } } +impl Formattable for Open +where + T: Display, +{ + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} + #[derive( Debug, Default, @@ -340,7 +372,7 @@ where Deref, DerefMut, Serialize, - StoredCompressed, + Compressable, )] #[repr(transparent)] pub struct High(T); @@ -437,15 +469,25 @@ where } } -impl std::fmt::Display for High +impl Display for High where - T: std::fmt::Display, + T: Display, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.0.fmt(f) } } +impl Formattable for High +where + T: Display, +{ + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} + #[derive( Debug, Default, @@ -462,7 +504,7 @@ where Deref, DerefMut, Serialize, - StoredCompressed, + Compressable, )] #[repr(transparent)] pub struct Low(T); @@ -559,15 +601,25 @@ where } } -impl std::fmt::Display for Low +impl Display for Low where - T: std::fmt::Display, + T: Display, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.0.fmt(f) } } +impl Formattable for Low +where + T: Display, +{ + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} + #[derive( Debug, Default, @@ -584,7 +636,7 @@ where Deref, DerefMut, Serialize, - StoredCompressed, + Compressable, )] #[repr(transparent)] pub struct Close(T); @@ -704,11 +756,21 @@ impl Sum for Close { } } -impl std::fmt::Display for Close +impl Display for Close where - T: std::fmt::Display, + T: Display, { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.0.fmt(f) } } + +impl Formattable for Close +where + T: Display, +{ + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/opreturnindex.rs b/crates/brk_types/src/opreturnindex.rs index 56a2eeb18..09dcf02e9 100644 --- a/crates/brk_types/src/opreturnindex.rs +++ b/crates/brk_types/src/opreturnindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -23,7 +23,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct OpReturnIndex(TypeIndex); @@ -78,3 +78,10 @@ impl std::fmt::Display for OpReturnIndex { self.0.fmt(f) } } + +impl Formattable for OpReturnIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/outpoint.rs b/crates/brk_types/src/outpoint.rs index 247869ec3..a6a2b1263 100644 --- a/crates/brk_types/src/outpoint.rs +++ b/crates/brk_types/src/outpoint.rs @@ -1,6 +1,6 @@ use schemars::JsonSchema; use serde::Serialize; -use vecdb::StoredCompressed; +use vecdb::{Compressable, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{TxIndex, Vout}; @@ -21,7 +21,7 @@ use crate::{TxIndex, Vout}; Serialize, JsonSchema, Hash, - StoredCompressed, + Compressable, )] pub struct OutPoint(u64); @@ -52,3 +52,10 @@ impl std::fmt::Display for OutPoint { write!(f, "txindex: {}, vout: {}", self.txindex(), self.vout()) } } + +impl Formattable for OutPoint { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} diff --git a/crates/brk_types/src/outputtype.rs b/crates/brk_types/src/outputtype.rs index 2e1df4bdf..674610ab8 100644 --- a/crates/brk_types/src/outputtype.rs +++ b/crates/brk_types/src/outputtype.rs @@ -3,6 +3,7 @@ use brk_error::Error; use schemars::JsonSchema; use serde::Serialize; use strum::Display; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; #[derive( @@ -914,3 +915,10 @@ impl From<&[u8]> for OutputType { Self::read_from_bytes(value).unwrap() } } + +impl Formattable for OutputType { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/p2aaddressindex.rs b/crates/brk_types/src/p2aaddressindex.rs index 964ff86f7..6cbab2897 100644 --- a/crates/brk_types/src/p2aaddressindex.rs +++ b/crates/brk_types/src/p2aaddressindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -23,7 +23,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct P2AAddressIndex(TypeIndex); impl From for P2AAddressIndex { @@ -94,3 +94,10 @@ impl std::fmt::Display for P2AAddressIndex { self.0.fmt(f) } } + +impl Formattable for P2AAddressIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/p2abytes.rs b/crates/brk_types/src/p2abytes.rs index b2d1dd67e..50e27bd46 100644 --- a/crates/brk_types/src/p2abytes.rs +++ b/crates/brk_types/src/p2abytes.rs @@ -2,6 +2,7 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::U8x2; @@ -42,3 +43,10 @@ impl fmt::Display for P2ABytes { write!(f, "{:?}", self.0) } } + +impl Formattable for P2ABytes { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} diff --git a/crates/brk_types/src/p2msoutputindex.rs b/crates/brk_types/src/p2msoutputindex.rs index 4fdb14369..28b34ec78 100644 --- a/crates/brk_types/src/p2msoutputindex.rs +++ b/crates/brk_types/src/p2msoutputindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -23,7 +23,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct P2MSOutputIndex(TypeIndex); impl From for P2MSOutputIndex { @@ -77,3 +77,10 @@ impl std::fmt::Display for P2MSOutputIndex { self.0.fmt(f) } } + +impl Formattable for P2MSOutputIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/p2pk33addressindex.rs b/crates/brk_types/src/p2pk33addressindex.rs index d5c5f508e..98f35a69b 100644 --- a/crates/brk_types/src/p2pk33addressindex.rs +++ b/crates/brk_types/src/p2pk33addressindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -23,7 +23,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct P2PK33AddressIndex(TypeIndex); impl From for P2PK33AddressIndex { @@ -95,3 +95,10 @@ impl std::fmt::Display for P2PK33AddressIndex { self.0.fmt(f) } } + +impl Formattable for P2PK33AddressIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/p2pk33bytes.rs b/crates/brk_types/src/p2pk33bytes.rs index 7ded0132c..d0036de1e 100644 --- a/crates/brk_types/src/p2pk33bytes.rs +++ b/crates/brk_types/src/p2pk33bytes.rs @@ -2,6 +2,7 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::U8x33; @@ -42,3 +43,10 @@ impl fmt::Display for P2PK33Bytes { write!(f, "{:?}", self.0) } } + +impl Formattable for P2PK33Bytes { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} diff --git a/crates/brk_types/src/p2pk65addressindex.rs b/crates/brk_types/src/p2pk65addressindex.rs index df4e9f89a..d5bafd4b6 100644 --- a/crates/brk_types/src/p2pk65addressindex.rs +++ b/crates/brk_types/src/p2pk65addressindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -23,7 +23,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct P2PK65AddressIndex(TypeIndex); impl From for P2PK65AddressIndex { @@ -94,3 +94,10 @@ impl std::fmt::Display for P2PK65AddressIndex { self.0.fmt(f) } } + +impl Formattable for P2PK65AddressIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/p2pk65bytes.rs b/crates/brk_types/src/p2pk65bytes.rs index b771c4e0f..b5492abb1 100644 --- a/crates/brk_types/src/p2pk65bytes.rs +++ b/crates/brk_types/src/p2pk65bytes.rs @@ -2,6 +2,7 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::U8x65; @@ -42,3 +43,10 @@ impl fmt::Display for P2PK65Bytes { write!(f, "{:?}", self.0) } } + +impl Formattable for P2PK65Bytes { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} diff --git a/crates/brk_types/src/p2pkhaddressindex.rs b/crates/brk_types/src/p2pkhaddressindex.rs index e5f047a48..6fe97991e 100644 --- a/crates/brk_types/src/p2pkhaddressindex.rs +++ b/crates/brk_types/src/p2pkhaddressindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -23,7 +23,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct P2PKHAddressIndex(TypeIndex); impl From for P2PKHAddressIndex { @@ -95,3 +95,10 @@ impl std::fmt::Display for P2PKHAddressIndex { self.0.fmt(f) } } + +impl Formattable for P2PKHAddressIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/p2pkhbytes.rs b/crates/brk_types/src/p2pkhbytes.rs index 29a295a24..98e6a0f0e 100644 --- a/crates/brk_types/src/p2pkhbytes.rs +++ b/crates/brk_types/src/p2pkhbytes.rs @@ -2,6 +2,7 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::U8x20; @@ -42,3 +43,10 @@ impl fmt::Display for P2PKHBytes { write!(f, "{:?}", self.0) } } + +impl Formattable for P2PKHBytes { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} diff --git a/crates/brk_types/src/p2shaddressindex.rs b/crates/brk_types/src/p2shaddressindex.rs index 8b1dddcd2..71bdd11ee 100644 --- a/crates/brk_types/src/p2shaddressindex.rs +++ b/crates/brk_types/src/p2shaddressindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -23,7 +23,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct P2SHAddressIndex(TypeIndex); impl From for P2SHAddressIndex { @@ -101,3 +101,10 @@ impl std::fmt::Display for P2SHAddressIndex { self.0.fmt(f) } } + +impl Formattable for P2SHAddressIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/p2shbytes.rs b/crates/brk_types/src/p2shbytes.rs index 394c1c15a..4b3fa5147 100644 --- a/crates/brk_types/src/p2shbytes.rs +++ b/crates/brk_types/src/p2shbytes.rs @@ -2,6 +2,7 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::U8x20; @@ -42,3 +43,10 @@ impl fmt::Display for P2SHBytes { write!(f, "{:?}", self.0) } } + +impl Formattable for P2SHBytes { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} diff --git a/crates/brk_types/src/p2traddressindex.rs b/crates/brk_types/src/p2traddressindex.rs index 56ad36c10..96e3a5810 100644 --- a/crates/brk_types/src/p2traddressindex.rs +++ b/crates/brk_types/src/p2traddressindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -23,7 +23,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct P2TRAddressIndex(TypeIndex); impl From for P2TRAddressIndex { @@ -95,3 +95,10 @@ impl std::fmt::Display for P2TRAddressIndex { self.0.fmt(f) } } + +impl Formattable for P2TRAddressIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/p2trbytes.rs b/crates/brk_types/src/p2trbytes.rs index 5df37b298..a643bf3dc 100644 --- a/crates/brk_types/src/p2trbytes.rs +++ b/crates/brk_types/src/p2trbytes.rs @@ -2,6 +2,7 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::U8x32; @@ -42,3 +43,10 @@ impl fmt::Display for P2TRBytes { write!(f, "{:?}", self.0) } } + +impl Formattable for P2TRBytes { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} diff --git a/crates/brk_types/src/p2wpkhaddressindex.rs b/crates/brk_types/src/p2wpkhaddressindex.rs index 40cd64601..feb3e4782 100644 --- a/crates/brk_types/src/p2wpkhaddressindex.rs +++ b/crates/brk_types/src/p2wpkhaddressindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -23,7 +23,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct P2WPKHAddressIndex(TypeIndex); impl From for P2WPKHAddressIndex { @@ -95,3 +95,10 @@ impl std::fmt::Display for P2WPKHAddressIndex { self.0.fmt(f) } } + +impl Formattable for P2WPKHAddressIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/p2wpkhbytes.rs b/crates/brk_types/src/p2wpkhbytes.rs index 69e445bed..ad41e5f93 100644 --- a/crates/brk_types/src/p2wpkhbytes.rs +++ b/crates/brk_types/src/p2wpkhbytes.rs @@ -2,6 +2,7 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::U8x20; @@ -42,3 +43,10 @@ impl fmt::Display for P2WPKHBytes { write!(f, "{:?}", self.0) } } + +impl Formattable for P2WPKHBytes { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} diff --git a/crates/brk_types/src/p2wshaddressindex.rs b/crates/brk_types/src/p2wshaddressindex.rs index 12f0878a8..ec40625f7 100644 --- a/crates/brk_types/src/p2wshaddressindex.rs +++ b/crates/brk_types/src/p2wshaddressindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -23,7 +23,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct P2WSHAddressIndex(TypeIndex); impl From for P2WSHAddressIndex { @@ -95,3 +95,10 @@ impl std::fmt::Display for P2WSHAddressIndex { self.0.fmt(f) } } + +impl Formattable for P2WSHAddressIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/p2wshbytes.rs b/crates/brk_types/src/p2wshbytes.rs index e80f7bb18..38f3b045d 100644 --- a/crates/brk_types/src/p2wshbytes.rs +++ b/crates/brk_types/src/p2wshbytes.rs @@ -2,6 +2,7 @@ use std::fmt; use derive_deref::Deref; use serde::Serialize; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::U8x32; @@ -42,3 +43,10 @@ impl fmt::Display for P2WSHBytes { write!(f, "{:?}", self.0) } } + +impl Formattable for P2WSHBytes { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} diff --git a/crates/brk_types/src/poolid.rs b/crates/brk_types/src/poolid.rs index 362c9d005..08141c721 100644 --- a/crates/brk_types/src/poolid.rs +++ b/crates/brk_types/src/poolid.rs @@ -1,6 +1,7 @@ use num_enum::{FromPrimitive, IntoPrimitive}; use serde::{Deserialize, Serialize}; use strum::Display; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; // Created from the list in `pools.rs` @@ -286,3 +287,10 @@ pub enum PoolId { Dummy254, Dummy255, } + +impl Formattable for PoolId { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/quarterindex.rs b/crates/brk_types/src/quarterindex.rs index 10ffecbd0..61b77beef 100644 --- a/crates/brk_types/src/quarterindex.rs +++ b/crates/brk_types/src/quarterindex.rs @@ -4,7 +4,7 @@ use std::{ }; use serde::{Deserialize, Serialize}; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::MonthIndex; @@ -24,7 +24,7 @@ use super::MonthIndex; Immutable, IntoBytes, KnownLayout, - StoredCompressed, + Compressable, )] pub struct QuarterIndex(u16); @@ -115,3 +115,10 @@ impl std::fmt::Display for QuarterIndex { f.write_str(str) } } + +impl Formattable for QuarterIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/rawlocktime.rs b/crates/brk_types/src/rawlocktime.rs index 03f817a69..64ab2c3f8 100644 --- a/crates/brk_types/src/rawlocktime.rs +++ b/crates/brk_types/src/rawlocktime.rs @@ -1,7 +1,7 @@ use bitcoin::{absolute::LockTime, locktime::absolute::LOCK_TIME_THRESHOLD}; use schemars::JsonSchema; use serde::Serialize; -use vecdb::StoredCompressed; +use vecdb::{Compressable, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; /// Transaction locktime @@ -14,7 +14,7 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; KnownLayout, FromBytes, Serialize, - StoredCompressed, + Compressable, JsonSchema, )] pub struct RawLockTime(u32); @@ -48,3 +48,10 @@ impl std::fmt::Display for RawLockTime { f.write_str(&lock_time.to_string()) } } + +impl Formattable for RawLockTime { + #[inline(always)] + fn may_need_escaping() -> bool { + true + } +} diff --git a/crates/brk_types/src/sats.rs b/crates/brk_types/src/sats.rs index e9c8c8df6..b8967ff5a 100644 --- a/crates/brk_types/src/sats.rs +++ b/crates/brk_types/src/sats.rs @@ -7,7 +7,7 @@ use bitcoin::Amount; use derive_deref::Deref; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use vecdb::{CheckedSub, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::StoredF64; @@ -31,7 +31,7 @@ use super::{Bitcoin, Cents, Dollars, Height}; KnownLayout, Serialize, Deserialize, - StoredCompressed, + Compressable, JsonSchema, )] pub struct Sats(u64); @@ -284,3 +284,10 @@ impl std::fmt::Display for Sats { f.write_str(str) } } + +impl Formattable for Sats { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/semesterindex.rs b/crates/brk_types/src/semesterindex.rs index 5ae83d43e..6ede617f5 100644 --- a/crates/brk_types/src/semesterindex.rs +++ b/crates/brk_types/src/semesterindex.rs @@ -4,7 +4,7 @@ use std::{ }; use serde::{Deserialize, Serialize}; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::MonthIndex; @@ -24,7 +24,7 @@ use super::MonthIndex; Immutable, IntoBytes, KnownLayout, - StoredCompressed, + Compressable, )] pub struct SemesterIndex(u16); @@ -115,3 +115,10 @@ impl std::fmt::Display for SemesterIndex { f.write_str(str) } } + +impl Formattable for SemesterIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/stored_bool.rs b/crates/brk_types/src/stored_bool.rs index 3d2690003..4d2595465 100644 --- a/crates/brk_types/src/stored_bool.rs +++ b/crates/brk_types/src/stored_bool.rs @@ -1,6 +1,6 @@ use derive_deref::Deref; use serde::Serialize; -use vecdb::{PrintableIndex, StoredCompressed}; +use vecdb::{Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; #[derive( @@ -18,7 +18,7 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct StoredBool(u16); @@ -68,3 +68,10 @@ impl std::fmt::Display for StoredBool { } } } + +impl Formattable for StoredBool { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/stored_f32.rs b/crates/brk_types/src/stored_f32.rs index 8d26db158..b0be39bd8 100644 --- a/crates/brk_types/src/stored_f32.rs +++ b/crates/brk_types/src/stored_f32.rs @@ -8,7 +8,7 @@ use std::{ use derive_deref::Deref; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{Close, StoredU32}; @@ -26,7 +26,7 @@ use super::{Dollars, StoredF64}; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct StoredF32(f32); @@ -236,3 +236,10 @@ impl std::fmt::Display for StoredF32 { f.write_str(str) } } + +impl Formattable for StoredF32 { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/stored_f64.rs b/crates/brk_types/src/stored_f64.rs index f07d2aa2c..d80af3f84 100644 --- a/crates/brk_types/src/stored_f64.rs +++ b/crates/brk_types/src/stored_f64.rs @@ -7,7 +7,7 @@ use std::{ use derive_deref::Deref; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::{Bitcoin, Dollars}; @@ -23,7 +23,7 @@ use crate::{Bitcoin, Dollars}; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct StoredF64(f64); @@ -209,3 +209,10 @@ impl std::fmt::Display for StoredF64 { f.write_str(str) } } + +impl Formattable for StoredF64 { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/stored_i16.rs b/crates/brk_types/src/stored_i16.rs index cc7b9ad76..4571e1a59 100644 --- a/crates/brk_types/src/stored_i16.rs +++ b/crates/brk_types/src/stored_i16.rs @@ -2,7 +2,7 @@ use std::ops::{Add, AddAssign, Div}; use derive_deref::Deref; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; #[derive( @@ -20,7 +20,7 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct StoredI16(i16); @@ -116,3 +116,10 @@ impl std::fmt::Display for StoredI16 { f.write_str(str) } } + +impl Formattable for StoredI16 { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/stored_u16.rs b/crates/brk_types/src/stored_u16.rs index 1a12046da..f1b06a106 100644 --- a/crates/brk_types/src/stored_u16.rs +++ b/crates/brk_types/src/stored_u16.rs @@ -2,7 +2,7 @@ use std::ops::{Add, AddAssign, Div}; use derive_deref::Deref; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{ @@ -26,7 +26,7 @@ use super::{ IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct StoredU16(u16); @@ -207,3 +207,10 @@ impl std::fmt::Display for StoredU16 { f.write_str(str) } } + +impl Formattable for StoredU16 { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/stored_u32.rs b/crates/brk_types/src/stored_u32.rs index 5a49ef48d..bbd758b25 100644 --- a/crates/brk_types/src/stored_u32.rs +++ b/crates/brk_types/src/stored_u32.rs @@ -2,7 +2,7 @@ use std::ops::{Add, AddAssign, Div, Mul}; use derive_deref::Deref; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{ @@ -26,7 +26,7 @@ use super::{ IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct StoredU32(u32); @@ -238,3 +238,10 @@ impl std::fmt::Display for StoredU32 { f.write_str(str) } } + +impl Formattable for StoredU32 { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/stored_u64.rs b/crates/brk_types/src/stored_u64.rs index a1f45984d..b7e547731 100644 --- a/crates/brk_types/src/stored_u64.rs +++ b/crates/brk_types/src/stored_u64.rs @@ -2,7 +2,7 @@ use std::ops::{Add, AddAssign, Div}; use derive_deref::Deref; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{ @@ -27,7 +27,7 @@ use super::{ IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct StoredU64(u64); @@ -260,3 +260,10 @@ impl std::fmt::Display for StoredU64 { f.write_str(str) } } + +impl Formattable for StoredU64 { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/stored_u8.rs b/crates/brk_types/src/stored_u8.rs index 13340c83a..82cc757b5 100644 --- a/crates/brk_types/src/stored_u8.rs +++ b/crates/brk_types/src/stored_u8.rs @@ -2,7 +2,7 @@ use std::ops::{Add, AddAssign, Div}; use derive_deref::Deref; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex}; +use vecdb::{CheckedSub, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; pub type StoredPhantom = StoredU8; @@ -121,3 +121,10 @@ impl std::fmt::Display for StoredU8 { f.write_str(str) } } + +impl Formattable for StoredU8 { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/timestamp.rs b/crates/brk_types/src/timestamp.rs index cce81179a..59e742499 100644 --- a/crates/brk_types/src/timestamp.rs +++ b/crates/brk_types/src/timestamp.rs @@ -4,7 +4,7 @@ use derive_deref::Deref; use jiff::{civil::date, tz::TimeZone}; use schemars::JsonSchema; use serde::Serialize; -use vecdb::{CheckedSub, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::Date; @@ -24,7 +24,7 @@ use super::Date; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, JsonSchema, )] pub struct Timestamp(u32); @@ -175,3 +175,10 @@ impl std::fmt::Display for Timestamp { f.write_str(str) } } + +impl Formattable for Timestamp { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/txid.rs b/crates/brk_types/src/txid.rs index c14b850c5..1117c04d8 100644 --- a/crates/brk_types/src/txid.rs +++ b/crates/brk_types/src/txid.rs @@ -4,6 +4,7 @@ use bitcoin::hashes::Hash; use derive_deref::Deref; use schemars::JsonSchema; use serde::{Serialize, Serializer}; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; /// Transaction ID (hash) @@ -77,3 +78,10 @@ impl Serialize for Txid { serializer.serialize_str(&self.to_string()) } } + +impl Formattable for Txid { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/txindex.rs b/crates/brk_types/src/txindex.rs index 3948d2dbc..b0c49c26e 100644 --- a/crates/brk_types/src/txindex.rs +++ b/crates/brk_types/src/txindex.rs @@ -4,7 +4,7 @@ use byteview::ByteView; use derive_deref::{Deref, DerefMut}; use schemars::JsonSchema; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::copy_first_4bytes; @@ -27,7 +27,7 @@ use super::StoredU32; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, JsonSchema, Hash, )] @@ -164,3 +164,10 @@ impl std::fmt::Display for TxIndex { f.write_str(str) } } + +impl Formattable for TxIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/txinindex.rs b/crates/brk_types/src/txinindex.rs index 13b5c2d8d..add22d564 100644 --- a/crates/brk_types/src/txinindex.rs +++ b/crates/brk_types/src/txinindex.rs @@ -2,7 +2,7 @@ use std::ops::{Add, AddAssign}; use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::Vin; @@ -23,7 +23,7 @@ use super::Vin; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct TxInIndex(u64); @@ -123,3 +123,10 @@ impl std::fmt::Display for TxInIndex { f.write_str(str) } } + +impl Formattable for TxInIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/txoutindex.rs b/crates/brk_types/src/txoutindex.rs index c8f0c7651..49f1837ca 100644 --- a/crates/brk_types/src/txoutindex.rs +++ b/crates/brk_types/src/txoutindex.rs @@ -2,7 +2,7 @@ use std::ops::{Add, AddAssign}; use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::copy_first_8bytes; @@ -25,7 +25,7 @@ use super::Vout; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct TxOutIndex(u64); @@ -140,3 +140,10 @@ impl std::fmt::Display for TxOutIndex { f.write_str(str) } } + +impl Formattable for TxOutIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/txversion.rs b/crates/brk_types/src/txversion.rs index 47f75e531..0051f4fa5 100644 --- a/crates/brk_types/src/txversion.rs +++ b/crates/brk_types/src/txversion.rs @@ -1,7 +1,7 @@ use derive_deref::Deref; use schemars::JsonSchema; use serde::Serialize; -use vecdb::StoredCompressed; +use vecdb::{Compressable, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::StoredU16; @@ -21,7 +21,7 @@ use super::StoredU16; KnownLayout, FromBytes, Serialize, - StoredCompressed, + Compressable, JsonSchema, )] pub struct TxVersion(u16); @@ -66,3 +66,10 @@ impl std::fmt::Display for TxVersion { f.write_str(str) } } + +impl Formattable for TxVersion { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/typeindex.rs b/crates/brk_types/src/typeindex.rs index 4efd72bdc..38992646f 100644 --- a/crates/brk_types/src/typeindex.rs +++ b/crates/brk_types/src/typeindex.rs @@ -3,7 +3,7 @@ use std::ops::Add; use byteview::ByteView; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use vecdb::{CheckedSub, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::copy_first_4bytes; @@ -24,7 +24,7 @@ use crate::copy_first_4bytes; KnownLayout, Serialize, Deserialize, - StoredCompressed, + Compressable, JsonSchema, Hash, )] @@ -150,3 +150,10 @@ impl std::fmt::Display for TypeIndex { f.write_str(str) } } + +impl Formattable for TypeIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/unknownoutputindex.rs b/crates/brk_types/src/unknownoutputindex.rs index c17da6b30..e3806c538 100644 --- a/crates/brk_types/src/unknownoutputindex.rs +++ b/crates/brk_types/src/unknownoutputindex.rs @@ -2,7 +2,7 @@ use std::ops::Add; use derive_deref::{Deref, DerefMut}; use serde::Serialize; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::TypeIndex; @@ -23,7 +23,7 @@ use crate::TypeIndex; IntoBytes, KnownLayout, Serialize, - StoredCompressed, + Compressable, )] pub struct UnknownOutputIndex(TypeIndex); @@ -78,3 +78,10 @@ impl std::fmt::Display for UnknownOutputIndex { self.0.fmt(f) } } + +impl Formattable for UnknownOutputIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/vout.rs b/crates/brk_types/src/vout.rs index 545bbded2..aa6e8a11f 100644 --- a/crates/brk_types/src/vout.rs +++ b/crates/brk_types/src/vout.rs @@ -1,6 +1,7 @@ use derive_deref::Deref; use schemars::JsonSchema; use serde::Serialize; +use vecdb::Formattable; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use crate::copy_first_2bytes; @@ -105,3 +106,10 @@ impl std::fmt::Display for Vout { self.0.fmt(f) } } + +impl Formattable for Vout { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/weekindex.rs b/crates/brk_types/src/weekindex.rs index 7eba8699e..e078fdbb4 100644 --- a/crates/brk_types/src/weekindex.rs +++ b/crates/brk_types/src/weekindex.rs @@ -4,7 +4,7 @@ use std::{ }; use serde::{Deserialize, Serialize}; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{Date, DateIndex}; @@ -24,7 +24,7 @@ use super::{Date, DateIndex}; Immutable, IntoBytes, KnownLayout, - StoredCompressed, + Compressable, )] pub struct WeekIndex(u16); @@ -139,3 +139,10 @@ impl std::fmt::Display for WeekIndex { f.write_str(str) } } + +impl Formattable for WeekIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/weight.rs b/crates/brk_types/src/weight.rs index cb7e96432..7b024ba01 100644 --- a/crates/brk_types/src/weight.rs +++ b/crates/brk_types/src/weight.rs @@ -3,7 +3,7 @@ use std::ops::{Add, AddAssign, Div}; use derive_deref::Deref; use schemars::JsonSchema; use serde::Serialize; -use vecdb::StoredCompressed; +use vecdb::{Compressable, Formattable}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; #[derive( @@ -20,7 +20,7 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; KnownLayout, FromBytes, Serialize, - StoredCompressed, + Compressable, JsonSchema, )] pub struct Weight(u64); @@ -94,3 +94,10 @@ impl std::fmt::Display for Weight { f.write_str(str) } } + +impl Formattable for Weight { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +} diff --git a/crates/brk_types/src/yearindex.rs b/crates/brk_types/src/yearindex.rs index 86b862dd9..e5731b6c3 100644 --- a/crates/brk_types/src/yearindex.rs +++ b/crates/brk_types/src/yearindex.rs @@ -4,7 +4,7 @@ use std::{ }; use serde::{Deserialize, Serialize}; -use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; +use vecdb::{CheckedSub, Compressable, Formattable, PrintableIndex}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{Date, DateIndex, MonthIndex}; @@ -24,7 +24,7 @@ use super::{Date, DateIndex, MonthIndex}; Immutable, IntoBytes, KnownLayout, - StoredCompressed, + Compressable, )] pub struct YearIndex(u16); @@ -136,3 +136,10 @@ impl std::fmt::Display for YearIndex { f.write_str(str) } } + +impl Formattable for YearIndex { + #[inline(always)] + fn may_need_escaping() -> bool { + false + } +}