mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-31 10:13:39 -07:00
global: snapshot
This commit is contained in:
@@ -7,7 +7,7 @@ use brk_error::Result;
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour4, Hour12, Minute1, Minute5,
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour4, Hour12,
|
||||
Minute10, Minute30, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
@@ -18,7 +18,7 @@ use vecdb::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes, indexes_from,
|
||||
ComputeIndexes, indexes, indexes_apply, indexes_from,
|
||||
internal::{ComputedVecValue, Indexes, NumericValue},
|
||||
};
|
||||
|
||||
@@ -27,8 +27,6 @@ use crate::{
|
||||
pub struct EagerIndexes<T, M: StorageMode = Rw>(
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub Indexes<
|
||||
<M as StorageMode>::Stored<EagerVec<PcoVec<Minute1, T>>>,
|
||||
<M as StorageMode>::Stored<EagerVec<PcoVec<Minute5, T>>>,
|
||||
<M as StorageMode>::Stored<EagerVec<PcoVec<Minute10, T>>>,
|
||||
<M as StorageMode>::Stored<EagerVec<PcoVec<Minute30, T>>>,
|
||||
<M as StorageMode>::Stored<EagerVec<PcoVec<Hour1, T>>>,
|
||||
@@ -86,23 +84,7 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
period!(minute1);
|
||||
period!(minute5);
|
||||
period!(minute10);
|
||||
period!(minute30);
|
||||
period!(hour1);
|
||||
period!(hour4);
|
||||
period!(hour12);
|
||||
period!(day1);
|
||||
period!(day3);
|
||||
period!(week1);
|
||||
period!(month1);
|
||||
period!(month3);
|
||||
period!(month6);
|
||||
period!(year1);
|
||||
period!(year10);
|
||||
period!(halvingepoch);
|
||||
period!(difficultyepoch);
|
||||
indexes_apply!(period);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -131,23 +113,7 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
period!(minute1);
|
||||
period!(minute5);
|
||||
period!(minute10);
|
||||
period!(minute30);
|
||||
period!(hour1);
|
||||
period!(hour4);
|
||||
period!(hour12);
|
||||
period!(day1);
|
||||
period!(day3);
|
||||
period!(week1);
|
||||
period!(month1);
|
||||
period!(month3);
|
||||
period!(month6);
|
||||
period!(year1);
|
||||
period!(year10);
|
||||
period!(halvingepoch);
|
||||
period!(difficultyepoch);
|
||||
indexes_apply!(period);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -176,23 +142,7 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
period!(minute1);
|
||||
period!(minute5);
|
||||
period!(minute10);
|
||||
period!(minute30);
|
||||
period!(hour1);
|
||||
period!(hour4);
|
||||
period!(hour12);
|
||||
period!(day1);
|
||||
period!(day3);
|
||||
period!(week1);
|
||||
period!(month1);
|
||||
period!(month3);
|
||||
period!(month6);
|
||||
period!(year1);
|
||||
period!(year10);
|
||||
period!(halvingepoch);
|
||||
period!(difficultyepoch);
|
||||
indexes_apply!(period);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour12, Hour4, Minute1, Minute10,
|
||||
Minute30, Minute5, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour12, Hour4,
|
||||
Minute10, Minute30, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
@@ -18,8 +18,6 @@ where
|
||||
T: VecValue + Formattable + Serialize + JsonSchema,
|
||||
{
|
||||
pub height: LazyVecFrom1<Height, T, Height, Height>,
|
||||
pub minute1: LazyVecFrom1<Minute1, T, Minute1, Minute1>,
|
||||
pub minute5: LazyVecFrom1<Minute5, T, Minute5, Minute5>,
|
||||
pub minute10: LazyVecFrom1<Minute10, T, Minute10, Minute10>,
|
||||
pub minute30: LazyVecFrom1<Minute30, T, Minute30, Minute30>,
|
||||
pub hour1: LazyVecFrom1<Hour1, T, Hour1, Hour1>,
|
||||
@@ -42,8 +40,6 @@ impl<T: VecValue + Formattable + Serialize + JsonSchema> ConstantVecs<T> {
|
||||
pub(crate) fn new<F>(name: &str, version: Version, indexes: &indexes::Vecs) -> Self
|
||||
where
|
||||
F: UnaryTransform<Height, T>
|
||||
+ UnaryTransform<Minute1, T>
|
||||
+ UnaryTransform<Minute5, T>
|
||||
+ UnaryTransform<Minute10, T>
|
||||
+ UnaryTransform<Minute30, T>
|
||||
+ UnaryTransform<Hour1, T>
|
||||
@@ -76,8 +72,6 @@ impl<T: VecValue + Formattable + Serialize + JsonSchema> ConstantVecs<T> {
|
||||
version,
|
||||
indexes.height.identity.read_only_boxed_clone(),
|
||||
),
|
||||
minute1: period!(minute1, Minute1),
|
||||
minute5: period!(minute5, Minute5),
|
||||
minute10: period!(minute10, Minute10),
|
||||
minute30: period!(minute30, Minute30),
|
||||
hour1: period!(hour1, Hour1),
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, FromCoarserIndex, HalvingEpoch, Height, Hour1, Hour4, Hour12,
|
||||
Minute1, Minute5, Minute10, Minute30, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
Minute10, Minute30, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
@@ -21,8 +21,6 @@ use crate::{
|
||||
pub struct ComputedHeightDerivedLast<T>(
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub Indexes<
|
||||
LazyAggVec<Minute1, Option<T>, Height, Height, T>,
|
||||
LazyAggVec<Minute5, Option<T>, Height, Height, T>,
|
||||
LazyAggVec<Minute10, Option<T>, Height, Height, T>,
|
||||
LazyAggVec<Minute30, Option<T>, Height, Height, T>,
|
||||
LazyAggVec<Hour1, Option<T>, Height, Height, T>,
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::marker::PhantomData;
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour4, Hour12, Minute1, Minute5,
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour4, Hour12,
|
||||
Minute10, Minute30, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
@@ -60,8 +60,6 @@ where
|
||||
pub struct LazyHeightDerivedLast<T, S1T = T>(
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub Indexes<
|
||||
LazyTransformLast<Minute1, Option<T>, Option<S1T>>,
|
||||
LazyTransformLast<Minute5, Option<T>, Option<S1T>>,
|
||||
LazyTransformLast<Minute10, Option<T>, Option<S1T>>,
|
||||
LazyTransformLast<Minute30, Option<T>, Option<S1T>>,
|
||||
LazyTransformLast<Hour1, Option<T>, Option<S1T>>,
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
//! Base generic struct with 17 type parameters — one per time period/epoch index.
|
||||
//! Base generic struct with 15 type parameters — one per time period/epoch index.
|
||||
//!
|
||||
//! Foundation for all per-index types. Replaces the repetitive 17-field pattern
|
||||
//! Foundation for all per-index types. Replaces the repetitive 15-field pattern
|
||||
//! found throughout height_derived types.
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
#[traversable(merge)]
|
||||
pub struct Indexes<M1, M5, M10, M30, H1, H4, H12, D1, D3, W1, Mo1, Mo3, Mo6, Y1, Y10, HE, DE> {
|
||||
pub minute1: M1,
|
||||
pub minute5: M5,
|
||||
pub struct Indexes<M10, M30, H1, H4, H12, D1, D3, W1, Mo1, Mo3, Mo6, Y1, Y10, HE, DE> {
|
||||
pub minute10: M10,
|
||||
pub minute30: M30,
|
||||
pub hour1: H1,
|
||||
@@ -38,8 +36,6 @@ pub struct Indexes<M1, M5, M10, M30, H1, H4, H12, D1, D3, W1, Mo1, Mo3, Mo6, Y1,
|
||||
macro_rules! indexes_from {
|
||||
($period:ident, $epoch:ident) => {
|
||||
$crate::internal::Indexes {
|
||||
minute1: $period!(minute1),
|
||||
minute5: $period!(minute5),
|
||||
minute10: $period!(minute10),
|
||||
minute30: $period!(minute30),
|
||||
hour1: $period!(hour1),
|
||||
@@ -63,29 +59,28 @@ macro_rules! indexes_from {
|
||||
};
|
||||
}
|
||||
|
||||
/// Helper macro to apply a function/macro to each field of an `Indexes` value.
|
||||
/// Imperative counterpart to `indexes_from!` — calls `$period!(field)` for each
|
||||
/// period field and `$epoch!(field)` for each epoch field.
|
||||
#[macro_export]
|
||||
macro_rules! indexes_map {
|
||||
($indexes:expr, |$field:ident| $body:expr) => {{
|
||||
let src = $indexes;
|
||||
$crate::internal::Indexes {
|
||||
minute1: { let $field = src.minute1; $body },
|
||||
minute5: { let $field = src.minute5; $body },
|
||||
minute10: { let $field = src.minute10; $body },
|
||||
minute30: { let $field = src.minute30; $body },
|
||||
hour1: { let $field = src.hour1; $body },
|
||||
hour4: { let $field = src.hour4; $body },
|
||||
hour12: { let $field = src.hour12; $body },
|
||||
day1: { let $field = src.day1; $body },
|
||||
day3: { let $field = src.day3; $body },
|
||||
week1: { let $field = src.week1; $body },
|
||||
month1: { let $field = src.month1; $body },
|
||||
month3: { let $field = src.month3; $body },
|
||||
month6: { let $field = src.month6; $body },
|
||||
year1: { let $field = src.year1; $body },
|
||||
year10: { let $field = src.year10; $body },
|
||||
halvingepoch: { let $field = src.halvingepoch; $body },
|
||||
difficultyepoch: { let $field = src.difficultyepoch; $body },
|
||||
}
|
||||
}};
|
||||
macro_rules! indexes_apply {
|
||||
($period:ident, $epoch:ident) => {
|
||||
$period!(minute10);
|
||||
$period!(minute30);
|
||||
$period!(hour1);
|
||||
$period!(hour4);
|
||||
$period!(hour12);
|
||||
$period!(day1);
|
||||
$period!(day3);
|
||||
$period!(week1);
|
||||
$period!(month1);
|
||||
$period!(month3);
|
||||
$period!(month6);
|
||||
$period!(year1);
|
||||
$period!(year10);
|
||||
$epoch!(halvingepoch);
|
||||
$epoch!(difficultyepoch);
|
||||
};
|
||||
($m:ident) => {
|
||||
$crate::indexes_apply!($m, $m)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Hour1, Hour4, Hour12, Minute1, Minute5, Minute10,
|
||||
Minute30, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Hour1, Hour4, Hour12,
|
||||
Minute10, Minute30, Month1, Month3, Month6, Version, Week1, Year1, Year10,
|
||||
};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
@@ -22,8 +22,6 @@ use crate::{
|
||||
pub struct LazyEagerIndexes<T, S>(
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub Indexes<
|
||||
LazyVecFrom1<Minute1, T, Minute1, S>,
|
||||
LazyVecFrom1<Minute5, T, Minute5, S>,
|
||||
LazyVecFrom1<Minute10, T, Minute10, S>,
|
||||
LazyVecFrom1<Minute30, T, Minute30, S>,
|
||||
LazyVecFrom1<Hour1, T, Hour1, S>,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use brk_types::{
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour12, Hour4, Minute1, Minute10,
|
||||
Minute30, Minute5, Month1, Month3, Month6, StoredU64, Week1, Year1, Year10,
|
||||
Day1, Day3, DifficultyEpoch, HalvingEpoch, Height, Hour1, Hour12, Hour4,
|
||||
Minute10, Minute30, Month1, Month3, Month6, StoredU64, Week1, Year1, Year10,
|
||||
};
|
||||
use vecdb::UnaryTransform;
|
||||
|
||||
use crate::blocks::{
|
||||
TARGET_BLOCKS_PER_DAY, TARGET_BLOCKS_PER_DAY3, TARGET_BLOCKS_PER_DECADE,
|
||||
TARGET_BLOCKS_PER_HALVING, TARGET_BLOCKS_PER_HOUR1, TARGET_BLOCKS_PER_HOUR12,
|
||||
TARGET_BLOCKS_PER_HOUR4, TARGET_BLOCKS_PER_MINUTE1, TARGET_BLOCKS_PER_MINUTE10,
|
||||
TARGET_BLOCKS_PER_MINUTE30, TARGET_BLOCKS_PER_MINUTE5, TARGET_BLOCKS_PER_MONTH,
|
||||
TARGET_BLOCKS_PER_HOUR4, TARGET_BLOCKS_PER_MINUTE10,
|
||||
TARGET_BLOCKS_PER_MINUTE30, TARGET_BLOCKS_PER_MONTH,
|
||||
TARGET_BLOCKS_PER_QUARTER, TARGET_BLOCKS_PER_SEMESTER, TARGET_BLOCKS_PER_WEEK,
|
||||
TARGET_BLOCKS_PER_YEAR,
|
||||
};
|
||||
@@ -22,20 +22,6 @@ impl UnaryTransform<Height, StoredU64> for BlockCountTarget {
|
||||
}
|
||||
}
|
||||
|
||||
impl UnaryTransform<Minute1, StoredU64> for BlockCountTarget {
|
||||
#[inline(always)]
|
||||
fn apply(_: Minute1) -> StoredU64 {
|
||||
StoredU64::from(TARGET_BLOCKS_PER_MINUTE1)
|
||||
}
|
||||
}
|
||||
|
||||
impl UnaryTransform<Minute5, StoredU64> for BlockCountTarget {
|
||||
#[inline(always)]
|
||||
fn apply(_: Minute5) -> StoredU64 {
|
||||
StoredU64::from(TARGET_BLOCKS_PER_MINUTE5)
|
||||
}
|
||||
}
|
||||
|
||||
impl UnaryTransform<Minute10, StoredU64> for BlockCountTarget {
|
||||
#[inline(always)]
|
||||
fn apply(_: Minute10) -> StoredU64 {
|
||||
|
||||
Reference in New Issue
Block a user