diff --git a/crates/brk_client/src/lib.rs b/crates/brk_client/src/lib.rs index 147ac2085..1b1165ee1 100644 --- a/crates/brk_client/src/lib.rs +++ b/crates/brk_client/src/lib.rs @@ -370,8 +370,8 @@ impl RangeBuilder { // Static index arrays -const _I1: &[Index] = &[Index::Minute10, Index::Minute30, Index::Hour1, Index::Hour4, Index::Hour12, Index::Day1, Index::Day3, Index::Week1, Index::Month1, Index::Month3, Index::Month6, Index::Year1, Index::Year10, Index::HalvingEpoch, Index::DifficultyEpoch, Index::Height]; -const _I2: &[Index] = &[Index::Minute10, Index::Minute30, Index::Hour1, Index::Hour4, Index::Hour12, Index::Day1, Index::Day3, Index::Week1, Index::Month1, Index::Month3, Index::Month6, Index::Year1, Index::Year10, Index::HalvingEpoch, Index::DifficultyEpoch]; +const _I1: &[Index] = &[Index::Minute10, Index::Minute30, Index::Hour1, Index::Hour4, Index::Hour12, Index::Day1, Index::Day3, Index::Week1, Index::Month1, Index::Month3, Index::Month6, Index::Year1, Index::Year10, Index::Halving, Index::Epoch, Index::Height]; +const _I2: &[Index] = &[Index::Minute10, Index::Minute30, Index::Hour1, Index::Hour4, Index::Hour12, Index::Day1, Index::Day3, Index::Week1, Index::Month1, Index::Month3, Index::Month6, Index::Year1, Index::Year10, Index::Halving, Index::Epoch]; const _I3: &[Index] = &[Index::Minute10]; const _I4: &[Index] = &[Index::Minute30]; const _I5: &[Index] = &[Index::Hour1]; @@ -385,8 +385,8 @@ const _I12: &[Index] = &[Index::Month3]; const _I13: &[Index] = &[Index::Month6]; const _I14: &[Index] = &[Index::Year1]; const _I15: &[Index] = &[Index::Year10]; -const _I16: &[Index] = &[Index::HalvingEpoch]; -const _I17: &[Index] = &[Index::DifficultyEpoch]; +const _I16: &[Index] = &[Index::Halving]; +const _I17: &[Index] = &[Index::Epoch]; const _I18: &[Index] = &[Index::Height]; const _I19: &[Index] = &[Index::TxIndex]; const _I20: &[Index] = &[Index::TxInIndex]; @@ -433,8 +433,8 @@ impl MetricPattern1By { pub fn month6(&self) -> DateMetricEndpointBuilder { _dep(&self.client, &self.name, Index::Month6) } pub fn year1(&self) -> DateMetricEndpointBuilder { _dep(&self.client, &self.name, Index::Year1) } pub fn year10(&self) -> DateMetricEndpointBuilder { _dep(&self.client, &self.name, Index::Year10) } - pub fn halvingepoch(&self) -> MetricEndpointBuilder { _ep(&self.client, &self.name, Index::HalvingEpoch) } - pub fn difficultyepoch(&self) -> MetricEndpointBuilder { _ep(&self.client, &self.name, Index::DifficultyEpoch) } + pub fn halvingepoch(&self) -> MetricEndpointBuilder { _ep(&self.client, &self.name, Index::Halving) } + pub fn difficultyepoch(&self) -> MetricEndpointBuilder { _ep(&self.client, &self.name, Index::Epoch) } pub fn height(&self) -> MetricEndpointBuilder { _ep(&self.client, &self.name, Index::Height) } } @@ -462,8 +462,8 @@ impl MetricPattern2By { pub fn month6(&self) -> DateMetricEndpointBuilder { _dep(&self.client, &self.name, Index::Month6) } pub fn year1(&self) -> DateMetricEndpointBuilder { _dep(&self.client, &self.name, Index::Year1) } pub fn year10(&self) -> DateMetricEndpointBuilder { _dep(&self.client, &self.name, Index::Year10) } - pub fn halvingepoch(&self) -> MetricEndpointBuilder { _ep(&self.client, &self.name, Index::HalvingEpoch) } - pub fn difficultyepoch(&self) -> MetricEndpointBuilder { _ep(&self.client, &self.name, Index::DifficultyEpoch) } + pub fn halvingepoch(&self) -> MetricEndpointBuilder { _ep(&self.client, &self.name, Index::Halving) } + pub fn difficultyepoch(&self) -> MetricEndpointBuilder { _ep(&self.client, &self.name, Index::Epoch) } } pub struct MetricPattern2 { name: Arc, pub by: MetricPattern2By } @@ -659,7 +659,7 @@ impl MetricPattern for MetricPattern15 { fn get(&self pub struct MetricPattern16By { client: Arc, name: Arc, _marker: std::marker::PhantomData } impl MetricPattern16By { - pub fn halvingepoch(&self) -> MetricEndpointBuilder { _ep(&self.client, &self.name, Index::HalvingEpoch) } + pub fn halvingepoch(&self) -> MetricEndpointBuilder { _ep(&self.client, &self.name, Index::Halving) } } pub struct MetricPattern16 { name: Arc, pub by: MetricPattern16By } @@ -673,7 +673,7 @@ impl MetricPattern for MetricPattern16 { fn get(&self pub struct MetricPattern17By { client: Arc, name: Arc, _marker: std::marker::PhantomData } impl MetricPattern17By { - pub fn difficultyepoch(&self) -> MetricEndpointBuilder { _ep(&self.client, &self.name, Index::DifficultyEpoch) } + pub fn difficultyepoch(&self) -> MetricEndpointBuilder { _ep(&self.client, &self.name, Index::Epoch) } } pub struct MetricPattern17 { name: Arc, pub by: MetricPattern17By } @@ -2894,7 +2894,7 @@ pub struct MetricsTree_Blocks_Difficulty { pub raw: MetricPattern1, pub as_hash: MetricPattern1, pub adjustment: BpsPercentRatioPattern, - pub epoch: MetricPattern1, + pub epoch: MetricPattern1, pub blocks_before_next_adjustment: MetricPattern1, pub days_before_next_adjustment: MetricPattern1, } @@ -3067,7 +3067,7 @@ impl MetricsTree_Blocks_Count { /// Metrics tree node. pub struct MetricsTree_Blocks_Halving { - pub epoch: MetricPattern1, + pub epoch: MetricPattern1, pub blocks_before_next_halving: MetricPattern1, pub days_before_next_halving: MetricPattern1, } @@ -4082,8 +4082,8 @@ pub struct MetricsTree_Indexes_Height { pub hour12: MetricPattern18, pub day1: MetricPattern18, pub day3: MetricPattern18, - pub difficultyepoch: MetricPattern18, - pub halvingepoch: MetricPattern18, + pub difficultyepoch: MetricPattern18, + pub halvingepoch: MetricPattern18, pub week1: MetricPattern18, pub month1: MetricPattern18, pub month3: MetricPattern18, @@ -4119,7 +4119,7 @@ impl MetricsTree_Indexes_Height { /// Metrics tree node. pub struct MetricsTree_Indexes_Difficultyepoch { - pub identity: MetricPattern17, + pub identity: MetricPattern17, pub first_height: MetricPattern17, pub height_count: MetricPattern17, } @@ -4136,7 +4136,7 @@ impl MetricsTree_Indexes_Difficultyepoch { /// Metrics tree node. pub struct MetricsTree_Indexes_Halvingepoch { - pub identity: MetricPattern16, + pub identity: MetricPattern16, pub first_height: MetricPattern16, } diff --git a/crates/brk_cohort/README.md b/crates/brk_cohort/README.md index f8e1e34d6..955e0c87b 100644 --- a/crates/brk_cohort/README.md +++ b/crates/brk_cohort/README.md @@ -24,7 +24,7 @@ pub enum Filter { Term(Term), // STH/LTH Time(TimeFilter), // Age-based Amount(AmountFilter), // Value-based - Epoch(HalvingEpoch), // Halving epoch + Epoch(Halving), // Halving epoch Year(Year), // Calendar year Type(OutputType), // P2PKH, P2TR, etc. } @@ -48,5 +48,5 @@ ctx.full_name(&filter, "min_age_150d"); // "utxos_min_age_150d" ## Built On - `brk_error` for error handling -- `brk_types` for `Sats`, `HalvingEpoch`, `OutputType` +- `brk_types` for `Sats`, `Halving`, `OutputType` - `brk_traversable` for data structure traversal diff --git a/crates/brk_cohort/src/by_epoch.rs b/crates/brk_cohort/src/by_epoch.rs index 1ec1c2ec5..2428a1c28 100644 --- a/crates/brk_cohort/src/by_epoch.rs +++ b/crates/brk_cohort/src/by_epoch.rs @@ -1,17 +1,17 @@ use brk_traversable::Traversable; -use brk_types::{HalvingEpoch, Height}; +use brk_types::{Halving, Height}; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use serde::Serialize; use super::{CohortName, Filter}; /// Epoch values -pub const EPOCH_VALUES: ByEpoch = ByEpoch { - _0: HalvingEpoch::new(0), - _1: HalvingEpoch::new(1), - _2: HalvingEpoch::new(2), - _3: HalvingEpoch::new(3), - _4: HalvingEpoch::new(4), +pub const EPOCH_VALUES: ByEpoch = ByEpoch { + _0: Halving::new(0), + _1: Halving::new(1), + _2: Halving::new(2), + _3: Halving::new(3), + _4: Halving::new(4), }; /// Epoch filters @@ -108,16 +108,16 @@ impl ByEpoch { } pub fn mut_vec_from_height(&mut self, height: Height) -> &mut T { - let epoch = HalvingEpoch::from(height); - if epoch == HalvingEpoch::new(0) { + let epoch = Halving::from(height); + if epoch == Halving::new(0) { &mut self._0 - } else if epoch == HalvingEpoch::new(1) { + } else if epoch == Halving::new(1) { &mut self._1 - } else if epoch == HalvingEpoch::new(2) { + } else if epoch == Halving::new(2) { &mut self._2 - } else if epoch == HalvingEpoch::new(3) { + } else if epoch == Halving::new(3) { &mut self._3 - } else if epoch == HalvingEpoch::new(4) { + } else if epoch == Halving::new(4) { &mut self._4 } else { todo!("") diff --git a/crates/brk_cohort/src/filter.rs b/crates/brk_cohort/src/filter.rs index e1324afbb..91f7aaf62 100644 --- a/crates/brk_cohort/src/filter.rs +++ b/crates/brk_cohort/src/filter.rs @@ -1,4 +1,4 @@ -use brk_types::{HalvingEpoch, OutputType, Sats, Year}; +use brk_types::{Halving, OutputType, Sats, Year}; use super::{AmountFilter, CohortContext, Term, TimeFilter}; @@ -8,7 +8,7 @@ pub enum Filter { Term(Term), Time(TimeFilter), Amount(AmountFilter), - Epoch(HalvingEpoch), + Epoch(Halving), Class(Year), Type(OutputType), } diff --git a/crates/brk_computer/src/blocks/difficulty/compute.rs b/crates/brk_computer/src/blocks/difficulty/compute.rs index 1925d6e98..0a0a29e82 100644 --- a/crates/brk_computer/src/blocks/difficulty/compute.rs +++ b/crates/brk_computer/src/blocks/difficulty/compute.rs @@ -37,7 +37,7 @@ impl Vecs { // Compute epoch by height self.epoch.height.compute_transform( starting_indexes.height, - &indexes.height.difficulty, + &indexes.height.epoch, |(h, epoch, ..)| (h, epoch), exit, )?; diff --git a/crates/brk_computer/src/blocks/difficulty/vecs.rs b/crates/brk_computer/src/blocks/difficulty/vecs.rs index 37020a65e..b1cafa90f 100644 --- a/crates/brk_computer/src/blocks/difficulty/vecs.rs +++ b/crates/brk_computer/src/blocks/difficulty/vecs.rs @@ -1,5 +1,5 @@ use brk_traversable::Traversable; -use brk_types::{BasisPointsSigned32, DifficultyEpoch, StoredF32, StoredF64, StoredU32}; +use brk_types::{BasisPointsSigned32, Epoch, StoredF32, StoredF64, StoredU32}; use vecdb::{Rw, StorageMode}; use crate::internal::{ComputedPerBlock, Resolutions, PercentPerBlock}; @@ -8,7 +8,7 @@ pub struct Vecs { pub raw: Resolutions, pub as_hash: ComputedPerBlock, pub adjustment: PercentPerBlock, - pub epoch: ComputedPerBlock, + pub epoch: ComputedPerBlock, pub blocks_before_next_adjustment: ComputedPerBlock, pub days_before_next_adjustment: ComputedPerBlock, } diff --git a/crates/brk_computer/src/blocks/halving/vecs.rs b/crates/brk_computer/src/blocks/halving/vecs.rs index 8b4ad8bdd..a3561f0bd 100644 --- a/crates/brk_computer/src/blocks/halving/vecs.rs +++ b/crates/brk_computer/src/blocks/halving/vecs.rs @@ -1,11 +1,11 @@ use brk_traversable::Traversable; -use brk_types::{HalvingEpoch, StoredF32, StoredU32}; +use brk_types::{Halving, StoredF32, StoredU32}; use vecdb::{Rw, StorageMode}; use crate::internal::ComputedPerBlock; #[derive(Traversable)] pub struct Vecs { - pub epoch: ComputedPerBlock, + pub epoch: ComputedPerBlock, pub blocks_before_next_halving: ComputedPerBlock, pub days_before_next_halving: ComputedPerBlock, } diff --git a/crates/brk_computer/src/blocks/time/import.rs b/crates/brk_computer/src/blocks/time/import.rs index 4d7e1867e..deca6eaf8 100644 --- a/crates/brk_computer/src/blocks/time/import.rs +++ b/crates/brk_computer/src/blocks/time/import.rs @@ -60,7 +60,7 @@ impl TimestampIndexes { year1: period!(year1), year10: period!(year10), halving: epoch!(halving), - difficulty: epoch!(difficulty), + epoch: epoch!(difficulty), })) } } diff --git a/crates/brk_computer/src/blocks/time/vecs.rs b/crates/brk_computer/src/blocks/time/vecs.rs index 648e99675..c81d8ba66 100644 --- a/crates/brk_computer/src/blocks/time/vecs.rs +++ b/crates/brk_computer/src/blocks/time/vecs.rs @@ -1,7 +1,7 @@ use brk_error::Result; use brk_traversable::Traversable; use brk_types::{ - Date, Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour4, Hour12, Indexes, + Date, Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Indexes, Minute10, Minute30, Month1, Month3, Month6, Timestamp, Week1, Year1, Year10, }; use derive_more::{Deref, DerefMut}; @@ -39,8 +39,8 @@ pub struct TimestampIndexes( LazyVecFrom1, LazyVecFrom1, LazyVecFrom1, - M::Stored>>, - M::Stored>>, + M::Stored>>, + M::Stored>>, >, ); @@ -65,13 +65,13 @@ impl TimestampIndexes { &indexer.vecs.blocks.timestamp, exit, )?; - self.difficulty.compute_indirect_sequential( + self.epoch.compute_indirect_sequential( indexes .height - .difficulty + .epoch .collect_one(prev_height) .unwrap_or_default(), - &indexes.difficulty.first_height, + &indexes.epoch.first_height, &indexer.vecs.blocks.timestamp, exit, )?; diff --git a/crates/brk_computer/src/indexes/difficulty.rs b/crates/brk_computer/src/indexes/epoch.rs similarity index 65% rename from crates/brk_computer/src/indexes/difficulty.rs rename to crates/brk_computer/src/indexes/epoch.rs index cd07683df..62c6e16d8 100644 --- a/crates/brk_computer/src/indexes/difficulty.rs +++ b/crates/brk_computer/src/indexes/epoch.rs @@ -1,14 +1,14 @@ use brk_traversable::Traversable; -use brk_types::{DifficultyEpoch, Height, StoredU64, Version}; +use brk_types::{Epoch, Height, StoredU64, Version}; use vecdb::{Database, EagerVec, ImportableVec, PcoVec, Rw, StorageMode}; use brk_error::Result; #[derive(Traversable)] pub struct Vecs { - pub identity: M::Stored>>, - pub first_height: M::Stored>>, - pub height_count: M::Stored>>, + pub identity: M::Stored>>, + pub first_height: M::Stored>>, + pub height_count: M::Stored>>, } impl Vecs { diff --git a/crates/brk_computer/src/indexes/halving.rs b/crates/brk_computer/src/indexes/halving.rs index d09c783d1..183e91774 100644 --- a/crates/brk_computer/src/indexes/halving.rs +++ b/crates/brk_computer/src/indexes/halving.rs @@ -1,13 +1,13 @@ use brk_traversable::Traversable; -use brk_types::{HalvingEpoch, Height, Version}; +use brk_types::{Halving, Height, Version}; use vecdb::{Database, EagerVec, ImportableVec, PcoVec, Rw, StorageMode}; use brk_error::Result; #[derive(Traversable)] pub struct Vecs { - pub identity: M::Stored>>, - pub first_height: M::Stored>>, + pub identity: M::Stored>>, + pub first_height: M::Stored>>, } impl Vecs { diff --git a/crates/brk_computer/src/indexes/height.rs b/crates/brk_computer/src/indexes/height.rs index e3843d973..d8a80c811 100644 --- a/crates/brk_computer/src/indexes/height.rs +++ b/crates/brk_computer/src/indexes/height.rs @@ -1,6 +1,6 @@ use brk_traversable::Traversable; use brk_types::{ - Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour4, Hour12, Minute10, Minute30, + Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Minute10, Minute30, Month1, Month3, Month6, StoredU64, Version, Week1, Year1, Year10, }; use vecdb::{Database, EagerVec, ImportableVec, PcoVec, Rw, StorageMode}; @@ -17,8 +17,8 @@ pub struct Vecs { pub hour12: M::Stored>>, pub day1: M::Stored>>, pub day3: M::Stored>>, - pub difficulty: M::Stored>>, - pub halving: M::Stored>>, + pub epoch: M::Stored>>, + pub halving: M::Stored>>, pub week1: M::Stored>>, pub month1: M::Stored>>, pub month3: M::Stored>>, @@ -39,7 +39,7 @@ impl Vecs { hour12: EagerVec::forced_import(db, "hour12", version)?, day1: EagerVec::forced_import(db, "day1", version)?, day3: EagerVec::forced_import(db, "day3", version)?, - difficulty: EagerVec::forced_import(db, "difficulty", version)?, + epoch: EagerVec::forced_import(db, "difficulty", version)?, halving: EagerVec::forced_import(db, "halving", version)?, week1: EagerVec::forced_import(db, "week1", version)?, month1: EagerVec::forced_import(db, "month1", version)?, diff --git a/crates/brk_computer/src/indexes/mod.rs b/crates/brk_computer/src/indexes/mod.rs index 4f578127b..635b7e4ab 100644 --- a/crates/brk_computer/src/indexes/mod.rs +++ b/crates/brk_computer/src/indexes/mod.rs @@ -1,7 +1,7 @@ mod address; mod day1; mod day3; -mod difficulty; +mod epoch; mod halving; mod height; mod hour1; @@ -38,7 +38,7 @@ use crate::{ pub use address::Vecs as AddressVecs; pub use day1::Vecs as Day1Vecs; pub use day3::Vecs as Day3Vecs; -pub use difficulty::Vecs as DifficultyVecs; +pub use epoch::Vecs as EpochVecs; pub use halving::Vecs as HalvingVecs; pub use height::Vecs as HeightVecs; pub use hour1::Vecs as Hour1Vecs; @@ -63,7 +63,7 @@ pub struct Vecs { db: Database, pub address: AddressVecs, pub height: HeightVecs, - pub difficulty: DifficultyVecs, + pub epoch: EpochVecs, pub halving: HalvingVecs, pub minute10: Minute10Vecs, pub minute30: Minute30Vecs, @@ -96,7 +96,7 @@ impl Vecs { let this = Self { address: AddressVecs::forced_import(version, indexer), height: HeightVecs::forced_import(&db, version)?, - difficulty: DifficultyVecs::forced_import(&db, version)?, + epoch: EpochVecs::forced_import(&db, version)?, halving: HalvingVecs::forced_import(&db, version)?, minute10: Minute10Vecs::forced_import(&db, version)?, minute30: Minute30Vecs::forced_import(&db, version)?, @@ -318,30 +318,30 @@ impl Vecs { ) -> Result<()> { let starting_difficulty = self .height - .difficulty + .epoch .collect_one(prev_height) .unwrap_or_default(); - self.height.difficulty.compute_from_index( + self.height.epoch.compute_from_index( starting_indexes.height, &indexer.vecs.blocks.weight, exit, )?; - self.difficulty.first_height.compute_first_per_index( + self.epoch.first_height.compute_first_per_index( starting_indexes.height, - &self.height.difficulty, + &self.height.epoch, exit, )?; - self.difficulty.identity.compute_from_index( + self.epoch.identity.compute_from_index( starting_difficulty, - &self.difficulty.first_height, + &self.epoch.first_height, exit, )?; - self.difficulty + self.epoch .height_count .compute_count_from_indexes( starting_difficulty, - &self.difficulty.first_height, + &self.epoch.first_height, &blocks_time.date, exit, )?; diff --git a/crates/brk_computer/src/internal/containers/per_resolution.rs b/crates/brk_computer/src/internal/containers/per_resolution.rs index d1242da9b..ce9185b6a 100644 --- a/crates/brk_computer/src/internal/containers/per_resolution.rs +++ b/crates/brk_computer/src/internal/containers/per_resolution.rs @@ -17,5 +17,5 @@ pub struct PerResolution( ::Stored>>, ::Stored>>, ::Stored>>, - ::Stored>>, - ::Stored>>, + ::Stored>>, + ::Stored>>, >, ) where @@ -68,7 +68,7 @@ where year1: per_period!(), year10: per_period!(), halving: per_period!(), - difficulty: per_period!(), + epoch: per_period!(), })) } @@ -110,7 +110,7 @@ where period!(year1); period!(year10); period!(halving); - period!(difficulty); + period!(epoch); Ok(()) } @@ -157,7 +157,7 @@ where period!(year1); period!(year10); period!(halving); - period!(difficulty); + period!(epoch); Ok(()) } @@ -204,7 +204,7 @@ where period!(year1); period!(year10); period!(halving); - period!(difficulty); + period!(epoch); Ok(()) } diff --git a/crates/brk_computer/src/internal/indexes/lazy.rs b/crates/brk_computer/src/internal/indexes/lazy.rs index f25b64ea0..15db3380d 100644 --- a/crates/brk_computer/src/internal/indexes/lazy.rs +++ b/crates/brk_computer/src/internal/indexes/lazy.rs @@ -1,6 +1,6 @@ use brk_traversable::Traversable; use brk_types::{ - Day1, Day3, DifficultyEpoch, HalvingEpoch, Hour1, Hour4, Hour12, Minute10, Minute30, Month1, + Day1, Day3, Epoch, Halving, Hour1, Hour4, Hour12, Minute10, Minute30, Month1, Month3, Month6, Version, Week1, Year1, Year10, }; use derive_more::{Deref, DerefMut}; @@ -27,8 +27,8 @@ pub struct LazyEagerIndexes( LazyVecFrom1, LazyVecFrom1, LazyVecFrom1, - LazyVecFrom1, - LazyVecFrom1, + LazyVecFrom1, + LazyVecFrom1, >, ) where @@ -70,7 +70,7 @@ where year1: period!(year1), year10: period!(year10), halving: period!(halving), - difficulty: period!(difficulty), + epoch: period!(epoch), }) } } diff --git a/crates/brk_computer/src/internal/per_block/computed/constant.rs b/crates/brk_computer/src/internal/per_block/computed/constant.rs index ee352f457..2c52f9bff 100644 --- a/crates/brk_computer/src/internal/per_block/computed/constant.rs +++ b/crates/brk_computer/src/internal/per_block/computed/constant.rs @@ -1,6 +1,6 @@ use brk_traversable::Traversable; use brk_types::{ - Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour4, Hour12, Minute10, Minute30, + Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Minute10, Minute30, Month1, Month3, Month6, Version, Week1, Year1, Year10, }; use schemars::JsonSchema; @@ -29,8 +29,8 @@ where pub month6: LazyVecFrom1, pub year1: LazyVecFrom1, pub year10: LazyVecFrom1, - pub halving: LazyVecFrom1, - pub difficulty: LazyVecFrom1, + pub halving: LazyVecFrom1, + pub epoch: LazyVecFrom1, } impl ConstantVecs { @@ -50,8 +50,8 @@ impl ConstantVecs { + UnaryTransform + UnaryTransform + UnaryTransform - + UnaryTransform - + UnaryTransform, + + UnaryTransform + + UnaryTransform, { macro_rules! period { ($idx:ident) => { @@ -79,7 +79,7 @@ impl ConstantVecs { year1: period!(year1), year10: period!(year10), halving: period!(halving), - difficulty: period!(difficulty), + epoch: period!(epoch), } } } diff --git a/crates/brk_computer/src/internal/per_block/computed/resolutions.rs b/crates/brk_computer/src/internal/per_block/computed/resolutions.rs index 25703e303..f0bbf9411 100644 --- a/crates/brk_computer/src/internal/per_block/computed/resolutions.rs +++ b/crates/brk_computer/src/internal/per_block/computed/resolutions.rs @@ -1,6 +1,6 @@ use brk_traversable::Traversable; use brk_types::{ - Day1, Day3, DifficultyEpoch, FromCoarserIndex, HalvingEpoch, Height, Hour1, Hour4, Hour12, + Day1, Day3, Epoch, FromCoarserIndex, Halving, Height, Hour1, Hour4, Hour12, Minute10, Minute30, Month1, Month3, Month6, Version, Week1, Year1, Year10, }; use derive_more::{Deref, DerefMut}; @@ -32,8 +32,8 @@ pub struct Resolutions( LazyAggVec, Height, Height, T>, LazyAggVec, Height, Height, T>, LazyAggVec, Height, Height, T>, - LazyAggVec, - LazyAggVec, + LazyAggVec, + LazyAggVec, >, ) where @@ -128,7 +128,7 @@ where year1: period!(year1), year10: period!(year10), halving: epoch!(halving), - difficulty: epoch!(difficulty), + epoch: epoch!(epoch), }) } } diff --git a/crates/brk_computer/src/internal/per_block/lazy/derived_resolutions.rs b/crates/brk_computer/src/internal/per_block/lazy/derived_resolutions.rs index 086832694..fa534b236 100644 --- a/crates/brk_computer/src/internal/per_block/lazy/derived_resolutions.rs +++ b/crates/brk_computer/src/internal/per_block/lazy/derived_resolutions.rs @@ -1,6 +1,6 @@ use brk_traversable::Traversable; use brk_types::{ - Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour4, Hour12, Minute10, Minute30, + Day1, Day3, Epoch, Halving, Height, Hour1, Hour4, Hour12, Minute10, Minute30, Month1, Month3, Month6, Version, Week1, Year1, Year10, }; use derive_more::{Deref, DerefMut}; @@ -34,8 +34,8 @@ pub struct DerivedResolutions( LazyTransformLast, Option>, LazyTransformLast, Option>, LazyTransformLast, Option>, - LazyTransformLast, - LazyTransformLast, + LazyTransformLast, + LazyTransformLast, >, ) where @@ -110,7 +110,7 @@ where year1: period!(year1), year10: period!(year10), halving: epoch!(halving), - difficulty: epoch!(difficulty), + epoch: epoch!(epoch), }) } @@ -154,7 +154,7 @@ where year1: period!(year1), year10: period!(year10), halving: epoch!(halving), - difficulty: epoch!(difficulty), + epoch: epoch!(epoch), }) } } diff --git a/crates/brk_computer/src/internal/transform/specialized.rs b/crates/brk_computer/src/internal/transform/specialized.rs index 8fded075f..8911b2452 100644 --- a/crates/brk_computer/src/internal/transform/specialized.rs +++ b/crates/brk_computer/src/internal/transform/specialized.rs @@ -1,5 +1,5 @@ use brk_types::{ - Close, Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, High, Hour1, Hour4, Hour12, Low, + Close, Day1, Day3, Epoch, Halving, Height, High, Hour1, Hour4, Hour12, Low, Minute10, Minute30, Month1, Month3, Month6, OHLCCents, OHLCDollars, OHLCSats, Open, StoredU64, Week1, Year1, Year10, }; @@ -114,16 +114,16 @@ impl UnaryTransform for BlockCountTarget { } } -impl UnaryTransform for BlockCountTarget { +impl UnaryTransform for BlockCountTarget { #[inline(always)] - fn apply(_: HalvingEpoch) -> StoredU64 { + fn apply(_: Halving) -> StoredU64 { StoredU64::from(TARGET_BLOCKS_PER_HALVING) } } -impl UnaryTransform for BlockCountTarget { +impl UnaryTransform for BlockCountTarget { #[inline(always)] - fn apply(_: DifficultyEpoch) -> StoredU64 { + fn apply(_: Epoch) -> StoredU64 { StoredU64::from(2016u64) } } diff --git a/crates/brk_computer/src/mining/rewards/compute.rs b/crates/brk_computer/src/mining/rewards/compute.rs index 9418ffddc..9255c53d9 100644 --- a/crates/brk_computer/src/mining/rewards/compute.rs +++ b/crates/brk_computer/src/mining/rewards/compute.rs @@ -1,6 +1,6 @@ use brk_error::Result; use brk_indexer::Indexer; -use brk_types::{BasisPoints16, CheckedSub, HalvingEpoch, Indexes, Sats}; +use brk_types::{BasisPoints16, CheckedSub, Halving, Indexes, Sats}; use vecdb::{Exit, ReadableVec, VecIndex}; use super::Vecs; @@ -102,7 +102,7 @@ impl Vecs { starting_indexes.height, &self.subsidy.base.sats.height, |(height, subsidy, ..)| { - let halving = HalvingEpoch::from(height); + let halving = Halving::from(height); let expected = Sats::FIFTY_BTC / 2_usize.pow(halving.to_usize() as u32); (height, expected.checked_sub(subsidy).unwrap()) }, diff --git a/crates/brk_computer/src/prices/ohlcs.rs b/crates/brk_computer/src/prices/ohlcs.rs index bd75d33e6..4a9bb7285 100644 --- a/crates/brk_computer/src/prices/ohlcs.rs +++ b/crates/brk_computer/src/prices/ohlcs.rs @@ -1,7 +1,7 @@ use brk_error::Result; use brk_traversable::Traversable; use brk_types::{ - Cents, Close, Day1, Day3, DifficultyEpoch, HalvingEpoch, High, Hour1, Hour4, Hour12, Indexes, + Cents, Close, Day1, Day3, Epoch, Halving, High, Hour1, Hour4, Hour12, Indexes, Low, Minute10, Minute30, Month1, Month3, Month6, OHLCCents, Open, Version, Week1, Year1, Year10, }; @@ -36,8 +36,8 @@ pub struct OhlcVecs( ::Stored>>, ::Stored>>, ::Stored>>, - ::Stored>>, - ::Stored>>, + ::Stored>>, + ::Stored>>, >, ) where @@ -73,7 +73,7 @@ where year1: per_period!(), year10: per_period!(), halving: per_period!(), - difficulty: per_period!(), + epoch: per_period!(), })) } } @@ -169,7 +169,7 @@ impl OhlcVecs { period!(year1); period!(year10); epoch!(halving); - epoch!(difficulty); + epoch!(epoch); Ok(()) } @@ -193,8 +193,8 @@ pub struct LazyOhlcVecs( LazyVecFrom1, LazyVecFrom1, LazyVecFrom1, - LazyVecFrom1, - LazyVecFrom1, + LazyVecFrom1, + LazyVecFrom1, >, ) where @@ -236,7 +236,7 @@ where year1: period!(year1), year10: period!(year10), halving: period!(halving), - difficulty: period!(difficulty), + epoch: period!(epoch), }) } } diff --git a/crates/brk_query/src/impl/mining/difficulty.rs b/crates/brk_query/src/impl/mining/difficulty.rs index 518c79711..e04058510 100644 --- a/crates/brk_query/src/impl/mining/difficulty.rs +++ b/crates/brk_query/src/impl/mining/difficulty.rs @@ -1,7 +1,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use brk_error::Result; -use brk_types::{DifficultyAdjustment, DifficultyEpoch, Height}; +use brk_types::{DifficultyAdjustment, Epoch, Height}; use vecdb::ReadableVec; use crate::Query; @@ -23,7 +23,7 @@ impl Query { let current_epoch = computer .indexes .height - .difficulty + .epoch .collect_one(current_height) .unwrap(); let current_epoch_usize: usize = current_epoch.into(); @@ -31,7 +31,7 @@ impl Query { // Get epoch start height let epoch_start_height = computer .indexes - .difficulty + .epoch .first_height .collect_one(current_epoch) .unwrap(); @@ -48,7 +48,7 @@ impl Query { .blocks .time .timestamp - .difficulty + .epoch .collect_one(current_epoch) .unwrap(); let current_timestamp = indexer @@ -87,10 +87,10 @@ impl Query { // Calculate previous retarget using stored difficulty values let previous_retarget = if current_epoch_usize > 0 { - let prev_epoch = DifficultyEpoch::from(current_epoch_usize - 1); + let prev_epoch = Epoch::from(current_epoch_usize - 1); let prev_epoch_start = computer .indexes - .difficulty + .epoch .first_height .collect_one(prev_epoch) .unwrap(); diff --git a/crates/brk_query/src/impl/mining/epochs.rs b/crates/brk_query/src/impl/mining/epochs.rs index cbded9414..9b224a51d 100644 --- a/crates/brk_query/src/impl/mining/epochs.rs +++ b/crates/brk_query/src/impl/mining/epochs.rs @@ -1,5 +1,5 @@ use brk_computer::Computer; -use brk_types::{DifficultyAdjustmentEntry, DifficultyEpoch, Height}; +use brk_types::{DifficultyAdjustmentEntry, Epoch, Height}; use vecdb::{ReadableVec, Ro, VecIndex}; /// Iterate over difficulty epochs within a height range. @@ -11,25 +11,25 @@ pub fn iter_difficulty_epochs( let start_epoch = computer .indexes .height - .difficulty + .epoch .collect_one(Height::from(start_height)) .unwrap_or_default(); let end_epoch = computer .indexes .height - .difficulty + .epoch .collect_one(Height::from(end_height)) .unwrap_or_default(); - let epoch_to_height = &computer.indexes.difficulty.first_height; - let epoch_to_timestamp = &computer.blocks.time.timestamp.difficulty; - let epoch_to_difficulty = &computer.blocks.difficulty.raw.difficulty; + let epoch_to_height = &computer.indexes.epoch.first_height; + let epoch_to_timestamp = &computer.blocks.time.timestamp.epoch; + let epoch_to_difficulty = &computer.blocks.difficulty.raw.epoch; let mut results = Vec::with_capacity(end_epoch.to_usize() - start_epoch.to_usize() + 1); let mut prev_difficulty: Option = None; for epoch_usize in start_epoch.to_usize()..=end_epoch.to_usize() { - let epoch = DifficultyEpoch::from(epoch_usize); + let epoch = Epoch::from(epoch_usize); let epoch_height = epoch_to_height.collect_one(epoch).unwrap_or_default(); // Skip epochs before our start height but track difficulty diff --git a/crates/brk_types/README.md b/crates/brk_types/README.md index 68cf7a083..00f84d894 100644 --- a/crates/brk_types/README.md +++ b/crates/brk_types/README.md @@ -11,7 +11,7 @@ Work with Bitcoin primitives (heights, satoshis, addresses, transactions) throug - **Bitcoin primitives**: `Height`, `Sats`, `Txid`, `BlockHash`, `Outpoint` with full arithmetic and conversion support - **Address types**: All output types (P2PK33, P2PK65, P2PKH, P2MS, P2SH, P2WPKH, P2WSH, P2TR, P2A, OP_RETURN) with address index variants - **Time indexes**: `DateIndex`, `WeekIndex`, `MonthIndex`, `QuarterIndex`, `SemesterIndex`, `YearIndex`, `DecadeIndex` with cross-index conversion -- **Protocol types**: `DifficultyEpoch`, `HalvingEpoch`, `TxVersion`, `RawLocktime` +- **Protocol types**: `Epoch`, `Halving`, `TxVersion`, `RawLocktime` - **Financial types**: `Dollars`, `Cents`, `OHLC` (Open/High/Low/Close) - **Serialization**: Serde + JSON Schema generation via schemars - **Compression**: PCO (Pco) derive for columnar compression in vecdb diff --git a/crates/brk_types/src/difficultyepoch.rs b/crates/brk_types/src/epoch.rs similarity index 73% rename from crates/brk_types/src/difficultyepoch.rs rename to crates/brk_types/src/epoch.rs index 3af287694..876cc7077 100644 --- a/crates/brk_types/src/difficultyepoch.rs +++ b/crates/brk_types/src/epoch.rs @@ -25,30 +25,30 @@ pub const BLOCKS_PER_DIFF_EPOCHS: u32 = 2016; Pco, JsonSchema, )] -pub struct DifficultyEpoch(u16); +pub struct Epoch(u16); -impl From for DifficultyEpoch { +impl From for Epoch { #[inline] fn from(value: u16) -> Self { Self(value) } } -impl From for DifficultyEpoch { +impl From for Epoch { #[inline] fn from(value: usize) -> Self { Self(value as u16) } } -impl From for usize { +impl From for usize { #[inline] - fn from(value: DifficultyEpoch) -> Self { + fn from(value: Epoch) -> Self { value.0 as usize } } -impl Add for DifficultyEpoch { +impl Add for Epoch { type Output = Self; fn add(self, rhs: Self) -> Self::Output { @@ -56,13 +56,13 @@ impl Add for DifficultyEpoch { } } -impl AddAssign for DifficultyEpoch { +impl AddAssign for Epoch { fn add_assign(&mut self, rhs: Self) { *self = *self + rhs } } -impl Add for DifficultyEpoch { +impl Add for Epoch { type Output = Self; fn add(self, rhs: usize) -> Self::Output { @@ -70,37 +70,37 @@ impl Add for DifficultyEpoch { } } -impl Div for DifficultyEpoch { +impl Div for Epoch { type Output = Self; fn div(self, rhs: usize) -> Self::Output { Self::from(self.0 as usize / rhs) } } -impl From for DifficultyEpoch { +impl From for Epoch { #[inline] fn from(value: Height) -> Self { Self((u32::from(value) / BLOCKS_PER_DIFF_EPOCHS) as u16) } } -impl CheckedSub for DifficultyEpoch { +impl CheckedSub for Epoch { fn checked_sub(self, rhs: Self) -> Option { self.0.checked_sub(rhs.0).map(Self) } } -impl PrintableIndex for DifficultyEpoch { +impl PrintableIndex for Epoch { fn to_string() -> &'static str { "difficultyepoch" } fn to_possible_strings() -> &'static [&'static str] { - &["difficulty", "difficultyepoch", "diff"] + &["epoch", "difficulty", "difficultyepoch", "diff"] } } -impl std::fmt::Display for DifficultyEpoch { +impl std::fmt::Display for Epoch { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut buf = itoa::Buffer::new(); let str = buf.format(self.0); @@ -108,7 +108,7 @@ impl std::fmt::Display for DifficultyEpoch { } } -impl Formattable for DifficultyEpoch { +impl Formattable for Epoch { #[inline(always)] fn write_to(&self, buf: &mut Vec) { let mut b = itoa::Buffer::new(); @@ -116,7 +116,7 @@ impl Formattable for DifficultyEpoch { } } -impl From for DifficultyEpoch { +impl From for Epoch { #[inline] fn from(value: f64) -> Self { let value = value.max(0.0); @@ -124,9 +124,9 @@ impl From for DifficultyEpoch { } } -impl From for f64 { +impl From for f64 { #[inline] - fn from(value: DifficultyEpoch) -> Self { + fn from(value: Epoch) -> Self { value.0 as f64 } } diff --git a/crates/brk_types/src/halvingepoch.rs b/crates/brk_types/src/halving.rs similarity index 76% rename from crates/brk_types/src/halvingepoch.rs rename to crates/brk_types/src/halving.rs index 7947ab593..ea1e20362 100644 --- a/crates/brk_types/src/halvingepoch.rs +++ b/crates/brk_types/src/halving.rs @@ -25,36 +25,36 @@ pub const BLOCKS_PER_HALVING: u32 = 210_000; Pco, JsonSchema, )] -pub struct HalvingEpoch(u8); +pub struct Halving(u8); -impl HalvingEpoch { +impl Halving { pub const fn new(value: u8) -> Self { Self(value) } } -impl From for HalvingEpoch { +impl From for Halving { #[inline] fn from(value: u8) -> Self { Self(value) } } -impl From for HalvingEpoch { +impl From for Halving { #[inline] fn from(value: usize) -> Self { Self(value as u8) } } -impl From for usize { +impl From for usize { #[inline] - fn from(value: HalvingEpoch) -> Self { + fn from(value: Halving) -> Self { value.0 as usize } } -impl Add for HalvingEpoch { +impl Add for Halving { type Output = Self; fn add(self, rhs: Self) -> Self::Output { @@ -62,13 +62,13 @@ impl Add for HalvingEpoch { } } -impl AddAssign for HalvingEpoch { +impl AddAssign for Halving { fn add_assign(&mut self, rhs: Self) { *self = *self + rhs } } -impl Add for HalvingEpoch { +impl Add for Halving { type Output = Self; fn add(self, rhs: usize) -> Self::Output { @@ -76,27 +76,27 @@ impl Add for HalvingEpoch { } } -impl From for HalvingEpoch { +impl From for Halving { #[inline] fn from(value: Height) -> Self { Self((u32::from(value) / BLOCKS_PER_HALVING) as u8) } } -impl CheckedSub for HalvingEpoch { +impl CheckedSub for Halving { fn checked_sub(self, rhs: Self) -> Option { self.0.checked_sub(rhs.0).map(Self) } } -impl Div for HalvingEpoch { +impl Div for Halving { type Output = Self; fn div(self, rhs: usize) -> Self::Output { Self::from(self.0 as usize / rhs) } } -impl PrintableIndex for HalvingEpoch { +impl PrintableIndex for Halving { fn to_string() -> &'static str { "halvingepoch" } @@ -106,7 +106,7 @@ impl PrintableIndex for HalvingEpoch { } } -impl std::fmt::Display for HalvingEpoch { +impl std::fmt::Display for Halving { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut buf = itoa::Buffer::new(); let str = buf.format(self.0); @@ -114,7 +114,7 @@ impl std::fmt::Display for HalvingEpoch { } } -impl Formattable for HalvingEpoch { +impl Formattable for Halving { #[inline(always)] fn write_to(&self, buf: &mut Vec) { let mut b = itoa::Buffer::new(); @@ -122,7 +122,7 @@ impl Formattable for HalvingEpoch { } } -impl From for HalvingEpoch { +impl From for Halving { #[inline] fn from(value: f64) -> Self { let value = value.max(0.0); @@ -130,9 +130,9 @@ impl From for HalvingEpoch { } } -impl From for f64 { +impl From for f64 { #[inline] - fn from(value: HalvingEpoch) -> Self { + fn from(value: Halving) -> Self { value.0 as f64 } } diff --git a/crates/brk_types/src/height.rs b/crates/brk_types/src/height.rs index 25cdbc94b..ea2053d95 100644 --- a/crates/brk_types/src/height.rs +++ b/crates/brk_types/src/height.rs @@ -12,7 +12,7 @@ use vecdb::{Bytes, CheckedSub, Formattable, Pco, PrintableIndex, Stamp}; use crate::{BLOCKS_PER_DIFF_EPOCHS, BLOCKS_PER_HALVING, FromCoarserIndex}; -use super::{DifficultyEpoch, HalvingEpoch, StoredU64}; +use super::{Epoch, Halving, StoredU64}; /// Block height #[derive( @@ -292,22 +292,22 @@ impl Formattable for Height { } } -impl FromCoarserIndex for Height { - fn min_from(coarser: DifficultyEpoch) -> usize { +impl FromCoarserIndex for Height { + fn min_from(coarser: Epoch) -> usize { usize::from(coarser) * BLOCKS_PER_DIFF_EPOCHS as usize } - fn max_from_(coarser: DifficultyEpoch) -> usize { + fn max_from_(coarser: Epoch) -> usize { (usize::from(coarser) + 1) * BLOCKS_PER_DIFF_EPOCHS as usize - 1 } } -impl FromCoarserIndex for Height { - fn min_from(coarser: HalvingEpoch) -> usize { +impl FromCoarserIndex for Height { + fn min_from(coarser: Halving) -> usize { usize::from(coarser) * BLOCKS_PER_HALVING as usize } - fn max_from_(coarser: HalvingEpoch) -> usize { + fn max_from_(coarser: Halving) -> usize { (usize::from(coarser) + 1) * BLOCKS_PER_HALVING as usize - 1 } } diff --git a/crates/brk_types/src/index.rs b/crates/brk_types/src/index.rs index f2162265f..27443beb4 100644 --- a/crates/brk_types/src/index.rs +++ b/crates/brk_types/src/index.rs @@ -8,8 +8,8 @@ use vecdb::PrintableIndex; use crate::PairOutputIndex; use super::{ - Date, Day1, Day3, DifficultyEpoch, EmptyAddressIndex, EmptyOutputIndex, FundedAddressIndex, - HalvingEpoch, Height, Hour1, Hour4, Hour12, Minute10, Minute30, Month1, Month3, Month6, + Date, Day1, Day3, Epoch, EmptyAddressIndex, EmptyOutputIndex, FundedAddressIndex, + Halving, Height, Hour1, Hour4, Hour12, Minute10, Minute30, Month1, Month3, Month6, OpReturnIndex, P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, Timestamp, TxInIndex, TxIndex, TxOutIndex, UnknownOutputIndex, Week1, Year1, Year10, @@ -36,8 +36,8 @@ pub enum Index { Month6, Year1, Year10, - HalvingEpoch, - DifficultyEpoch, + Halving, + Epoch, Height, TxIndex, TxInIndex, @@ -75,8 +75,8 @@ impl Index { Self::Month6, Self::Year1, Self::Year10, - Self::HalvingEpoch, - Self::DifficultyEpoch, + Self::Halving, + Self::Epoch, Self::Height, Self::TxIndex, Self::TxInIndex, @@ -114,8 +114,8 @@ impl Index { Self::Month6 => Month6::to_possible_strings(), Self::Year1 => Year1::to_possible_strings(), Self::Year10 => Year10::to_possible_strings(), - Self::HalvingEpoch => HalvingEpoch::to_possible_strings(), - Self::DifficultyEpoch => DifficultyEpoch::to_possible_strings(), + Self::Halving => Halving::to_possible_strings(), + Self::Epoch => Epoch::to_possible_strings(), Self::Height => Height::to_possible_strings(), Self::TxIndex => TxIndex::to_possible_strings(), Self::TxInIndex => TxInIndex::to_possible_strings(), @@ -160,8 +160,8 @@ impl Index { Self::Month6 => ::to_string(), Self::Year1 => ::to_string(), Self::Year10 => ::to_string(), - Self::HalvingEpoch => ::to_string(), - Self::DifficultyEpoch => ::to_string(), + Self::Halving => ::to_string(), + Self::Epoch => ::to_string(), Self::Height => ::to_string(), Self::TxIndex => ::to_string(), Self::TxInIndex => ::to_string(), @@ -188,7 +188,7 @@ impl Index { /// Used for rate limiting to account for expensive lazy computations. pub const fn cost_multiplier(&self) -> usize { match self { - Self::DifficultyEpoch => 60, + Self::Epoch => 60, _ => 1, } } diff --git a/crates/brk_types/src/lib.rs b/crates/brk_types/src/lib.rs index a42fbd54d..4fdf2fb8d 100644 --- a/crates/brk_types/src/lib.rs +++ b/crates/brk_types/src/lib.rs @@ -57,7 +57,7 @@ mod deser; mod difficultyadjustment; mod difficultyadjustmententry; mod difficultyentry; -mod difficultyepoch; +mod epoch; mod diskusage; mod dollars; mod emptyaddressdata; @@ -71,7 +71,7 @@ mod formatresponse; mod from_coarser; mod fundedaddressdata; mod fundedaddressindex; -mod halvingepoch; +mod halving; mod hashrateentry; mod hashratesummary; mod health; @@ -249,7 +249,7 @@ pub use deser::*; pub use difficultyadjustment::*; pub use difficultyadjustmententry::*; pub use difficultyentry::*; -pub use difficultyepoch::*; +pub use epoch::*; pub use diskusage::*; pub use dollars::*; pub use emptyaddressdata::*; @@ -263,7 +263,7 @@ pub use formatresponse::*; pub use from_coarser::*; pub use fundedaddressdata::*; pub use fundedaddressindex::*; -pub use halvingepoch::*; +pub use halving::*; pub use hashrateentry::*; pub use hashratesummary::*; pub use health::*; diff --git a/crates/brk_types/src/treenode.rs b/crates/brk_types/src/treenode.rs index 70c8bd009..9491cf8fb 100644 --- a/crates/brk_types/src/treenode.rs +++ b/crates/brk_types/src/treenode.rs @@ -466,7 +466,7 @@ mod tests { // - height_cumulative (renamed to "cumulative") → direct leaf at Height // - day1 → branch with sum/cumulative at Day1 // - week1 (flattened from dates) → branch with sum/cumulative at Week1 - // - difficultyepoch → branch with sum/cumulative at DifficultyEpoch + // - difficultyepoch → branch with sum/cumulative at Epoch let tree = branch(vec![ ("cumulative", leaf("metric_cumulative", Index::Height)), ( @@ -486,10 +486,10 @@ mod tests { ( "difficultyepoch", branch(vec![ - ("sum", leaf("metric_sum", Index::DifficultyEpoch)), + ("sum", leaf("metric_sum", Index::Epoch)), ( "cumulative", - leaf("metric_cumulative", Index::DifficultyEpoch), + leaf("metric_cumulative", Index::Epoch), ), ]), ), @@ -501,19 +501,19 @@ mod tests { TreeNode::Branch(map) => { assert_eq!(map.len(), 2); - // sum: Day1, Week1, DifficultyEpoch (NOT Height) + // sum: Day1, Week1, Epoch (NOT Height) let sum_indexes = get_leaf_indexes(map.get("sum").unwrap()).unwrap(); assert!(!sum_indexes.contains(&Index::Height)); assert!(sum_indexes.contains(&Index::Day1)); assert!(sum_indexes.contains(&Index::Week1)); - assert!(sum_indexes.contains(&Index::DifficultyEpoch)); + assert!(sum_indexes.contains(&Index::Epoch)); - // cumulative: Height, Day1, Week1, DifficultyEpoch + // cumulative: Height, Day1, Week1, Epoch let cumulative_indexes = get_leaf_indexes(map.get("cumulative").unwrap()).unwrap(); assert!(cumulative_indexes.contains(&Index::Height)); assert!(cumulative_indexes.contains(&Index::Day1)); assert!(cumulative_indexes.contains(&Index::Week1)); - assert!(cumulative_indexes.contains(&Index::DifficultyEpoch)); + assert!(cumulative_indexes.contains(&Index::Epoch)); } _ => panic!("Expected branch"), } diff --git a/modules/brk-client/docs/globals.md b/modules/brk-client/docs/globals.md index 8972f0e40..b52856cf3 100644 --- a/modules/brk-client/docs/globals.md +++ b/modules/brk-client/docs/globals.md @@ -280,14 +280,14 @@ - [Date](type-aliases/Date.md) - [DateIndex](type-aliases/DateIndex.md) - [DecadeIndex](type-aliases/DecadeIndex.md) -- [DifficultyEpoch](type-aliases/DifficultyEpoch.md) +- [Epoch](type-aliases/Epoch.md) - [Dollars](type-aliases/Dollars.md) - [EmptyAddressIndex](type-aliases/EmptyAddressIndex.md) - [EmptyOutputIndex](type-aliases/EmptyOutputIndex.md) - [FeeRate](type-aliases/FeeRate.md) - [Format](type-aliases/Format.md) - [FundedAddressIndex](type-aliases/FundedAddressIndex.md) -- [HalvingEpoch](type-aliases/HalvingEpoch.md) +- [Halving](type-aliases/Halving.md) - [Height](type-aliases/Height.md) - [Hex](type-aliases/Hex.md) - [High](type-aliases/High.md) diff --git a/modules/brk-client/docs/type-aliases/DifficultyEpoch.md b/modules/brk-client/docs/type-aliases/Epoch.md similarity index 68% rename from modules/brk-client/docs/type-aliases/DifficultyEpoch.md rename to modules/brk-client/docs/type-aliases/Epoch.md index 0ad53ff12..fa98abb3f 100644 --- a/modules/brk-client/docs/type-aliases/DifficultyEpoch.md +++ b/modules/brk-client/docs/type-aliases/Epoch.md @@ -2,11 +2,11 @@ *** -[brk-client](../globals.md) / DifficultyEpoch +[brk-client](../globals.md) / Epoch -# Type Alias: DifficultyEpoch +# Type Alias: Epoch -> **DifficultyEpoch**\<\> = `number` +> **Epoch**\<\> = `number` Defined in: [Developer/brk/modules/brk-client/index.js:281](https://github.com/bitcoinresearchkit/brk/blob/4a06caec672337d1974d77b021e6d10711049dbe/modules/brk-client/index.js#L281) diff --git a/modules/brk-client/docs/type-aliases/HalvingEpoch.md b/modules/brk-client/docs/type-aliases/Halving.md similarity index 69% rename from modules/brk-client/docs/type-aliases/HalvingEpoch.md rename to modules/brk-client/docs/type-aliases/Halving.md index 45782bda8..9b147423d 100644 --- a/modules/brk-client/docs/type-aliases/HalvingEpoch.md +++ b/modules/brk-client/docs/type-aliases/Halving.md @@ -2,11 +2,11 @@ *** -[brk-client](../globals.md) / HalvingEpoch +[brk-client](../globals.md) / Halving -# Type Alias: HalvingEpoch +# Type Alias: Halving -> **HalvingEpoch**\<\> = `number` +> **Halving**\<\> = `number` Defined in: [Developer/brk/modules/brk-client/index.js:330](https://github.com/bitcoinresearchkit/brk/blob/4a06caec672337d1974d77b021e6d10711049dbe/modules/brk-client/index.js#L330) diff --git a/modules/brk-client/index.js b/modules/brk-client/index.js index 778d8f014..4465c9c82 100644 --- a/modules/brk-client/index.js +++ b/modules/brk-client/index.js @@ -312,7 +312,7 @@ * @property {number} difficulty - Difficulty value. * @property {Height} height - Block height of the adjustment. */ -/** @typedef {number} DifficultyEpoch */ +/** @typedef {number} Epoch */ /** * Disk usage of the indexed data * @@ -361,7 +361,7 @@ * @property {CentsSquaredSats} investorCapRaw - The investor capitalization: Σ(price² × sats) */ /** @typedef {TypeIndex} FundedAddressIndex */ -/** @typedef {number} HalvingEpoch */ +/** @typedef {number} Halving */ /** * A single hashrate data point. * @@ -3718,7 +3718,7 @@ function create_24hPattern(client, acc) { * @property {MetricPattern1} raw * @property {MetricPattern1} asHash * @property {BpsPercentRatioPattern} adjustment - * @property {MetricPattern1} epoch + * @property {MetricPattern1} epoch * @property {MetricPattern1} blocksBeforeNextAdjustment * @property {MetricPattern1} daysBeforeNextAdjustment */ @@ -3797,7 +3797,7 @@ function create_24hPattern(client, acc) { /** * @typedef {Object} MetricsTree_Blocks_Halving - * @property {MetricPattern1} epoch + * @property {MetricPattern1} epoch * @property {MetricPattern1} blocksBeforeNextHalving * @property {MetricPattern1} daysBeforeNextHalving */ @@ -4238,8 +4238,8 @@ function create_24hPattern(client, acc) { * @property {MetricPattern18} hour12 * @property {MetricPattern18} day1 * @property {MetricPattern18} day3 - * @property {MetricPattern18} difficultyepoch - * @property {MetricPattern18} halvingepoch + * @property {MetricPattern18} difficultyepoch + * @property {MetricPattern18} halvingepoch * @property {MetricPattern18} week1 * @property {MetricPattern18} month1 * @property {MetricPattern18} month3 @@ -4251,14 +4251,14 @@ function create_24hPattern(client, acc) { /** * @typedef {Object} MetricsTree_Indexes_Difficultyepoch - * @property {MetricPattern17} identity + * @property {MetricPattern17} identity * @property {MetricPattern17} firstHeight * @property {MetricPattern17} heightCount */ /** * @typedef {Object} MetricsTree_Indexes_Halvingepoch - * @property {MetricPattern16} identity + * @property {MetricPattern16} identity * @property {MetricPattern16} firstHeight */ diff --git a/packages/brk_client/brk_client/__init__.py b/packages/brk_client/brk_client/__init__.py index 88ed8a084..3beee10bb 100644 --- a/packages/brk_client/brk_client/__init__.py +++ b/packages/brk_client/brk_client/__init__.py @@ -88,7 +88,7 @@ Limit = int Date = int Day1 = int Day3 = int -DifficultyEpoch = int +Epoch = int # US Dollar amount as floating point Dollars = float EmptyAddressIndex = TypeIndex @@ -96,7 +96,7 @@ EmptyOutputIndex = TypeIndex # Fee rate in sats/vB FeeRate = float FundedAddressIndex = TypeIndex -HalvingEpoch = int +Halving = int # Hex-encoded string Hex = str # Highest price value for a time period @@ -3011,7 +3011,7 @@ class MetricsTree_Blocks_Difficulty: self.raw: MetricPattern1[StoredF64] = MetricPattern1(client, 'difficulty') self.as_hash: MetricPattern1[StoredF64] = MetricPattern1(client, 'difficulty_as_hash') self.adjustment: BpsPercentRatioPattern = BpsPercentRatioPattern(client, 'difficulty_adjustment') - self.epoch: MetricPattern1[DifficultyEpoch] = MetricPattern1(client, 'difficulty_epoch') + self.epoch: MetricPattern1[Epoch] = MetricPattern1(client, 'difficulty_epoch') self.blocks_before_next_adjustment: MetricPattern1[StoredU32] = MetricPattern1(client, 'blocks_before_next_difficulty_adjustment') self.days_before_next_adjustment: MetricPattern1[StoredF32] = MetricPattern1(client, 'days_before_next_difficulty_adjustment') @@ -3094,7 +3094,7 @@ class MetricsTree_Blocks_Halving: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.epoch: MetricPattern1[HalvingEpoch] = MetricPattern1(client, 'halving_epoch') + self.epoch: MetricPattern1[Halving] = MetricPattern1(client, 'halving_epoch') self.blocks_before_next_halving: MetricPattern1[StoredU32] = MetricPattern1(client, 'blocks_before_next_halving') self.days_before_next_halving: MetricPattern1[StoredF32] = MetricPattern1(client, 'days_before_next_halving') @@ -3573,8 +3573,8 @@ class MetricsTree_Indexes_Height: self.hour12: MetricPattern18[Hour12] = MetricPattern18(client, 'hour12') self.day1: MetricPattern18[Day1] = MetricPattern18(client, 'day1') self.day3: MetricPattern18[Day3] = MetricPattern18(client, 'day3') - self.difficultyepoch: MetricPattern18[DifficultyEpoch] = MetricPattern18(client, 'difficultyepoch') - self.halvingepoch: MetricPattern18[HalvingEpoch] = MetricPattern18(client, 'halvingepoch') + self.difficultyepoch: MetricPattern18[Epoch] = MetricPattern18(client, 'difficultyepoch') + self.halvingepoch: MetricPattern18[Halving] = MetricPattern18(client, 'halvingepoch') self.week1: MetricPattern18[Week1] = MetricPattern18(client, 'week1') self.month1: MetricPattern18[Month1] = MetricPattern18(client, 'month1') self.month3: MetricPattern18[Month3] = MetricPattern18(client, 'month3') @@ -3587,7 +3587,7 @@ class MetricsTree_Indexes_Difficultyepoch: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern17[DifficultyEpoch] = MetricPattern17(client, 'difficultyepoch') + self.identity: MetricPattern17[Epoch] = MetricPattern17(client, 'difficultyepoch') self.first_height: MetricPattern17[Height] = MetricPattern17(client, 'first_height') self.height_count: MetricPattern17[StoredU64] = MetricPattern17(client, 'height_count') @@ -3595,7 +3595,7 @@ class MetricsTree_Indexes_Halvingepoch: """Metrics tree node.""" def __init__(self, client: BrkClientBase, base_path: str = ''): - self.identity: MetricPattern16[HalvingEpoch] = MetricPattern16(client, 'halvingepoch') + self.identity: MetricPattern16[Halving] = MetricPattern16(client, 'halvingepoch') self.first_height: MetricPattern16[Height] = MetricPattern16(client, 'first_height') class MetricsTree_Indexes_Minute10: