use brk_traversable::Traversable; use brk_types::{Bitcoin, Cents, Dollars, Height, Sats, Version}; use vecdb::{LazyVecFrom1, ReadableCloneableVec, UnaryTransform, VecIndex}; use crate::internal::ValuePerBlock; /// Fully lazy value type at height level. /// /// All fields are lazy transforms from existing sources - no storage. #[derive(Clone, Traversable)] pub struct LazyValue { pub btc: LazyVecFrom1, pub sats: LazyVecFrom1, pub usd: LazyVecFrom1, pub cents: LazyVecFrom1, } impl LazyValue { pub(crate) fn from_block_source< SatsTransform, BitcoinTransform, CentsTransform, DollarsTransform, >( name: &str, source: &ValuePerBlock, version: Version, ) -> Self where SatsTransform: UnaryTransform, BitcoinTransform: UnaryTransform, CentsTransform: UnaryTransform, DollarsTransform: UnaryTransform, { let sats = LazyVecFrom1::transformed::( &format!("{name}_sats"), version, source.sats.height.read_only_boxed_clone(), ); let btc = LazyVecFrom1::transformed::( name, version, source.sats.height.read_only_boxed_clone(), ); let cents = LazyVecFrom1::transformed::( &format!("{name}_cents"), version, source.cents.height.read_only_boxed_clone(), ); let usd = LazyVecFrom1::transformed::( &format!("{name}_usd"), version, source.usd.height.read_only_boxed_clone(), ); Self { btc, sats, usd, cents, } } }