mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 23:29:58 -07:00
global: utxos part 6
This commit is contained in:
@@ -103,9 +103,7 @@ where
|
||||
)?;
|
||||
|
||||
let height: Option<&EagerVec<Height, T>> = None;
|
||||
self.compute_rest(indexes, starting_indexes, exit, height)?;
|
||||
|
||||
Ok(())
|
||||
self.compute_rest(indexes, starting_indexes, exit, height)
|
||||
}
|
||||
|
||||
pub fn compute_rest(
|
||||
|
||||
@@ -18,7 +18,7 @@ use super::{ComputedVecsFromDateIndex, StorableVecGeneatorOptions};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ComputedRatioVecsFromDateIndex {
|
||||
pub price: ComputedVecsFromDateIndex<Dollars>,
|
||||
pub price: Option<ComputedVecsFromDateIndex<Dollars>>,
|
||||
|
||||
pub ratio: ComputedVecsFromDateIndex<StoredF32>,
|
||||
pub ratio_sma: ComputedVecsFromDateIndex<StoredF32>,
|
||||
@@ -60,19 +60,22 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
pub fn forced_import(
|
||||
path: &Path,
|
||||
name: &str,
|
||||
// _compute_source: bool,
|
||||
compute_source: bool,
|
||||
version: Version,
|
||||
compressed: Compressed,
|
||||
options: StorableVecGeneatorOptions,
|
||||
) -> color_eyre::Result<Self> {
|
||||
Ok(Self {
|
||||
price: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
name,
|
||||
VERSION + version,
|
||||
compressed,
|
||||
options,
|
||||
)?,
|
||||
price: compute_source.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
name,
|
||||
VERSION + version,
|
||||
compressed,
|
||||
options,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
ratio: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&format!("{name}_ratio"),
|
||||
@@ -300,7 +303,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn compute<F>(
|
||||
pub fn compute_all<F>(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
@@ -319,8 +322,34 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
) -> Result<()>,
|
||||
{
|
||||
self.price
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.compute(indexer, indexes, starting_indexes, exit, compute)?;
|
||||
|
||||
let date_to_price_opt: Option<&EagerVec<DateIndex, Dollars>> = None;
|
||||
self.compute_rest(
|
||||
indexer,
|
||||
indexes,
|
||||
fetched,
|
||||
starting_indexes,
|
||||
exit,
|
||||
date_to_price_opt,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn compute_rest(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
fetched: &fetched::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
date_to_price_opt: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
|
||||
) -> color_eyre::Result<()> {
|
||||
let date_to_price = date_to_price_opt.unwrap_or_else(|| unsafe {
|
||||
std::mem::transmute(&self.price.as_ref().unwrap().dateindex)
|
||||
});
|
||||
|
||||
let closes = &fetched.timeindexes_to_close.dateindex;
|
||||
|
||||
self.ratio.compute(
|
||||
@@ -329,7 +358,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v, _, _, starting_indexes, exit| {
|
||||
let mut price = self.price.dateindex.into_iter();
|
||||
let mut price = date_to_price.iter();
|
||||
v.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
closes,
|
||||
@@ -590,6 +619,10 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
self.ratio_m3sd
|
||||
.compute_rest(indexes, starting_indexes, exit)?;
|
||||
|
||||
let date_to_price = date_to_price_opt.unwrap_or_else(|| unsafe {
|
||||
std::mem::transmute(&self.price.as_ref().unwrap().dateindex)
|
||||
});
|
||||
|
||||
self.ratio_p99_as_price.compute(
|
||||
indexer,
|
||||
indexes,
|
||||
@@ -599,7 +632,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
let mut iter = self.ratio_p99.dateindex.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&self.price.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
(i, price * multiplier)
|
||||
@@ -618,7 +651,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
let mut iter = self.ratio_p99_5.dateindex.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&self.price.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
(i, price * multiplier)
|
||||
@@ -637,7 +670,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
let mut iter = self.ratio_p99_9.dateindex.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&self.price.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
(i, price * multiplier)
|
||||
@@ -656,7 +689,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
let mut iter = self.ratio_p1.dateindex.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&self.price.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
(i, price * multiplier)
|
||||
@@ -675,7 +708,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
let mut iter = self.ratio_p0_5.dateindex.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&self.price.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
(i, price * multiplier)
|
||||
@@ -694,7 +727,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
let mut iter = self.ratio_p0_1.dateindex.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&self.price.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
(i, price * multiplier)
|
||||
@@ -713,7 +746,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
let mut iter = self.ratio_p1sd.dateindex.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&self.price.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
(i, price * multiplier)
|
||||
@@ -732,7 +765,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
let mut iter = self.ratio_p2sd.dateindex.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&self.price.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
(i, price * multiplier)
|
||||
@@ -751,7 +784,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
let mut iter = self.ratio_p3sd.dateindex.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&self.price.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
(i, price * multiplier)
|
||||
@@ -770,7 +803,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
let mut iter = self.ratio_m1sd.dateindex.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&self.price.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
(i, price * multiplier)
|
||||
@@ -789,7 +822,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
let mut iter = self.ratio_m2sd.dateindex.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&self.price.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
(i, price * multiplier)
|
||||
@@ -808,7 +841,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
let mut iter = self.ratio_m3sd.dateindex.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&self.price.dateindex,
|
||||
date_to_price,
|
||||
|(i, price, ..)| {
|
||||
let multiplier = iter.unwrap_get_inner(i);
|
||||
(i, price * multiplier)
|
||||
@@ -862,7 +895,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
|
||||
pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {
|
||||
[
|
||||
self.price.vecs(),
|
||||
self.price.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
self.ratio.vecs(),
|
||||
self.ratio_sma.vecs(),
|
||||
self.ratio_1w_sma.vecs(),
|
||||
|
||||
@@ -209,6 +209,7 @@ impl Vecs {
|
||||
indexes_to_1w_sma: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"1w_sma",
|
||||
true,
|
||||
VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
@@ -216,6 +217,7 @@ impl Vecs {
|
||||
indexes_to_8d_sma: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"8d_sma",
|
||||
true,
|
||||
VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
@@ -223,6 +225,7 @@ impl Vecs {
|
||||
indexes_to_13d_sma: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"13d_sma",
|
||||
true,
|
||||
VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
@@ -230,6 +233,7 @@ impl Vecs {
|
||||
indexes_to_21d_sma: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"21d_sma",
|
||||
true,
|
||||
VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
@@ -237,6 +241,7 @@ impl Vecs {
|
||||
indexes_to_1m_sma: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"1m_sma",
|
||||
true,
|
||||
VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
@@ -244,6 +249,7 @@ impl Vecs {
|
||||
indexes_to_34d_sma: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"34d_sma",
|
||||
true,
|
||||
VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
@@ -251,6 +257,7 @@ impl Vecs {
|
||||
indexes_to_55d_sma: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"55d_sma",
|
||||
true,
|
||||
VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
@@ -258,6 +265,7 @@ impl Vecs {
|
||||
indexes_to_89d_sma: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"89d_sma",
|
||||
true,
|
||||
VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
@@ -265,6 +273,7 @@ impl Vecs {
|
||||
indexes_to_144d_sma: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"144d_sma",
|
||||
true,
|
||||
VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
@@ -272,6 +281,7 @@ impl Vecs {
|
||||
indexes_to_1y_sma: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"1y_sma",
|
||||
true,
|
||||
VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
@@ -279,6 +289,7 @@ impl Vecs {
|
||||
indexes_to_2y_sma: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"2y_sma",
|
||||
true,
|
||||
VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
@@ -286,6 +297,7 @@ impl Vecs {
|
||||
indexes_to_200w_sma: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"200w_sma",
|
||||
true,
|
||||
VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
@@ -293,6 +305,7 @@ impl Vecs {
|
||||
indexes_to_4y_sma: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"4y_sma",
|
||||
true,
|
||||
VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
@@ -1622,7 +1635,7 @@ impl Vecs {
|
||||
.into_iter()
|
||||
.for_each(|(vecs, sma)| {
|
||||
s.spawn(move || -> color_eyre::Result<()> {
|
||||
vecs.compute(
|
||||
vecs.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
fetched,
|
||||
|
||||
@@ -25,7 +25,7 @@ pub struct Vecs {
|
||||
pub mining: mining::Vecs,
|
||||
pub market: market::Vecs,
|
||||
pub transactions: transactions::Vecs,
|
||||
// pub utxos: utxos::Vecs,
|
||||
pub utxos: utxos::Vecs,
|
||||
pub fetched: Option<fetched::Vecs>,
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ impl Vecs {
|
||||
mining: mining::Vecs::forced_import(path, computation, compressed)?,
|
||||
constants: constants::Vecs::forced_import(path, computation, compressed)?,
|
||||
market: market::Vecs::forced_import(path, computation, compressed)?,
|
||||
// utxos: utxos::Vecs::forced_import(path, computation, compressed, fetched.as_ref())?,
|
||||
utxos: utxos::Vecs::forced_import(path, computation, compressed, fetched.as_ref())?,
|
||||
transactions: transactions::Vecs::forced_import(
|
||||
path,
|
||||
indexer,
|
||||
@@ -110,14 +110,14 @@ impl Vecs {
|
||||
)?;
|
||||
}
|
||||
|
||||
// self.utxos.compute(
|
||||
// indexer,
|
||||
// &self.indexes,
|
||||
// &self.transactions,
|
||||
// self.fetched.as_ref(),
|
||||
// &starting_indexes,
|
||||
// exit,
|
||||
// )?;
|
||||
self.utxos.compute(
|
||||
indexer,
|
||||
&self.indexes,
|
||||
&self.transactions,
|
||||
self.fetched.as_ref(),
|
||||
&starting_indexes,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -130,7 +130,7 @@ impl Vecs {
|
||||
self.mining.vecs(),
|
||||
self.market.vecs(),
|
||||
self.transactions.vecs(),
|
||||
// self.utxos.vecs(),
|
||||
self.utxos.vecs(),
|
||||
self.fetched.as_ref().map_or(vec![], |v| v.vecs()),
|
||||
]
|
||||
.into_iter()
|
||||
|
||||
@@ -12,7 +12,8 @@ use crate::{
|
||||
vecs::{
|
||||
Indexes, fetched,
|
||||
grouped::{
|
||||
ComputedValueVecsFromHeight, ComputedVecsFromHeight, StorableVecGeneatorOptions,
|
||||
ComputedRatioVecsFromDateIndex, ComputedValueVecsFromHeight, ComputedVecsFromHeight,
|
||||
StorableVecGeneatorOptions,
|
||||
},
|
||||
indexes,
|
||||
},
|
||||
@@ -30,6 +31,9 @@ pub struct Vecs {
|
||||
pub indexes_to_supply: ComputedValueVecsFromHeight,
|
||||
pub height_to_utxo_count: EagerVec<Height, StoredUsize>,
|
||||
pub indexes_to_utxo_count: ComputedVecsFromHeight<StoredUsize>,
|
||||
|
||||
pub indexes_to_realized_price: Option<ComputedVecsFromHeight<Dollars>>,
|
||||
pub indexes_to_realized_price_extra: Option<ComputedRatioVecsFromDateIndex>,
|
||||
}
|
||||
|
||||
impl Vecs {
|
||||
@@ -38,6 +42,7 @@ impl Vecs {
|
||||
cohort_name: Option<&str>,
|
||||
_computation: Computation,
|
||||
compressed: Compressed,
|
||||
version: Version,
|
||||
fetched: Option<&fetched::Vecs>,
|
||||
) -> color_eyre::Result<Self> {
|
||||
let compute_dollars = fetched.is_some();
|
||||
@@ -48,15 +53,20 @@ impl Vecs {
|
||||
|
||||
let suffix = |s: &str| cohort_name.map_or(s.to_string(), |name| format!("{name}_{s}"));
|
||||
|
||||
let mut state = CohortState::default();
|
||||
if compute_dollars {
|
||||
state.realized_cap = Some(Dollars::ZERO);
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
starting_height: Height::ZERO,
|
||||
state: CohortState::default(),
|
||||
state,
|
||||
|
||||
height_to_realized_cap: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
&suffix("realized_cap"),
|
||||
VERSION + Version::ZERO,
|
||||
VERSION + Version::ZERO + version,
|
||||
compressed,
|
||||
)
|
||||
.unwrap()
|
||||
@@ -66,7 +76,7 @@ impl Vecs {
|
||||
path,
|
||||
&suffix("realized_cap"),
|
||||
false,
|
||||
VERSION + Version::ZERO,
|
||||
VERSION + Version::ZERO + version,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
)
|
||||
@@ -75,14 +85,14 @@ impl Vecs {
|
||||
height_to_supply: EagerVec::forced_import(
|
||||
path,
|
||||
&suffix("supply"),
|
||||
VERSION + Version::ZERO,
|
||||
VERSION + Version::ZERO + version,
|
||||
compressed,
|
||||
)?,
|
||||
indexes_to_supply: ComputedValueVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("supply"),
|
||||
false,
|
||||
VERSION + Version::ZERO,
|
||||
VERSION + Version::ZERO + version,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
compute_dollars,
|
||||
@@ -90,22 +100,45 @@ impl Vecs {
|
||||
height_to_utxo_count: EagerVec::forced_import(
|
||||
path,
|
||||
&suffix("utxo_count"),
|
||||
VERSION + Version::ZERO,
|
||||
VERSION + Version::ZERO + version,
|
||||
compressed,
|
||||
)?,
|
||||
indexes_to_utxo_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("utxo_count"),
|
||||
false,
|
||||
VERSION + Version::ZERO,
|
||||
VERSION + Version::ZERO + version,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
)?,
|
||||
|
||||
indexes_to_realized_price: compute_dollars.then(|| {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("realized_price"),
|
||||
true,
|
||||
VERSION + Version::ZERO + version,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
indexes_to_realized_price_extra: compute_dollars.then(|| {
|
||||
ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("realized_price"),
|
||||
false,
|
||||
VERSION + Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn init(&mut self, starting_indexes: &Indexes) -> Height {
|
||||
self.starting_height = [
|
||||
pub fn starting_height(&self) -> Height {
|
||||
[
|
||||
self.height_to_supply.len(),
|
||||
self.height_to_utxo_count.len(),
|
||||
self.height_to_realized_cap
|
||||
@@ -116,29 +149,33 @@ impl Vecs {
|
||||
.map(Height::from)
|
||||
.min()
|
||||
.unwrap()
|
||||
.min(starting_indexes.height);
|
||||
}
|
||||
|
||||
if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() {
|
||||
if let Some(prev_height) = self.starting_height.checked_sub(Height::new(1)) {
|
||||
self.state.supply.value = self
|
||||
.height_to_supply
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height);
|
||||
self.state.supply.utxos = *self
|
||||
.height_to_utxo_count
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height);
|
||||
pub fn init(&mut self, starting_height: Height) {
|
||||
if starting_height > self.starting_height() {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
self.starting_height = starting_height;
|
||||
|
||||
if let Some(prev_height) = starting_height.checked_sub(Height::new(1)) {
|
||||
self.state.supply.value = self
|
||||
.height_to_supply
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height);
|
||||
self.state.supply.utxos = *self
|
||||
.height_to_utxo_count
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height);
|
||||
|
||||
if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() {
|
||||
self.state.realized_cap = Some(
|
||||
height_to_realized_cap
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height),
|
||||
);
|
||||
} else {
|
||||
self.state.realized_cap = Some(Dollars::ZERO);
|
||||
}
|
||||
}
|
||||
|
||||
self.starting_height
|
||||
}
|
||||
|
||||
pub fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
|
||||
@@ -157,10 +194,15 @@ impl Vecs {
|
||||
base_version + height_to_realized_cap.inner_version(),
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn forced_pushed_at(&mut self, height: Height, exit: &Exit) -> Result<()> {
|
||||
if self.starting_height > height {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.height_to_supply
|
||||
.forced_push_at(height, self.state.supply.value, exit)?;
|
||||
|
||||
@@ -173,7 +215,10 @@ impl Vecs {
|
||||
if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() {
|
||||
height_to_realized_cap.forced_push_at(
|
||||
height,
|
||||
self.state.realized_cap.unwrap(),
|
||||
self.state.realized_cap.unwrap_or_else(|| {
|
||||
dbg!(&self.state);
|
||||
panic!();
|
||||
}),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
@@ -225,6 +270,41 @@ impl Vecs {
|
||||
)?;
|
||||
}
|
||||
|
||||
if let Some(indexes_to_realized_price) = self.indexes_to_realized_price.as_mut() {
|
||||
indexes_to_realized_price.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, _, starting_indexes, exit| {
|
||||
vec.compute_divide(
|
||||
starting_indexes.height,
|
||||
self.height_to_realized_cap.as_ref().unwrap(),
|
||||
&**self.indexes_to_supply.bitcoin.height.as_ref().unwrap(),
|
||||
exit,
|
||||
)
|
||||
},
|
||||
)?;
|
||||
}
|
||||
|
||||
if let Some(indexes_to_realized_price_extra) = self.indexes_to_realized_price_extra.as_mut()
|
||||
{
|
||||
indexes_to_realized_price_extra.compute_rest(
|
||||
indexer,
|
||||
indexes,
|
||||
fetched.as_ref().unwrap(),
|
||||
starting_indexes,
|
||||
exit,
|
||||
Some(
|
||||
self.indexes_to_realized_price
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.dateindex
|
||||
.unwrap_last(),
|
||||
),
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -242,6 +322,12 @@ impl Vecs {
|
||||
self.indexes_to_realized_cap
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.indexes_to_realized_price
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
self.indexes_to_realized_price_extra
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.vecs()),
|
||||
]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
@@ -261,6 +347,9 @@ impl Clone for Vecs {
|
||||
indexes_to_supply: self.indexes_to_supply.clone(),
|
||||
height_to_utxo_count: self.height_to_utxo_count.clone(),
|
||||
indexes_to_utxo_count: self.indexes_to_utxo_count.clone(),
|
||||
|
||||
indexes_to_realized_price: self.indexes_to_realized_price.clone(),
|
||||
indexes_to_realized_price_extra: self.indexes_to_realized_price_extra.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user