mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-19 15:08:12 -07:00
global: move addressindex_to_outputindex stores from computer to indexer
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
use super::{GroupFilter, GroupedByFromSize, GroupedBySizeRange, GroupedByUpToSize};
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct AddressGroups<T> {
|
||||
pub by_from_size: GroupedByFromSize<T>,
|
||||
pub by_size_range: GroupedBySizeRange<T>,
|
||||
pub by_up_to_size: GroupedByUpToSize<T>,
|
||||
}
|
||||
|
||||
impl<T> AddressGroups<T> {
|
||||
pub fn as_mut_vecs(&mut self) -> Vec<&mut T> {
|
||||
self.by_from_size
|
||||
.as_mut_vec()
|
||||
.into_iter()
|
||||
.chain(self.by_size_range.as_mut_vec())
|
||||
.chain(self.by_up_to_size.as_mut_vec())
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
pub fn as_mut_separate_vecs(&mut self) -> Vec<&mut T> {
|
||||
self.by_size_range
|
||||
.as_mut_vec()
|
||||
.into_iter()
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
pub fn as_mut_overlapping_vecs(&mut self) -> Vec<&mut T> {
|
||||
self.by_up_to_size
|
||||
.as_mut_vec()
|
||||
.into_iter()
|
||||
.chain(self.by_from_size.as_mut_vec())
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AddressGroups<(GroupFilter, T)> {
|
||||
pub fn vecs(&self) -> Vec<&T> {
|
||||
self.by_size_range
|
||||
.vecs()
|
||||
.into_iter()
|
||||
.chain(self.by_up_to_size.vecs())
|
||||
.chain(self.by_from_size.vecs())
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<AddressGroups<T>> for AddressGroups<(GroupFilter, T)> {
|
||||
fn from(value: AddressGroups<T>) -> Self {
|
||||
Self {
|
||||
by_size_range: GroupedBySizeRange::from(value.by_size_range),
|
||||
by_up_to_size: GroupedByUpToSize::from(value.by_up_to_size),
|
||||
by_from_size: GroupedByFromSize::from(value.by_from_size),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,243 +0,0 @@
|
||||
use std::{
|
||||
mem,
|
||||
ops::{Add, AddAssign},
|
||||
};
|
||||
|
||||
use brk_core::{Height, OutputType, Result, StoredUsize};
|
||||
use brk_exit::Exit;
|
||||
use brk_vec::{EagerVec, VecIterator};
|
||||
|
||||
use super::GroupFilter;
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct GroupedByAddressType<T> {
|
||||
pub p2pk65: T,
|
||||
pub p2pk33: T,
|
||||
pub p2pkh: T,
|
||||
pub p2sh: T,
|
||||
pub p2wpkh: T,
|
||||
pub p2wsh: T,
|
||||
pub p2tr: T,
|
||||
pub p2a: T,
|
||||
}
|
||||
|
||||
impl<T> GroupedByAddressType<T> {
|
||||
pub fn get(&self, address_type: OutputType) -> Option<&T> {
|
||||
match address_type {
|
||||
OutputType::P2PK65 => Some(&self.p2pk65),
|
||||
OutputType::P2PK33 => Some(&self.p2pk33),
|
||||
OutputType::P2PKH => Some(&self.p2pkh),
|
||||
OutputType::P2SH => Some(&self.p2sh),
|
||||
OutputType::P2WPKH => Some(&self.p2wpkh),
|
||||
OutputType::P2WSH => Some(&self.p2wsh),
|
||||
OutputType::P2TR => Some(&self.p2tr),
|
||||
OutputType::P2A => Some(&self.p2a),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, address_type: OutputType) -> Option<&mut T> {
|
||||
match address_type {
|
||||
OutputType::P2PK65 => Some(&mut self.p2pk65),
|
||||
OutputType::P2PK33 => Some(&mut self.p2pk33),
|
||||
OutputType::P2PKH => Some(&mut self.p2pkh),
|
||||
OutputType::P2SH => Some(&mut self.p2sh),
|
||||
OutputType::P2WPKH => Some(&mut self.p2wpkh),
|
||||
OutputType::P2WSH => Some(&mut self.p2wsh),
|
||||
OutputType::P2TR => Some(&mut self.p2tr),
|
||||
OutputType::P2A => Some(&mut self.p2a),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_mut_vec(&mut self) -> [&mut T; 8] {
|
||||
[
|
||||
&mut self.p2pk65,
|
||||
&mut self.p2pk33,
|
||||
&mut self.p2pkh,
|
||||
&mut self.p2sh,
|
||||
&mut self.p2wpkh,
|
||||
&mut self.p2wsh,
|
||||
&mut self.p2tr,
|
||||
&mut self.p2a,
|
||||
]
|
||||
}
|
||||
|
||||
pub fn as_typed_vec(&self) -> [(OutputType, &T); 8] {
|
||||
[
|
||||
(OutputType::P2PK65, &self.p2pk65),
|
||||
(OutputType::P2PK33, &self.p2pk33),
|
||||
(OutputType::P2PKH, &self.p2pkh),
|
||||
(OutputType::P2SH, &self.p2sh),
|
||||
(OutputType::P2WPKH, &self.p2wpkh),
|
||||
(OutputType::P2WSH, &self.p2wsh),
|
||||
(OutputType::P2TR, &self.p2tr),
|
||||
(OutputType::P2A, &self.p2a),
|
||||
]
|
||||
}
|
||||
|
||||
pub fn as_mut_typed_vec(&mut self) -> [(OutputType, &mut T); 8] {
|
||||
[
|
||||
(OutputType::P2PK65, &mut self.p2pk65),
|
||||
(OutputType::P2PK33, &mut self.p2pk33),
|
||||
(OutputType::P2PKH, &mut self.p2pkh),
|
||||
(OutputType::P2SH, &mut self.p2sh),
|
||||
(OutputType::P2WPKH, &mut self.p2wpkh),
|
||||
(OutputType::P2WSH, &mut self.p2wsh),
|
||||
(OutputType::P2TR, &mut self.p2tr),
|
||||
(OutputType::P2A, &mut self.p2a),
|
||||
]
|
||||
}
|
||||
|
||||
pub fn into_typed_vec(&mut self) -> [(OutputType, T); 8]
|
||||
where
|
||||
T: Default,
|
||||
{
|
||||
[
|
||||
(OutputType::P2PK65, mem::take(&mut self.p2pk65)),
|
||||
(OutputType::P2PK33, mem::take(&mut self.p2pk33)),
|
||||
(OutputType::P2PKH, mem::take(&mut self.p2pkh)),
|
||||
(OutputType::P2SH, mem::take(&mut self.p2sh)),
|
||||
(OutputType::P2WPKH, mem::take(&mut self.p2wpkh)),
|
||||
(OutputType::P2WSH, mem::take(&mut self.p2wsh)),
|
||||
(OutputType::P2TR, mem::take(&mut self.p2tr)),
|
||||
(OutputType::P2A, mem::take(&mut self.p2a)),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> GroupedByAddressType<(GroupFilter, T)> {
|
||||
pub fn vecs(&self) -> [&T; 8] {
|
||||
[
|
||||
&self.p2pk65.1,
|
||||
&self.p2pk33.1,
|
||||
&self.p2pkh.1,
|
||||
&self.p2sh.1,
|
||||
&self.p2wpkh.1,
|
||||
&self.p2wsh.1,
|
||||
&self.p2tr.1,
|
||||
&self.p2a.1,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<GroupedByAddressType<T>> for GroupedByAddressType<(GroupFilter, T)> {
|
||||
fn from(value: GroupedByAddressType<T>) -> Self {
|
||||
Self {
|
||||
p2pk65: (GroupFilter::Type(OutputType::P2PK65), value.p2pk65),
|
||||
p2pk33: (GroupFilter::Type(OutputType::P2PK33), value.p2pk33),
|
||||
p2pkh: (GroupFilter::Type(OutputType::P2PKH), value.p2pkh),
|
||||
p2sh: (GroupFilter::Type(OutputType::P2SH), value.p2sh),
|
||||
p2wpkh: (GroupFilter::Type(OutputType::P2WPKH), value.p2wpkh),
|
||||
p2wsh: (GroupFilter::Type(OutputType::P2WSH), value.p2wsh),
|
||||
p2tr: (GroupFilter::Type(OutputType::P2TR), value.p2tr),
|
||||
p2a: (GroupFilter::Type(OutputType::P2A), value.p2a),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Add for GroupedByAddressType<T>
|
||||
where
|
||||
T: Add<Output = T>,
|
||||
{
|
||||
type Output = Self;
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self {
|
||||
p2pk65: self.p2pk65 + rhs.p2pk65,
|
||||
p2pk33: self.p2pk33 + rhs.p2pk33,
|
||||
p2pkh: self.p2pkh + rhs.p2pkh,
|
||||
p2sh: self.p2sh + rhs.p2sh,
|
||||
p2wpkh: self.p2wpkh + rhs.p2wpkh,
|
||||
p2wsh: self.p2wsh + rhs.p2wsh,
|
||||
p2tr: self.p2tr + rhs.p2tr,
|
||||
p2a: self.p2a + rhs.p2a,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AddAssign for GroupedByAddressType<T>
|
||||
where
|
||||
T: AddAssign,
|
||||
{
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
self.p2pk65 += rhs.p2pk65;
|
||||
self.p2pk33 += rhs.p2pk33;
|
||||
self.p2pkh += rhs.p2pkh;
|
||||
self.p2sh += rhs.p2sh;
|
||||
self.p2wpkh += rhs.p2wpkh;
|
||||
self.p2wsh += rhs.p2wsh;
|
||||
self.p2tr += rhs.p2tr;
|
||||
self.p2a += rhs.p2a;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(&GroupedByAddressType<EagerVec<Height, StoredUsize>>, Height)>
|
||||
for GroupedByAddressType<usize>
|
||||
{
|
||||
fn from(
|
||||
(groups, starting_height): (&GroupedByAddressType<EagerVec<Height, StoredUsize>>, Height),
|
||||
) -> Self {
|
||||
if let Some(prev_height) = starting_height.decremented() {
|
||||
Self {
|
||||
p2pk65: groups
|
||||
.p2pk65
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height)
|
||||
.into(),
|
||||
p2pk33: groups
|
||||
.p2pk33
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height)
|
||||
.into(),
|
||||
p2pkh: groups
|
||||
.p2pkh
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height)
|
||||
.into(),
|
||||
p2sh: groups.p2sh.into_iter().unwrap_get_inner(prev_height).into(),
|
||||
p2wpkh: groups
|
||||
.p2wpkh
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height)
|
||||
.into(),
|
||||
p2wsh: groups
|
||||
.p2wsh
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height)
|
||||
.into(),
|
||||
p2tr: groups.p2tr.into_iter().unwrap_get_inner(prev_height).into(),
|
||||
p2a: groups.p2a.into_iter().unwrap_get_inner(prev_height).into(),
|
||||
}
|
||||
} else {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GroupedByAddressType<EagerVec<Height, StoredUsize>> {
|
||||
pub fn forced_push_at(
|
||||
&mut self,
|
||||
height: Height,
|
||||
addresstype_to_usize: &GroupedByAddressType<usize>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.p2pk65
|
||||
.forced_push_at(height, addresstype_to_usize.p2pk65.into(), exit)?;
|
||||
self.p2pk33
|
||||
.forced_push_at(height, addresstype_to_usize.p2pk33.into(), exit)?;
|
||||
self.p2pkh
|
||||
.forced_push_at(height, addresstype_to_usize.p2pkh.into(), exit)?;
|
||||
self.p2sh
|
||||
.forced_push_at(height, addresstype_to_usize.p2sh.into(), exit)?;
|
||||
self.p2wpkh
|
||||
.forced_push_at(height, addresstype_to_usize.p2wpkh.into(), exit)?;
|
||||
self.p2wsh
|
||||
.forced_push_at(height, addresstype_to_usize.p2wsh.into(), exit)?;
|
||||
self.p2tr
|
||||
.forced_push_at(height, addresstype_to_usize.p2tr.into(), exit)?;
|
||||
self.p2a
|
||||
.forced_push_at(height, addresstype_to_usize.p2a.into(), exit)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
use super::GroupFilter;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct GroupedByDateRange<T> {
|
||||
pub start_to_1d: T,
|
||||
pub _1d_to_1w: T,
|
||||
pub _1w_to_1m: T,
|
||||
pub _1m_to_2m: T,
|
||||
pub _2m_to_3m: T,
|
||||
pub _3m_to_4m: T,
|
||||
pub _4m_to_5m: T,
|
||||
pub _5m_to_6m: T,
|
||||
pub _6m_to_1y: T,
|
||||
pub _1y_to_2y: T,
|
||||
pub _2y_to_3y: T,
|
||||
pub _3y_to_4y: T,
|
||||
pub _4y_to_5y: T,
|
||||
pub _5y_to_6y: T,
|
||||
pub _6y_to_7y: T,
|
||||
pub _7y_to_8y: T,
|
||||
pub _8y_to_10y: T,
|
||||
pub _10y_to_15y: T,
|
||||
pub _15y_to_end: T,
|
||||
}
|
||||
|
||||
impl<T> From<GroupedByDateRange<T>> for GroupedByDateRange<(GroupFilter, T)> {
|
||||
fn from(value: GroupedByDateRange<T>) -> Self {
|
||||
Self {
|
||||
start_to_1d: (GroupFilter::To(1), value.start_to_1d),
|
||||
_1d_to_1w: (GroupFilter::Range(1..7), value._1d_to_1w),
|
||||
_1w_to_1m: (GroupFilter::Range(7..30), value._1w_to_1m),
|
||||
_1m_to_2m: (GroupFilter::Range(30..2 * 30), value._1m_to_2m),
|
||||
_2m_to_3m: (GroupFilter::Range(2 * 30..3 * 30), value._2m_to_3m),
|
||||
_3m_to_4m: (GroupFilter::Range(3 * 30..4 * 30), value._3m_to_4m),
|
||||
_4m_to_5m: (GroupFilter::Range(4 * 30..5 * 30), value._4m_to_5m),
|
||||
_5m_to_6m: (GroupFilter::Range(5 * 30..6 * 30), value._5m_to_6m),
|
||||
_6m_to_1y: (GroupFilter::Range(6 * 30..365), value._6m_to_1y),
|
||||
_1y_to_2y: (GroupFilter::Range(365..2 * 365), value._1y_to_2y),
|
||||
_2y_to_3y: (GroupFilter::Range(2 * 365..3 * 365), value._2y_to_3y),
|
||||
_3y_to_4y: (GroupFilter::Range(3 * 365..4 * 365), value._3y_to_4y),
|
||||
_4y_to_5y: (GroupFilter::Range(4 * 365..5 * 365), value._4y_to_5y),
|
||||
_5y_to_6y: (GroupFilter::Range(5 * 365..6 * 365), value._5y_to_6y),
|
||||
_6y_to_7y: (GroupFilter::Range(6 * 365..7 * 365), value._6y_to_7y),
|
||||
_7y_to_8y: (GroupFilter::Range(7 * 365..8 * 365), value._7y_to_8y),
|
||||
_8y_to_10y: (GroupFilter::Range(8 * 365..10 * 365), value._8y_to_10y),
|
||||
_10y_to_15y: (GroupFilter::Range(10 * 365..15 * 365), value._10y_to_15y),
|
||||
_15y_to_end: (GroupFilter::From(15 * 365), value._15y_to_end),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> GroupedByDateRange<T> {
|
||||
pub fn as_vec(&mut self) -> [&T; 19] {
|
||||
[
|
||||
&self.start_to_1d,
|
||||
&self._1d_to_1w,
|
||||
&self._1w_to_1m,
|
||||
&self._1m_to_2m,
|
||||
&self._2m_to_3m,
|
||||
&self._3m_to_4m,
|
||||
&self._4m_to_5m,
|
||||
&self._5m_to_6m,
|
||||
&self._6m_to_1y,
|
||||
&self._1y_to_2y,
|
||||
&self._2y_to_3y,
|
||||
&self._3y_to_4y,
|
||||
&self._4y_to_5y,
|
||||
&self._5y_to_6y,
|
||||
&self._6y_to_7y,
|
||||
&self._7y_to_8y,
|
||||
&self._8y_to_10y,
|
||||
&self._10y_to_15y,
|
||||
&self._15y_to_end,
|
||||
]
|
||||
}
|
||||
|
||||
pub fn as_mut_vec(&mut self) -> [&mut T; 19] {
|
||||
[
|
||||
&mut self.start_to_1d,
|
||||
&mut self._1d_to_1w,
|
||||
&mut self._1w_to_1m,
|
||||
&mut self._1m_to_2m,
|
||||
&mut self._2m_to_3m,
|
||||
&mut self._3m_to_4m,
|
||||
&mut self._4m_to_5m,
|
||||
&mut self._5m_to_6m,
|
||||
&mut self._6m_to_1y,
|
||||
&mut self._1y_to_2y,
|
||||
&mut self._2y_to_3y,
|
||||
&mut self._3y_to_4y,
|
||||
&mut self._4y_to_5y,
|
||||
&mut self._5y_to_6y,
|
||||
&mut self._6y_to_7y,
|
||||
&mut self._7y_to_8y,
|
||||
&mut self._8y_to_10y,
|
||||
&mut self._10y_to_15y,
|
||||
&mut self._15y_to_end,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> GroupedByDateRange<(GroupFilter, T)> {
|
||||
pub fn vecs(&self) -> [&T; 19] {
|
||||
[
|
||||
&self.start_to_1d.1,
|
||||
&self._1d_to_1w.1,
|
||||
&self._1w_to_1m.1,
|
||||
&self._1m_to_2m.1,
|
||||
&self._2m_to_3m.1,
|
||||
&self._3m_to_4m.1,
|
||||
&self._4m_to_5m.1,
|
||||
&self._5m_to_6m.1,
|
||||
&self._6m_to_1y.1,
|
||||
&self._1y_to_2y.1,
|
||||
&self._2y_to_3y.1,
|
||||
&self._3y_to_4y.1,
|
||||
&self._4y_to_5y.1,
|
||||
&self._5y_to_6y.1,
|
||||
&self._6y_to_7y.1,
|
||||
&self._7y_to_8y.1,
|
||||
&self._8y_to_10y.1,
|
||||
&self._10y_to_15y.1,
|
||||
&self._15y_to_end.1,
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
use brk_core::{HalvingEpoch, Height};
|
||||
|
||||
use super::GroupFilter;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct GroupedByEpoch<T> {
|
||||
pub _0: T,
|
||||
pub _1: T,
|
||||
pub _2: T,
|
||||
pub _3: T,
|
||||
pub _4: T,
|
||||
}
|
||||
|
||||
impl<T> From<GroupedByEpoch<T>> for GroupedByEpoch<(GroupFilter, T)> {
|
||||
fn from(value: GroupedByEpoch<T>) -> Self {
|
||||
Self {
|
||||
_0: (GroupFilter::Epoch(HalvingEpoch::new(0)), value._0),
|
||||
_1: (GroupFilter::Epoch(HalvingEpoch::new(1)), value._1),
|
||||
_2: (GroupFilter::Epoch(HalvingEpoch::new(2)), value._2),
|
||||
_3: (GroupFilter::Epoch(HalvingEpoch::new(3)), value._3),
|
||||
_4: (GroupFilter::Epoch(HalvingEpoch::new(4)), value._4),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> GroupedByEpoch<T> {
|
||||
pub fn as_mut_vec(&mut self) -> [&mut T; 5] {
|
||||
[
|
||||
&mut self._0,
|
||||
&mut self._1,
|
||||
&mut self._2,
|
||||
&mut self._3,
|
||||
&mut self._4,
|
||||
]
|
||||
}
|
||||
|
||||
pub fn mut_vec_from_height(&mut self, height: Height) -> &mut T {
|
||||
let epoch = HalvingEpoch::from(height);
|
||||
if epoch == HalvingEpoch::new(0) {
|
||||
&mut self._0
|
||||
} else if epoch == HalvingEpoch::new(1) {
|
||||
&mut self._1
|
||||
} else if epoch == HalvingEpoch::new(2) {
|
||||
&mut self._2
|
||||
} else if epoch == HalvingEpoch::new(3) {
|
||||
&mut self._3
|
||||
} else if epoch == HalvingEpoch::new(4) {
|
||||
&mut self._4
|
||||
} else {
|
||||
todo!("")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> GroupedByEpoch<(GroupFilter, T)> {
|
||||
pub fn vecs(&self) -> [&T; 5] {
|
||||
[&self._0.1, &self._1.1, &self._2.1, &self._3.1, &self._4.1]
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
use super::GroupFilter;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct GroupedByFromDate<T> {
|
||||
pub _1d: T,
|
||||
pub _1w: T,
|
||||
pub _1m: T,
|
||||
pub _2m: T,
|
||||
pub _3m: T,
|
||||
pub _4m: T,
|
||||
pub _5m: T,
|
||||
pub _6m: T,
|
||||
pub _1y: T,
|
||||
pub _2y: T,
|
||||
pub _3y: T,
|
||||
pub _4y: T,
|
||||
pub _5y: T,
|
||||
pub _6y: T,
|
||||
pub _7y: T,
|
||||
pub _8y: T,
|
||||
pub _10y: T,
|
||||
pub _15y: T,
|
||||
}
|
||||
|
||||
impl<T> GroupedByFromDate<T> {
|
||||
pub fn as_mut_vec(&mut self) -> [&mut T; 18] {
|
||||
[
|
||||
&mut self._1d,
|
||||
&mut self._1w,
|
||||
&mut self._1m,
|
||||
&mut self._2m,
|
||||
&mut self._3m,
|
||||
&mut self._4m,
|
||||
&mut self._5m,
|
||||
&mut self._6m,
|
||||
&mut self._1y,
|
||||
&mut self._2y,
|
||||
&mut self._3y,
|
||||
&mut self._4y,
|
||||
&mut self._5y,
|
||||
&mut self._6y,
|
||||
&mut self._7y,
|
||||
&mut self._8y,
|
||||
&mut self._10y,
|
||||
&mut self._15y,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> GroupedByFromDate<(GroupFilter, T)> {
|
||||
pub fn vecs(&self) -> [&T; 18] {
|
||||
[
|
||||
&self._1d.1,
|
||||
&self._1w.1,
|
||||
&self._1m.1,
|
||||
&self._2m.1,
|
||||
&self._3m.1,
|
||||
&self._4m.1,
|
||||
&self._5m.1,
|
||||
&self._6m.1,
|
||||
&self._1y.1,
|
||||
&self._2y.1,
|
||||
&self._3y.1,
|
||||
&self._4y.1,
|
||||
&self._5y.1,
|
||||
&self._6y.1,
|
||||
&self._7y.1,
|
||||
&self._8y.1,
|
||||
&self._10y.1,
|
||||
&self._15y.1,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<GroupedByFromDate<T>> for GroupedByFromDate<(GroupFilter, T)> {
|
||||
fn from(value: GroupedByFromDate<T>) -> Self {
|
||||
Self {
|
||||
_1d: (GroupFilter::From(1), value._1d),
|
||||
_1w: (GroupFilter::From(7), value._1w),
|
||||
_1m: (GroupFilter::From(30), value._1m),
|
||||
_2m: (GroupFilter::From(2 * 30), value._2m),
|
||||
_3m: (GroupFilter::From(3 * 30), value._3m),
|
||||
_4m: (GroupFilter::From(4 * 30), value._4m),
|
||||
_5m: (GroupFilter::From(5 * 30), value._5m),
|
||||
_6m: (GroupFilter::From(6 * 30), value._6m),
|
||||
_1y: (GroupFilter::From(365), value._1y),
|
||||
_2y: (GroupFilter::From(2 * 365), value._2y),
|
||||
_3y: (GroupFilter::From(3 * 365), value._3y),
|
||||
_4y: (GroupFilter::From(4 * 365), value._4y),
|
||||
_5y: (GroupFilter::From(5 * 365), value._5y),
|
||||
_6y: (GroupFilter::From(6 * 365), value._6y),
|
||||
_7y: (GroupFilter::From(7 * 365), value._7y),
|
||||
_8y: (GroupFilter::From(8 * 365), value._8y),
|
||||
_10y: (GroupFilter::From(10 * 365), value._10y),
|
||||
_15y: (GroupFilter::From(15 * 365), value._15y),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
use brk_core::Sats;
|
||||
|
||||
use super::GroupFilter;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct GroupedByFromSize<T> {
|
||||
pub _1_000sats: T,
|
||||
pub _1btc: T,
|
||||
pub _10btc: T,
|
||||
pub _100btc: T,
|
||||
}
|
||||
|
||||
impl<T> GroupedByFromSize<T> {
|
||||
pub fn as_mut_vec(&mut self) -> [&mut T; 4] {
|
||||
[
|
||||
&mut self._1_000sats,
|
||||
&mut self._1btc,
|
||||
&mut self._10btc,
|
||||
&mut self._100btc,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> GroupedByFromSize<(GroupFilter, T)> {
|
||||
pub fn vecs(&self) -> [&T; 4] {
|
||||
[
|
||||
&self._1_000sats.1,
|
||||
&self._1btc.1,
|
||||
&self._10btc.1,
|
||||
&self._100btc.1,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<GroupedByFromSize<T>> for GroupedByFromSize<(GroupFilter, T)> {
|
||||
fn from(value: GroupedByFromSize<T>) -> Self {
|
||||
Self {
|
||||
_1_000sats: (GroupFilter::From(1_000), value._1_000sats),
|
||||
_1btc: (GroupFilter::From(usize::from(Sats::ONE_BTC)), value._1btc),
|
||||
_10btc: (
|
||||
GroupFilter::From(usize::from(10 * Sats::ONE_BTC)),
|
||||
value._10btc,
|
||||
),
|
||||
_100btc: (
|
||||
GroupFilter::From(usize::from(100 * Sats::ONE_BTC)),
|
||||
value._100btc,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,256 +0,0 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
use brk_core::Sats;
|
||||
|
||||
use super::GroupFilter;
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct GroupedBySizeRange<T> {
|
||||
pub _0sats: T,
|
||||
pub from_1sat_to_10sats: T,
|
||||
pub from_10sats_to_100sats: T,
|
||||
pub from_100sats_to_1_000sats: T,
|
||||
pub from_1_000sats_to_10_000sats: T,
|
||||
pub from_10_000sats_to_100_000sats: T,
|
||||
pub from_100_000sats_to_1_000_000sats: T,
|
||||
pub from_1_000_000sats_to_10_000_000sats: T,
|
||||
pub from_10_000_000sats_to_1btc: T,
|
||||
pub from_1btc_to_10btc: T,
|
||||
pub from_10btc_to_100btc: T,
|
||||
pub from_100btc_to_1_000btc: T,
|
||||
pub from_1_000btc_to_10_000btc: T,
|
||||
pub from_10_000btc_to_100_000btc: T,
|
||||
pub from_100_000btc: T,
|
||||
}
|
||||
|
||||
impl<T> From<GroupedBySizeRange<T>> for GroupedBySizeRange<(GroupFilter, T)> {
|
||||
fn from(value: GroupedBySizeRange<T>) -> Self {
|
||||
#[allow(clippy::inconsistent_digit_grouping)]
|
||||
Self {
|
||||
_0sats: (GroupFilter::To(1), value._0sats),
|
||||
from_1sat_to_10sats: (GroupFilter::Range(1..10), value.from_1sat_to_10sats),
|
||||
from_10sats_to_100sats: (GroupFilter::Range(10..100), value.from_10sats_to_100sats),
|
||||
from_100sats_to_1_000sats: (
|
||||
GroupFilter::Range(100..1_000),
|
||||
value.from_100sats_to_1_000sats,
|
||||
),
|
||||
from_1_000sats_to_10_000sats: (
|
||||
GroupFilter::Range(1_000..10_000),
|
||||
value.from_1_000sats_to_10_000sats,
|
||||
),
|
||||
from_10_000sats_to_100_000sats: (
|
||||
GroupFilter::Range(10_000..100_000),
|
||||
value.from_10_000sats_to_100_000sats,
|
||||
),
|
||||
from_100_000sats_to_1_000_000sats: (
|
||||
GroupFilter::Range(100_000..1_000_000),
|
||||
value.from_100_000sats_to_1_000_000sats,
|
||||
),
|
||||
from_1_000_000sats_to_10_000_000sats: (
|
||||
GroupFilter::Range(1_000_000..10_000_000),
|
||||
value.from_1_000_000sats_to_10_000_000sats,
|
||||
),
|
||||
from_10_000_000sats_to_1btc: (
|
||||
GroupFilter::Range(10_000_000..1_00_000_000),
|
||||
value.from_10_000_000sats_to_1btc,
|
||||
),
|
||||
from_1btc_to_10btc: (
|
||||
GroupFilter::Range(1_00_000_000..10_00_000_000),
|
||||
value.from_1btc_to_10btc,
|
||||
),
|
||||
from_10btc_to_100btc: (
|
||||
GroupFilter::Range(10_00_000_000..100_00_000_000),
|
||||
value.from_10btc_to_100btc,
|
||||
),
|
||||
from_100btc_to_1_000btc: (
|
||||
GroupFilter::Range(100_00_000_000..1_000_00_000_000),
|
||||
value.from_100btc_to_1_000btc,
|
||||
),
|
||||
from_1_000btc_to_10_000btc: (
|
||||
GroupFilter::Range(1_000_00_000_000..10_000_00_000_000),
|
||||
value.from_1_000btc_to_10_000btc,
|
||||
),
|
||||
from_10_000btc_to_100_000btc: (
|
||||
GroupFilter::Range(10_000_00_000_000..100_000_00_000_000),
|
||||
value.from_10_000btc_to_100_000btc,
|
||||
),
|
||||
from_100_000btc: (GroupFilter::From(100_000_00_000_000), value.from_100_000btc),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> GroupedBySizeRange<T> {
|
||||
#[allow(clippy::inconsistent_digit_grouping)]
|
||||
pub fn get_mut(&mut self, value: Sats) -> &mut T {
|
||||
if value == Sats::ZERO {
|
||||
&mut self._0sats
|
||||
} else if value < Sats::_10 {
|
||||
&mut self.from_1sat_to_10sats
|
||||
} else if value < Sats::_100 {
|
||||
&mut self.from_10sats_to_100sats
|
||||
} else if value < Sats::_1K {
|
||||
&mut self.from_100sats_to_1_000sats
|
||||
} else if value < Sats::_10K {
|
||||
&mut self.from_1_000sats_to_10_000sats
|
||||
} else if value < Sats::_100K {
|
||||
&mut self.from_10_000sats_to_100_000sats
|
||||
} else if value < Sats::_1M {
|
||||
&mut self.from_100_000sats_to_1_000_000sats
|
||||
} else if value < Sats::_10M {
|
||||
&mut self.from_1_000_000sats_to_10_000_000sats
|
||||
} else if value < Sats::_1_BTC {
|
||||
&mut self.from_10_000_000sats_to_1btc
|
||||
} else if value < Sats::_10_BTC {
|
||||
&mut self.from_1btc_to_10btc
|
||||
} else if value < Sats::_100_BTC {
|
||||
&mut self.from_10btc_to_100btc
|
||||
} else if value < Sats::_1K_BTC {
|
||||
&mut self.from_100btc_to_1_000btc
|
||||
} else if value < Sats::_10K_BTC {
|
||||
&mut self.from_1_000btc_to_10_000btc
|
||||
} else if value < Sats::_100K_BTC {
|
||||
&mut self.from_10_000btc_to_100_000btc
|
||||
} else {
|
||||
&mut self.from_100_000btc
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_vec(&self) -> [&T; 15] {
|
||||
[
|
||||
&self._0sats,
|
||||
&self.from_1sat_to_10sats,
|
||||
&self.from_10sats_to_100sats,
|
||||
&self.from_100sats_to_1_000sats,
|
||||
&self.from_1_000sats_to_10_000sats,
|
||||
&self.from_10_000sats_to_100_000sats,
|
||||
&self.from_100_000sats_to_1_000_000sats,
|
||||
&self.from_1_000_000sats_to_10_000_000sats,
|
||||
&self.from_10_000_000sats_to_1btc,
|
||||
&self.from_1btc_to_10btc,
|
||||
&self.from_10btc_to_100btc,
|
||||
&self.from_100btc_to_1_000btc,
|
||||
&self.from_1_000btc_to_10_000btc,
|
||||
&self.from_10_000btc_to_100_000btc,
|
||||
&self.from_100_000btc,
|
||||
]
|
||||
}
|
||||
|
||||
pub fn as_typed_vec(&self) -> [(Sats, &T); 15] {
|
||||
[
|
||||
(Sats::ZERO, &self._0sats),
|
||||
(Sats::_1, &self.from_1sat_to_10sats),
|
||||
(Sats::_10, &self.from_10sats_to_100sats),
|
||||
(Sats::_100, &self.from_100sats_to_1_000sats),
|
||||
(Sats::_1K, &self.from_1_000sats_to_10_000sats),
|
||||
(Sats::_10K, &self.from_10_000sats_to_100_000sats),
|
||||
(Sats::_100K, &self.from_100_000sats_to_1_000_000sats),
|
||||
(Sats::_1M, &self.from_1_000_000sats_to_10_000_000sats),
|
||||
(Sats::_10M, &self.from_10_000_000sats_to_1btc),
|
||||
(Sats::_1_BTC, &self.from_1btc_to_10btc),
|
||||
(Sats::_10_BTC, &self.from_10btc_to_100btc),
|
||||
(Sats::_100_BTC, &self.from_100btc_to_1_000btc),
|
||||
(Sats::_1K_BTC, &self.from_1_000btc_to_10_000btc),
|
||||
(Sats::_10K_BTC, &self.from_10_000btc_to_100_000btc),
|
||||
(Sats::_100K_BTC, &self.from_100_000btc),
|
||||
]
|
||||
}
|
||||
|
||||
pub fn as_mut_vec(&mut self) -> [&mut T; 15] {
|
||||
[
|
||||
&mut self._0sats,
|
||||
&mut self.from_1sat_to_10sats,
|
||||
&mut self.from_10sats_to_100sats,
|
||||
&mut self.from_100sats_to_1_000sats,
|
||||
&mut self.from_1_000sats_to_10_000sats,
|
||||
&mut self.from_10_000sats_to_100_000sats,
|
||||
&mut self.from_100_000sats_to_1_000_000sats,
|
||||
&mut self.from_1_000_000sats_to_10_000_000sats,
|
||||
&mut self.from_10_000_000sats_to_1btc,
|
||||
&mut self.from_1btc_to_10btc,
|
||||
&mut self.from_10btc_to_100btc,
|
||||
&mut self.from_100btc_to_1_000btc,
|
||||
&mut self.from_1_000btc_to_10_000btc,
|
||||
&mut self.from_10_000btc_to_100_000btc,
|
||||
&mut self.from_100_000btc,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> GroupedBySizeRange<(GroupFilter, T)> {
|
||||
pub fn vecs(&self) -> [&T; 15] {
|
||||
[
|
||||
&self._0sats.1,
|
||||
&self.from_1sat_to_10sats.1,
|
||||
&self.from_10sats_to_100sats.1,
|
||||
&self.from_100sats_to_1_000sats.1,
|
||||
&self.from_1_000sats_to_10_000sats.1,
|
||||
&self.from_10_000sats_to_100_000sats.1,
|
||||
&self.from_100_000sats_to_1_000_000sats.1,
|
||||
&self.from_1_000_000sats_to_10_000_000sats.1,
|
||||
&self.from_10_000_000sats_to_1btc.1,
|
||||
&self.from_1btc_to_10btc.1,
|
||||
&self.from_10btc_to_100btc.1,
|
||||
&self.from_100btc_to_1_000btc.1,
|
||||
&self.from_1_000btc_to_10_000btc.1,
|
||||
&self.from_10_000btc_to_100_000btc.1,
|
||||
&self.from_100_000btc.1,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Add for GroupedBySizeRange<T>
|
||||
where
|
||||
T: Add<Output = T>,
|
||||
{
|
||||
type Output = Self;
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self {
|
||||
_0sats: self._0sats + rhs._0sats,
|
||||
from_1sat_to_10sats: self.from_1sat_to_10sats + rhs.from_1sat_to_10sats,
|
||||
from_10sats_to_100sats: self.from_10sats_to_100sats + rhs.from_10sats_to_100sats,
|
||||
from_100sats_to_1_000sats: self.from_100sats_to_1_000sats
|
||||
+ rhs.from_100sats_to_1_000sats,
|
||||
from_1_000sats_to_10_000sats: self.from_1_000sats_to_10_000sats
|
||||
+ rhs.from_1_000sats_to_10_000sats,
|
||||
from_10_000sats_to_100_000sats: self.from_10_000sats_to_100_000sats
|
||||
+ rhs.from_10_000sats_to_100_000sats,
|
||||
from_100_000sats_to_1_000_000sats: self.from_100_000sats_to_1_000_000sats
|
||||
+ rhs.from_100_000sats_to_1_000_000sats,
|
||||
from_1_000_000sats_to_10_000_000sats: self.from_1_000_000sats_to_10_000_000sats
|
||||
+ rhs.from_1_000_000sats_to_10_000_000sats,
|
||||
from_10_000_000sats_to_1btc: self.from_10_000_000sats_to_1btc
|
||||
+ rhs.from_10_000_000sats_to_1btc,
|
||||
from_1btc_to_10btc: self.from_1btc_to_10btc + rhs.from_1btc_to_10btc,
|
||||
from_10btc_to_100btc: self.from_10btc_to_100btc + rhs.from_10btc_to_100btc,
|
||||
from_100btc_to_1_000btc: self.from_100btc_to_1_000btc + rhs.from_100btc_to_1_000btc,
|
||||
from_1_000btc_to_10_000btc: self.from_1_000btc_to_10_000btc
|
||||
+ rhs.from_1_000btc_to_10_000btc,
|
||||
from_10_000btc_to_100_000btc: self.from_10_000btc_to_100_000btc
|
||||
+ rhs.from_10_000btc_to_100_000btc,
|
||||
from_100_000btc: self.from_100_000btc + rhs.from_100_000btc,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AddAssign for GroupedBySizeRange<T>
|
||||
where
|
||||
T: AddAssign,
|
||||
{
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
self._0sats += rhs._0sats;
|
||||
self.from_1sat_to_10sats += rhs.from_1sat_to_10sats;
|
||||
self.from_10sats_to_100sats += rhs.from_10sats_to_100sats;
|
||||
self.from_100sats_to_1_000sats += rhs.from_100sats_to_1_000sats;
|
||||
self.from_1_000sats_to_10_000sats += rhs.from_1_000sats_to_10_000sats;
|
||||
self.from_10_000sats_to_100_000sats += rhs.from_10_000sats_to_100_000sats;
|
||||
self.from_100_000sats_to_1_000_000sats += rhs.from_100_000sats_to_1_000_000sats;
|
||||
self.from_1_000_000sats_to_10_000_000sats += rhs.from_1_000_000sats_to_10_000_000sats;
|
||||
self.from_10_000_000sats_to_1btc += rhs.from_10_000_000sats_to_1btc;
|
||||
self.from_1btc_to_10btc += rhs.from_1btc_to_10btc;
|
||||
self.from_10btc_to_100btc += rhs.from_10btc_to_100btc;
|
||||
self.from_100btc_to_1_000btc += rhs.from_100btc_to_1_000btc;
|
||||
self.from_1_000btc_to_10_000btc += rhs.from_1_000btc_to_10_000btc;
|
||||
self.from_10_000btc_to_100_000btc += rhs.from_10_000btc_to_100_000btc;
|
||||
self.from_100_000btc += rhs.from_100_000btc;
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
use brk_core::OutputType;
|
||||
|
||||
use super::GroupFilter;
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct GroupedBySpendableType<T> {
|
||||
pub p2pk65: T,
|
||||
pub p2pk33: T,
|
||||
pub p2pkh: T,
|
||||
pub p2ms: T,
|
||||
pub p2sh: T,
|
||||
pub p2wpkh: T,
|
||||
pub p2wsh: T,
|
||||
pub p2tr: T,
|
||||
pub p2a: T,
|
||||
pub unknown: T,
|
||||
pub empty: T,
|
||||
}
|
||||
|
||||
impl<T> GroupedBySpendableType<T> {
|
||||
pub fn get_mut(&mut self, output_type: OutputType) -> &mut T {
|
||||
match output_type {
|
||||
OutputType::P2PK65 => &mut self.p2pk65,
|
||||
OutputType::P2PK33 => &mut self.p2pk33,
|
||||
OutputType::P2PKH => &mut self.p2pkh,
|
||||
OutputType::P2MS => &mut self.p2ms,
|
||||
OutputType::P2SH => &mut self.p2sh,
|
||||
OutputType::P2WPKH => &mut self.p2wpkh,
|
||||
OutputType::P2WSH => &mut self.p2wsh,
|
||||
OutputType::P2TR => &mut self.p2tr,
|
||||
OutputType::P2A => &mut self.p2a,
|
||||
OutputType::Unknown => &mut self.unknown,
|
||||
OutputType::Empty => &mut self.empty,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_mut_vec(&mut self) -> [&mut T; 11] {
|
||||
[
|
||||
&mut self.p2pk65,
|
||||
&mut self.p2pk33,
|
||||
&mut self.p2pkh,
|
||||
&mut self.p2ms,
|
||||
&mut self.p2sh,
|
||||
&mut self.p2wpkh,
|
||||
&mut self.p2wsh,
|
||||
&mut self.p2tr,
|
||||
&mut self.p2a,
|
||||
&mut self.unknown,
|
||||
&mut self.empty,
|
||||
]
|
||||
}
|
||||
|
||||
pub fn as_typed_vec(&self) -> [(OutputType, &T); 11] {
|
||||
[
|
||||
(OutputType::P2PK65, &self.p2pk65),
|
||||
(OutputType::P2PK33, &self.p2pk33),
|
||||
(OutputType::P2PKH, &self.p2pkh),
|
||||
(OutputType::P2MS, &self.p2ms),
|
||||
(OutputType::P2SH, &self.p2sh),
|
||||
(OutputType::P2WPKH, &self.p2wpkh),
|
||||
(OutputType::P2WSH, &self.p2wsh),
|
||||
(OutputType::P2TR, &self.p2tr),
|
||||
(OutputType::P2A, &self.p2a),
|
||||
(OutputType::Unknown, &self.unknown),
|
||||
(OutputType::Empty, &self.empty),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> GroupedBySpendableType<(GroupFilter, T)> {
|
||||
pub fn vecs(&self) -> [&T; 11] {
|
||||
[
|
||||
&self.p2pk65.1,
|
||||
&self.p2pk33.1,
|
||||
&self.p2pkh.1,
|
||||
&self.p2ms.1,
|
||||
&self.p2sh.1,
|
||||
&self.p2wpkh.1,
|
||||
&self.p2wsh.1,
|
||||
&self.p2tr.1,
|
||||
&self.p2a.1,
|
||||
&self.unknown.1,
|
||||
&self.empty.1,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<GroupedBySpendableType<T>> for GroupedBySpendableType<(GroupFilter, T)> {
|
||||
fn from(value: GroupedBySpendableType<T>) -> Self {
|
||||
Self {
|
||||
p2pk65: (GroupFilter::Type(OutputType::P2PK65), value.p2pk65),
|
||||
p2pk33: (GroupFilter::Type(OutputType::P2PK33), value.p2pk33),
|
||||
p2pkh: (GroupFilter::Type(OutputType::P2PKH), value.p2pkh),
|
||||
p2ms: (GroupFilter::Type(OutputType::P2MS), value.p2ms),
|
||||
p2sh: (GroupFilter::Type(OutputType::P2SH), value.p2sh),
|
||||
p2wpkh: (GroupFilter::Type(OutputType::P2WPKH), value.p2wpkh),
|
||||
p2wsh: (GroupFilter::Type(OutputType::P2WSH), value.p2wsh),
|
||||
p2tr: (GroupFilter::Type(OutputType::P2TR), value.p2tr),
|
||||
p2a: (GroupFilter::Type(OutputType::P2A), value.p2a),
|
||||
unknown: (GroupFilter::Type(OutputType::Unknown), value.unknown),
|
||||
empty: (GroupFilter::Type(OutputType::Empty), value.empty),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Add for GroupedBySpendableType<T>
|
||||
where
|
||||
T: Add<Output = T>,
|
||||
{
|
||||
type Output = Self;
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self {
|
||||
p2pk65: self.p2pk65 + rhs.p2pk65,
|
||||
p2pk33: self.p2pk33 + rhs.p2pk33,
|
||||
p2pkh: self.p2pkh + rhs.p2pkh,
|
||||
p2ms: self.p2ms + rhs.p2ms,
|
||||
p2sh: self.p2sh + rhs.p2sh,
|
||||
p2wpkh: self.p2wpkh + rhs.p2wpkh,
|
||||
p2wsh: self.p2wsh + rhs.p2wsh,
|
||||
p2tr: self.p2tr + rhs.p2tr,
|
||||
p2a: self.p2a + rhs.p2a,
|
||||
unknown: self.unknown + rhs.unknown,
|
||||
empty: self.empty + rhs.empty,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AddAssign for GroupedBySpendableType<T>
|
||||
where
|
||||
T: AddAssign,
|
||||
{
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
self.p2pk65 += rhs.p2pk65;
|
||||
self.p2pk33 += rhs.p2pk33;
|
||||
self.p2pkh += rhs.p2pkh;
|
||||
self.p2ms += rhs.p2ms;
|
||||
self.p2sh += rhs.p2sh;
|
||||
self.p2wpkh += rhs.p2wpkh;
|
||||
self.p2wsh += rhs.p2wsh;
|
||||
self.p2tr += rhs.p2tr;
|
||||
self.p2a += rhs.p2a;
|
||||
self.unknown += rhs.unknown;
|
||||
self.empty += rhs.empty;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
use super::GroupFilter;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct GroupedByTerm<T> {
|
||||
pub short: T,
|
||||
pub long: T,
|
||||
}
|
||||
|
||||
impl<T> GroupedByTerm<T> {
|
||||
pub fn as_mut_vec(&mut self) -> [&mut T; 2] {
|
||||
[&mut self.short, &mut self.long]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> GroupedByTerm<(GroupFilter, T)> {
|
||||
pub fn vecs(&self) -> [&T; 2] {
|
||||
[&self.short.1, &self.long.1]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<GroupedByTerm<T>> for GroupedByTerm<(GroupFilter, T)> {
|
||||
fn from(value: GroupedByTerm<T>) -> Self {
|
||||
Self {
|
||||
short: (GroupFilter::To(5 * 30), value.short),
|
||||
long: (GroupFilter::From(5 * 30), value.long),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
use brk_core::OutputType;
|
||||
|
||||
use super::{GroupedBySpendableType, GroupedByUnspendableType};
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct GroupedByType<T> {
|
||||
pub spendable: GroupedBySpendableType<T>,
|
||||
pub unspendable: GroupedByUnspendableType<T>,
|
||||
}
|
||||
|
||||
impl<T> GroupedByType<T> {
|
||||
pub fn get(&self, output_type: OutputType) -> &T {
|
||||
match output_type {
|
||||
OutputType::P2PK65 => &self.spendable.p2pk65,
|
||||
OutputType::P2PK33 => &self.spendable.p2pk33,
|
||||
OutputType::P2PKH => &self.spendable.p2pkh,
|
||||
OutputType::P2MS => &self.spendable.p2ms,
|
||||
OutputType::P2SH => &self.spendable.p2sh,
|
||||
OutputType::P2WPKH => &self.spendable.p2wpkh,
|
||||
OutputType::P2WSH => &self.spendable.p2wsh,
|
||||
OutputType::P2TR => &self.spendable.p2tr,
|
||||
OutputType::P2A => &self.spendable.p2a,
|
||||
OutputType::Empty => &self.spendable.empty,
|
||||
OutputType::Unknown => &self.spendable.unknown,
|
||||
OutputType::OpReturn => &self.unspendable.opreturn,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, output_type: OutputType) -> &mut T {
|
||||
match output_type {
|
||||
OutputType::P2PK65 => &mut self.spendable.p2pk65,
|
||||
OutputType::P2PK33 => &mut self.spendable.p2pk33,
|
||||
OutputType::P2PKH => &mut self.spendable.p2pkh,
|
||||
OutputType::P2MS => &mut self.spendable.p2ms,
|
||||
OutputType::P2SH => &mut self.spendable.p2sh,
|
||||
OutputType::P2WPKH => &mut self.spendable.p2wpkh,
|
||||
OutputType::P2WSH => &mut self.spendable.p2wsh,
|
||||
OutputType::P2TR => &mut self.spendable.p2tr,
|
||||
OutputType::P2A => &mut self.spendable.p2a,
|
||||
OutputType::Unknown => &mut self.spendable.unknown,
|
||||
OutputType::Empty => &mut self.spendable.empty,
|
||||
OutputType::OpReturn => &mut self.unspendable.opreturn,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Add for GroupedByType<T>
|
||||
where
|
||||
T: Add<Output = T>,
|
||||
{
|
||||
type Output = Self;
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self {
|
||||
spendable: self.spendable + rhs.spendable,
|
||||
unspendable: self.unspendable + rhs.unspendable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AddAssign for GroupedByType<T>
|
||||
where
|
||||
T: AddAssign,
|
||||
{
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
self.spendable += rhs.spendable;
|
||||
self.unspendable += rhs.unspendable;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct GroupedByUnspendableType<T> {
|
||||
pub opreturn: T,
|
||||
}
|
||||
|
||||
impl<T> GroupedByUnspendableType<T> {
|
||||
pub fn as_vec(&self) -> [&T; 1] {
|
||||
[&self.opreturn]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Add for GroupedByUnspendableType<T>
|
||||
where
|
||||
T: Add<Output = T>,
|
||||
{
|
||||
type Output = Self;
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self {
|
||||
opreturn: self.opreturn + rhs.opreturn,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AddAssign for GroupedByUnspendableType<T>
|
||||
where
|
||||
T: AddAssign,
|
||||
{
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
self.opreturn += rhs.opreturn;
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
use super::GroupFilter;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct GroupedByUpToDate<T> {
|
||||
pub _1d: T,
|
||||
pub _1w: T,
|
||||
pub _1m: T,
|
||||
pub _2m: T,
|
||||
pub _3m: T,
|
||||
pub _4m: T,
|
||||
pub _5m: T,
|
||||
pub _6m: T,
|
||||
pub _1y: T,
|
||||
pub _2y: T,
|
||||
pub _3y: T,
|
||||
pub _4y: T,
|
||||
pub _5y: T,
|
||||
pub _6y: T,
|
||||
pub _7y: T,
|
||||
pub _8y: T,
|
||||
pub _10y: T,
|
||||
pub _15y: T,
|
||||
}
|
||||
|
||||
impl<T> GroupedByUpToDate<T> {
|
||||
pub fn as_mut_vec(&mut self) -> [&mut T; 18] {
|
||||
[
|
||||
&mut self._1d,
|
||||
&mut self._1w,
|
||||
&mut self._1m,
|
||||
&mut self._2m,
|
||||
&mut self._3m,
|
||||
&mut self._4m,
|
||||
&mut self._5m,
|
||||
&mut self._6m,
|
||||
&mut self._1y,
|
||||
&mut self._2y,
|
||||
&mut self._3y,
|
||||
&mut self._4y,
|
||||
&mut self._5y,
|
||||
&mut self._6y,
|
||||
&mut self._7y,
|
||||
&mut self._8y,
|
||||
&mut self._10y,
|
||||
&mut self._15y,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> GroupedByUpToDate<(GroupFilter, T)> {
|
||||
pub fn vecs(&self) -> [&T; 18] {
|
||||
[
|
||||
&self._1d.1,
|
||||
&self._1w.1,
|
||||
&self._1m.1,
|
||||
&self._2m.1,
|
||||
&self._3m.1,
|
||||
&self._4m.1,
|
||||
&self._5m.1,
|
||||
&self._6m.1,
|
||||
&self._1y.1,
|
||||
&self._2y.1,
|
||||
&self._3y.1,
|
||||
&self._4y.1,
|
||||
&self._5y.1,
|
||||
&self._6y.1,
|
||||
&self._7y.1,
|
||||
&self._8y.1,
|
||||
&self._10y.1,
|
||||
&self._15y.1,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<GroupedByUpToDate<T>> for GroupedByUpToDate<(GroupFilter, T)> {
|
||||
fn from(value: GroupedByUpToDate<T>) -> Self {
|
||||
Self {
|
||||
_1d: (GroupFilter::To(1), value._1d),
|
||||
_1w: (GroupFilter::To(7), value._1w),
|
||||
_1m: (GroupFilter::To(30), value._1m),
|
||||
_2m: (GroupFilter::To(2 * 30), value._2m),
|
||||
_3m: (GroupFilter::To(3 * 30), value._3m),
|
||||
_4m: (GroupFilter::To(4 * 30), value._4m),
|
||||
_5m: (GroupFilter::To(5 * 30), value._5m),
|
||||
_6m: (GroupFilter::To(6 * 30), value._6m),
|
||||
_1y: (GroupFilter::To(365), value._1y),
|
||||
_2y: (GroupFilter::To(2 * 365), value._2y),
|
||||
_3y: (GroupFilter::To(3 * 365), value._3y),
|
||||
_4y: (GroupFilter::To(4 * 365), value._4y),
|
||||
_5y: (GroupFilter::To(5 * 365), value._5y),
|
||||
_6y: (GroupFilter::To(6 * 365), value._6y),
|
||||
_7y: (GroupFilter::To(7 * 365), value._7y),
|
||||
_8y: (GroupFilter::To(8 * 365), value._8y),
|
||||
_10y: (GroupFilter::To(10 * 365), value._10y),
|
||||
_15y: (GroupFilter::To(15 * 365), value._15y),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
use brk_core::Sats;
|
||||
|
||||
use super::GroupFilter;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct GroupedByUpToSize<T> {
|
||||
pub _1_000sats: T,
|
||||
pub _10_000sats: T,
|
||||
pub _1btc: T,
|
||||
pub _10btc: T,
|
||||
pub _100btc: T,
|
||||
}
|
||||
|
||||
impl<T> GroupedByUpToSize<T> {
|
||||
pub fn as_mut_vec(&mut self) -> [&mut T; 5] {
|
||||
[
|
||||
&mut self._1_000sats,
|
||||
&mut self._10_000sats,
|
||||
&mut self._1btc,
|
||||
&mut self._10btc,
|
||||
&mut self._100btc,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> GroupedByUpToSize<(GroupFilter, T)> {
|
||||
pub fn vecs(&self) -> [&T; 5] {
|
||||
[
|
||||
&self._1_000sats.1,
|
||||
&self._10_000sats.1,
|
||||
&self._1btc.1,
|
||||
&self._10btc.1,
|
||||
&self._100btc.1,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<GroupedByUpToSize<T>> for GroupedByUpToSize<(GroupFilter, T)> {
|
||||
fn from(value: GroupedByUpToSize<T>) -> Self {
|
||||
Self {
|
||||
_1_000sats: (GroupFilter::To(1_000), value._1_000sats),
|
||||
_10_000sats: (GroupFilter::To(10_000), value._10_000sats),
|
||||
_1btc: (GroupFilter::To(usize::from(Sats::ONE_BTC)), value._1btc),
|
||||
_10btc: (
|
||||
GroupFilter::To(usize::from(10 * Sats::ONE_BTC)),
|
||||
value._10btc,
|
||||
),
|
||||
_100btc: (
|
||||
GroupFilter::To(usize::from(100 * Sats::ONE_BTC)),
|
||||
value._100btc,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
#[derive(Default, Clone)]
|
||||
pub struct GroupedByValue<T> {
|
||||
pub up_to_1cent: T,
|
||||
pub from_1c_to_10c: T,
|
||||
pub from_10c_to_1d: T,
|
||||
pub from_1d_to_10d: T,
|
||||
pub from_10usd_to_100usd: T,
|
||||
pub from_100usd_to_1_000usd: T,
|
||||
pub from_1_000usd_to_10_000usd: T,
|
||||
pub from_10_000usd_to_100_000usd: T,
|
||||
pub from_100_000usd_to_1_000_000usd: T,
|
||||
pub from_1_000_000usd_to_10_000_000usd: T,
|
||||
pub from_10_000_000usd_to_100_000_000usd: T,
|
||||
pub from_100_000_000usd_to_1_000_000_000usd: T,
|
||||
pub from_1_000_000_000usd: T,
|
||||
// ...
|
||||
}
|
||||
|
||||
impl<T> GroupedByValue<T> {
|
||||
pub fn as_mut_vec(&mut self) -> Vec<&mut T> {
|
||||
vec![
|
||||
&mut self.up_to_1cent,
|
||||
&mut self.from_1c_to_10c,
|
||||
&mut self.from_10c_to_1d,
|
||||
&mut self.from_1d_to_10d,
|
||||
&mut self.from_10usd_to_100usd,
|
||||
&mut self.from_100usd_to_1_000usd,
|
||||
&mut self.from_1_000usd_to_10_000usd,
|
||||
&mut self.from_10_000usd_to_100_000usd,
|
||||
&mut self.from_100_000usd_to_1_000_000usd,
|
||||
&mut self.from_1_000_000usd_to_10_000_000usd,
|
||||
&mut self.from_10_000_000usd_to_100_000_000usd,
|
||||
&mut self.from_100_000_000usd_to_1_000_000_000usd,
|
||||
&mut self.from_1_000_000_000usd,
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
use std::ops::Range;
|
||||
|
||||
use brk_core::{HalvingEpoch, OutputType};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum GroupFilter {
|
||||
All,
|
||||
To(usize),
|
||||
Range(Range<usize>),
|
||||
From(usize),
|
||||
Epoch(HalvingEpoch),
|
||||
Type(OutputType),
|
||||
}
|
||||
|
||||
impl GroupFilter {
|
||||
pub fn contains(&self, value: usize) -> bool {
|
||||
match self {
|
||||
GroupFilter::All => true,
|
||||
GroupFilter::To(to) => *to > value,
|
||||
GroupFilter::From(from) => *from <= value,
|
||||
GroupFilter::Range(r) => r.contains(&value),
|
||||
GroupFilter::Epoch(_) => false,
|
||||
GroupFilter::Type(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn includes(&self, other: &GroupFilter) -> bool {
|
||||
match self {
|
||||
GroupFilter::All => true,
|
||||
GroupFilter::To(to) => match other {
|
||||
GroupFilter::All => false,
|
||||
GroupFilter::To(to2) => to >= to2,
|
||||
GroupFilter::Range(range) => range.end <= *to,
|
||||
GroupFilter::From(_) => false,
|
||||
GroupFilter::Epoch(_) => false,
|
||||
GroupFilter::Type(_) => false,
|
||||
},
|
||||
GroupFilter::From(from) => match other {
|
||||
GroupFilter::All => false,
|
||||
GroupFilter::To(_) => false,
|
||||
GroupFilter::Range(range) => range.start >= *from,
|
||||
GroupFilter::From(from2) => from <= from2,
|
||||
GroupFilter::Epoch(_) => false,
|
||||
GroupFilter::Type(_) => false,
|
||||
},
|
||||
GroupFilter::Range(_) => false,
|
||||
GroupFilter::Epoch(_) => false,
|
||||
GroupFilter::Type(_) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
mod address;
|
||||
mod by_address_type;
|
||||
mod by_date_range;
|
||||
mod by_epoch;
|
||||
mod by_from_date;
|
||||
mod by_from_size;
|
||||
mod by_size_range;
|
||||
mod by_spendable_type;
|
||||
mod by_term;
|
||||
mod by_type;
|
||||
mod by_unspendable_type;
|
||||
mod by_up_to_date;
|
||||
mod by_up_to_size;
|
||||
mod filter;
|
||||
mod utxo;
|
||||
|
||||
pub use address::*;
|
||||
pub use by_address_type::*;
|
||||
pub use by_date_range::*;
|
||||
pub use by_epoch::*;
|
||||
pub use by_from_date::*;
|
||||
pub use by_from_size::*;
|
||||
pub use by_size_range::*;
|
||||
pub use by_spendable_type::*;
|
||||
pub use by_term::*;
|
||||
pub use by_type::*;
|
||||
pub use by_unspendable_type::*;
|
||||
pub use by_up_to_date::*;
|
||||
pub use by_up_to_size::*;
|
||||
pub use filter::*;
|
||||
pub use utxo::*;
|
||||
@@ -1,91 +0,0 @@
|
||||
use crate::{
|
||||
GroupFilter, GroupedByDateRange, GroupedByEpoch, GroupedByFromDate, GroupedByFromSize,
|
||||
GroupedBySizeRange, GroupedBySpendableType, GroupedByTerm, GroupedByUpToDate,
|
||||
GroupedByUpToSize,
|
||||
};
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct UTXOGroups<T> {
|
||||
pub all: T,
|
||||
pub by_date_range: GroupedByDateRange<T>,
|
||||
pub by_epoch: GroupedByEpoch<T>,
|
||||
pub by_from_date: GroupedByFromDate<T>,
|
||||
pub by_from_size: GroupedByFromSize<T>,
|
||||
pub by_size_range: GroupedBySizeRange<T>,
|
||||
pub by_term: GroupedByTerm<T>,
|
||||
pub by_type: GroupedBySpendableType<T>,
|
||||
pub by_up_to_date: GroupedByUpToDate<T>,
|
||||
pub by_up_to_size: GroupedByUpToSize<T>,
|
||||
}
|
||||
|
||||
impl<T> UTXOGroups<T> {
|
||||
pub fn as_mut_vecs(&mut self) -> Vec<&mut T> {
|
||||
[&mut self.all]
|
||||
.into_iter()
|
||||
.chain(self.by_term.as_mut_vec())
|
||||
.chain(self.by_up_to_date.as_mut_vec())
|
||||
.chain(self.by_from_date.as_mut_vec())
|
||||
.chain(self.by_from_size.as_mut_vec())
|
||||
.chain(self.by_date_range.as_mut_vec())
|
||||
.chain(self.by_epoch.as_mut_vec())
|
||||
.chain(self.by_size_range.as_mut_vec())
|
||||
.chain(self.by_up_to_size.as_mut_vec())
|
||||
.chain(self.by_type.as_mut_vec())
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
pub fn as_mut_separate_vecs(&mut self) -> Vec<&mut T> {
|
||||
self.by_date_range
|
||||
.as_mut_vec()
|
||||
.into_iter()
|
||||
.chain(self.by_epoch.as_mut_vec())
|
||||
.chain(self.by_size_range.as_mut_vec())
|
||||
.chain(self.by_type.as_mut_vec())
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
pub fn as_mut_overlapping_vecs(&mut self) -> Vec<&mut T> {
|
||||
[&mut self.all]
|
||||
.into_iter()
|
||||
.chain(self.by_term.as_mut_vec())
|
||||
.chain(self.by_up_to_date.as_mut_vec())
|
||||
.chain(self.by_from_date.as_mut_vec())
|
||||
.chain(self.by_up_to_size.as_mut_vec())
|
||||
.chain(self.by_from_size.as_mut_vec())
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> UTXOGroups<(GroupFilter, T)> {
|
||||
pub fn vecs(&self) -> Vec<&T> {
|
||||
[&self.all.1]
|
||||
.into_iter()
|
||||
.chain(self.by_term.vecs())
|
||||
.chain(self.by_up_to_date.vecs())
|
||||
.chain(self.by_from_date.vecs())
|
||||
.chain(self.by_date_range.vecs())
|
||||
.chain(self.by_epoch.vecs())
|
||||
.chain(self.by_size_range.vecs())
|
||||
.chain(self.by_type.vecs())
|
||||
.chain(self.by_up_to_size.vecs())
|
||||
.chain(self.by_from_size.vecs())
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<UTXOGroups<T>> for UTXOGroups<(GroupFilter, T)> {
|
||||
fn from(value: UTXOGroups<T>) -> Self {
|
||||
Self {
|
||||
all: (GroupFilter::All, value.all),
|
||||
by_term: GroupedByTerm::from(value.by_term),
|
||||
by_up_to_date: GroupedByUpToDate::from(value.by_up_to_date),
|
||||
by_from_date: GroupedByFromDate::from(value.by_from_date),
|
||||
by_date_range: GroupedByDateRange::from(value.by_date_range),
|
||||
by_epoch: GroupedByEpoch::from(value.by_epoch),
|
||||
by_size_range: GroupedBySizeRange::from(value.by_size_range),
|
||||
by_up_to_size: GroupedByUpToSize::from(value.by_up_to_size),
|
||||
by_from_size: GroupedByFromSize::from(value.by_from_size),
|
||||
by_type: GroupedBySpendableType::from(value.by_type),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,11 @@ use brk_indexer::Indexer;
|
||||
use brk_vec::{Computation, Format};
|
||||
use log::info;
|
||||
|
||||
mod groups;
|
||||
mod states;
|
||||
mod stores;
|
||||
mod utils;
|
||||
mod vecs;
|
||||
|
||||
use groups::*;
|
||||
use states::*;
|
||||
use stores::Stores;
|
||||
use vecs::Vecs;
|
||||
@@ -55,7 +53,6 @@ impl Computer {
|
||||
// TODO: Give self.path, join inside import
|
||||
&outputs_dir.join("stores"),
|
||||
VERSION + Version::ZERO,
|
||||
&indexer.stores.keyspace,
|
||||
)?,
|
||||
fetcher,
|
||||
})
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
use brk_core::{OutputType, Sats};
|
||||
|
||||
use crate::{GroupedBySizeRange, GroupedByType};
|
||||
use brk_core::{GroupedBySizeRange, GroupedByType, OutputType, Sats};
|
||||
|
||||
use super::SupplyState;
|
||||
|
||||
|
||||
@@ -1,131 +1,52 @@
|
||||
use std::{path::Path, thread};
|
||||
|
||||
use brk_core::{
|
||||
AddressData, EmptyAddressData, Height, OutputIndex, OutputType, P2AAddressIndex,
|
||||
P2AAddressIndexOutputindex, P2PK33AddressIndex, P2PK33AddressIndexOutputindex,
|
||||
P2PK65AddressIndex, P2PK65AddressIndexOutputindex, P2PKHAddressIndex,
|
||||
P2PKHAddressIndexOutputindex, P2SHAddressIndex, P2SHAddressIndexOutputindex, P2TRAddressIndex,
|
||||
P2TRAddressIndexOutputindex, P2WPKHAddressIndex, P2WPKHAddressIndexOutputindex,
|
||||
P2WSHAddressIndex, P2WSHAddressIndexOutputindex, Result, TypeIndex, Unit, Version,
|
||||
AddressData, EmptyAddressData, GroupedByAddressType, Height, OutputType, P2AAddressIndex,
|
||||
P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2TRAddressIndex,
|
||||
P2WPKHAddressIndex, P2WSHAddressIndex, Result, TypeIndex, Version,
|
||||
};
|
||||
use brk_store::{AnyStore, Store};
|
||||
use fjall::{PersistMode, TransactionalKeyspace};
|
||||
use log::info;
|
||||
|
||||
use crate::{
|
||||
GroupedByAddressType,
|
||||
vecs::stateful::{
|
||||
AddressTypeToTypeIndexTree, AddressTypeToTypeIndexVec, WithAddressDataSource,
|
||||
},
|
||||
};
|
||||
use crate::vecs::stateful::{AddressTypeToTypeIndexTree, WithAddressDataSource};
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Stores {
|
||||
keyspace: TransactionalKeyspace,
|
||||
|
||||
pub p2aaddressindex_to_addressdata: Store<P2AAddressIndex, AddressData>,
|
||||
pub p2aaddressindex_to_emptyaddressdata: Store<P2AAddressIndex, EmptyAddressData>,
|
||||
pub p2aaddressindex_to_outputs_received: Store<P2AAddressIndexOutputindex, Unit>,
|
||||
pub p2aaddressindex_to_outputs_sent: Store<P2AAddressIndexOutputindex, Unit>,
|
||||
|
||||
pub p2pk33addressindex_to_addressdata: Store<P2PK33AddressIndex, AddressData>,
|
||||
pub p2pk33addressindex_to_emptyaddressdata: Store<P2PK33AddressIndex, EmptyAddressData>,
|
||||
pub p2pk33addressindex_to_outputs_received: Store<P2PK33AddressIndexOutputindex, Unit>,
|
||||
pub p2pk33addressindex_to_outputs_sent: Store<P2PK33AddressIndexOutputindex, Unit>,
|
||||
|
||||
pub p2pk65addressindex_to_addressdata: Store<P2PK65AddressIndex, AddressData>,
|
||||
pub p2pk65addressindex_to_emptyaddressdata: Store<P2PK65AddressIndex, EmptyAddressData>,
|
||||
pub p2pk65addressindex_to_outputs_received: Store<P2PK65AddressIndexOutputindex, Unit>,
|
||||
pub p2pk65addressindex_to_outputs_sent: Store<P2PK65AddressIndexOutputindex, Unit>,
|
||||
|
||||
pub p2pkhaddressindex_to_addressdata: Store<P2PKHAddressIndex, AddressData>,
|
||||
pub p2pkhaddressindex_to_emptyaddressdata: Store<P2PKHAddressIndex, EmptyAddressData>,
|
||||
pub p2pkhaddressindex_to_outputs_received: Store<P2PKHAddressIndexOutputindex, Unit>,
|
||||
pub p2pkhaddressindex_to_outputs_sent: Store<P2PKHAddressIndexOutputindex, Unit>,
|
||||
|
||||
pub p2shaddressindex_to_addressdata: Store<P2SHAddressIndex, AddressData>,
|
||||
pub p2shaddressindex_to_emptyaddressdata: Store<P2SHAddressIndex, EmptyAddressData>,
|
||||
pub p2shaddressindex_to_outputs_received: Store<P2SHAddressIndexOutputindex, Unit>,
|
||||
pub p2shaddressindex_to_outputs_sent: Store<P2SHAddressIndexOutputindex, Unit>,
|
||||
|
||||
pub p2traddressindex_to_addressdata: Store<P2TRAddressIndex, AddressData>,
|
||||
pub p2traddressindex_to_emptyaddressdata: Store<P2TRAddressIndex, EmptyAddressData>,
|
||||
pub p2traddressindex_to_outputs_received: Store<P2TRAddressIndexOutputindex, Unit>,
|
||||
pub p2traddressindex_to_outputs_sent: Store<P2TRAddressIndexOutputindex, Unit>,
|
||||
|
||||
pub p2wpkhaddressindex_to_addressdata: Store<P2WPKHAddressIndex, AddressData>,
|
||||
pub p2wpkhaddressindex_to_emptyaddressdata: Store<P2WPKHAddressIndex, EmptyAddressData>,
|
||||
pub p2wpkhaddressindex_to_outputs_received: Store<P2WPKHAddressIndexOutputindex, Unit>,
|
||||
pub p2wpkhaddressindex_to_outputs_sent: Store<P2WPKHAddressIndexOutputindex, Unit>,
|
||||
|
||||
pub p2wshaddressindex_to_addressdata: Store<P2WSHAddressIndex, AddressData>,
|
||||
pub p2wshaddressindex_to_emptyaddressdata: Store<P2WSHAddressIndex, EmptyAddressData>,
|
||||
pub p2wshaddressindex_to_outputs_received: Store<P2WSHAddressIndexOutputindex, Unit>,
|
||||
pub p2wshaddressindex_to_outputs_sent: Store<P2WSHAddressIndexOutputindex, Unit>,
|
||||
}
|
||||
|
||||
impl Stores {
|
||||
pub fn import(
|
||||
path: &Path,
|
||||
version: Version,
|
||||
keyspace: &TransactionalKeyspace,
|
||||
) -> color_eyre::Result<Self> {
|
||||
pub fn import(path: &Path, version: Version) -> color_eyre::Result<Self> {
|
||||
let (
|
||||
(
|
||||
p2aaddressindex_to_addressdata,
|
||||
p2aaddressindex_to_emptyaddressdata,
|
||||
p2aaddressindex_to_outputs_received,
|
||||
p2aaddressindex_to_outputs_sent,
|
||||
),
|
||||
(
|
||||
p2pk33addressindex_to_addressdata,
|
||||
p2pk33addressindex_to_emptyaddressdata,
|
||||
p2pk33addressindex_to_outputs_received,
|
||||
p2pk33addressindex_to_outputs_sent,
|
||||
),
|
||||
(
|
||||
p2pk65addressindex_to_addressdata,
|
||||
p2pk65addressindex_to_emptyaddressdata,
|
||||
p2pk65addressindex_to_outputs_received,
|
||||
p2pk65addressindex_to_outputs_sent,
|
||||
),
|
||||
(
|
||||
p2pkhaddressindex_to_addressdata,
|
||||
p2pkhaddressindex_to_emptyaddressdata,
|
||||
p2pkhaddressindex_to_outputs_received,
|
||||
p2pkhaddressindex_to_outputs_sent,
|
||||
),
|
||||
(
|
||||
p2shaddressindex_to_addressdata,
|
||||
p2shaddressindex_to_emptyaddressdata,
|
||||
p2shaddressindex_to_outputs_received,
|
||||
p2shaddressindex_to_outputs_sent,
|
||||
),
|
||||
(
|
||||
p2traddressindex_to_addressdata,
|
||||
p2traddressindex_to_emptyaddressdata,
|
||||
p2traddressindex_to_outputs_received,
|
||||
p2traddressindex_to_outputs_sent,
|
||||
),
|
||||
(
|
||||
p2wpkhaddressindex_to_addressdata,
|
||||
p2wpkhaddressindex_to_emptyaddressdata,
|
||||
p2wpkhaddressindex_to_outputs_received,
|
||||
p2wpkhaddressindex_to_outputs_sent,
|
||||
),
|
||||
(
|
||||
p2wshaddressindex_to_addressdata,
|
||||
p2wshaddressindex_to_emptyaddressdata,
|
||||
p2wshaddressindex_to_outputs_received,
|
||||
p2wshaddressindex_to_outputs_sent,
|
||||
),
|
||||
(p2aaddressindex_to_addressdata, p2aaddressindex_to_emptyaddressdata),
|
||||
(p2pk33addressindex_to_addressdata, p2pk33addressindex_to_emptyaddressdata),
|
||||
(p2pk65addressindex_to_addressdata, p2pk65addressindex_to_emptyaddressdata),
|
||||
(p2pkhaddressindex_to_addressdata, p2pkhaddressindex_to_emptyaddressdata),
|
||||
(p2shaddressindex_to_addressdata, p2shaddressindex_to_emptyaddressdata),
|
||||
(p2traddressindex_to_addressdata, p2traddressindex_to_emptyaddressdata),
|
||||
(p2wpkhaddressindex_to_addressdata, p2wpkhaddressindex_to_emptyaddressdata),
|
||||
(p2wshaddressindex_to_addressdata, p2wshaddressindex_to_emptyaddressdata),
|
||||
) = thread::scope(|scope| {
|
||||
let p2a = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2aaddressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -133,36 +54,18 @@ impl Stores {
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2aaddressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2aaddressindex_to_outputs_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2aaddressindex_to_outputs_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let p2pk33 = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk33addressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -170,36 +73,18 @@ impl Stores {
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk33addressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk33addressindex_to_outputs_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk33addressindex_to_outputs_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let p2pk65 = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk65addressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -207,36 +92,18 @@ impl Stores {
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk65addressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk65addressindex_to_outputs_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pk65addressindex_to_outputs_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let p2pkh = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pkhaddressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -244,36 +111,18 @@ impl Stores {
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pkhaddressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pkhaddressindex_to_outputs_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2pkhaddressindex_to_outputs_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let p2sh = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2shaddressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -281,36 +130,18 @@ impl Stores {
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2shaddressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2shaddressindex_to_outputs_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2shaddressindex_to_outputs_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let p2tr = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2traddressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -318,36 +149,18 @@ impl Stores {
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2traddressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2traddressindex_to_outputs_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2traddressindex_to_outputs_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let p2wpkh = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wpkhaddressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -355,36 +168,18 @@ impl Stores {
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wpkhaddressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wpkhaddressindex_to_outputs_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wpkhaddressindex_to_outputs_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let p2wsh = scope.spawn(|| {
|
||||
(
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wshaddressindex_to_addressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -392,29 +187,12 @@ impl Stores {
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wshaddressindex_to_emptyaddressdata",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wshaddressindex_to_outputs_received",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
Store::import(
|
||||
keyspace,
|
||||
path,
|
||||
"p2wshaddressindex_to_outputs_sent",
|
||||
version + VERSION + Version::ZERO,
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
@@ -431,47 +209,29 @@ impl Stores {
|
||||
});
|
||||
|
||||
Ok(Self {
|
||||
keyspace: keyspace.clone(),
|
||||
|
||||
p2aaddressindex_to_addressdata,
|
||||
p2aaddressindex_to_emptyaddressdata,
|
||||
p2aaddressindex_to_outputs_received,
|
||||
p2aaddressindex_to_outputs_sent,
|
||||
|
||||
p2pk33addressindex_to_addressdata,
|
||||
p2pk33addressindex_to_emptyaddressdata,
|
||||
p2pk33addressindex_to_outputs_received,
|
||||
p2pk33addressindex_to_outputs_sent,
|
||||
|
||||
p2pk65addressindex_to_addressdata,
|
||||
p2pk65addressindex_to_emptyaddressdata,
|
||||
p2pk65addressindex_to_outputs_received,
|
||||
p2pk65addressindex_to_outputs_sent,
|
||||
|
||||
p2pkhaddressindex_to_addressdata,
|
||||
p2pkhaddressindex_to_emptyaddressdata,
|
||||
p2pkhaddressindex_to_outputs_received,
|
||||
p2pkhaddressindex_to_outputs_sent,
|
||||
|
||||
p2shaddressindex_to_addressdata,
|
||||
p2shaddressindex_to_emptyaddressdata,
|
||||
p2shaddressindex_to_outputs_received,
|
||||
p2shaddressindex_to_outputs_sent,
|
||||
|
||||
p2traddressindex_to_addressdata,
|
||||
p2traddressindex_to_emptyaddressdata,
|
||||
p2traddressindex_to_outputs_received,
|
||||
p2traddressindex_to_outputs_sent,
|
||||
|
||||
p2wpkhaddressindex_to_addressdata,
|
||||
p2wpkhaddressindex_to_emptyaddressdata,
|
||||
p2wpkhaddressindex_to_outputs_received,
|
||||
p2wpkhaddressindex_to_outputs_sent,
|
||||
|
||||
p2wshaddressindex_to_addressdata,
|
||||
p2wshaddressindex_to_emptyaddressdata,
|
||||
p2wshaddressindex_to_outputs_received,
|
||||
p2wshaddressindex_to_outputs_sent,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -489,13 +249,7 @@ impl Stores {
|
||||
|
||||
self.as_mut_slice()
|
||||
.into_iter()
|
||||
.try_for_each(|store| store.reset())?;
|
||||
|
||||
info!("Persisting stores...");
|
||||
|
||||
self.keyspace
|
||||
.persist(PersistMode::SyncAll)
|
||||
.map_err(|e| e.into())
|
||||
.try_for_each(|store| store.reset())
|
||||
}
|
||||
|
||||
pub fn get_addressdata(
|
||||
@@ -585,8 +339,6 @@ impl Stores {
|
||||
pub fn commit(
|
||||
&mut self,
|
||||
height: Height,
|
||||
sent: AddressTypeToTypeIndexVec<OutputIndex>,
|
||||
received: AddressTypeToTypeIndexVec<OutputIndex>,
|
||||
addresstype_to_typeindex_to_addressdata: AddressTypeToTypeIndexTree<
|
||||
WithAddressDataSource<AddressData>,
|
||||
>,
|
||||
@@ -811,191 +563,7 @@ impl Stores {
|
||||
});
|
||||
});
|
||||
|
||||
thread::scope(|s| {
|
||||
let GroupedByAddressType {
|
||||
p2pk65,
|
||||
p2pk33,
|
||||
p2pkh,
|
||||
p2sh,
|
||||
p2wpkh,
|
||||
p2wsh,
|
||||
p2tr,
|
||||
p2a,
|
||||
} = received.unwrap();
|
||||
|
||||
s.spawn(|| {
|
||||
self.p2aaddressindex_to_outputs_received.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2a.into_iter()
|
||||
.map(P2AAddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
s.spawn(|| {
|
||||
self.p2pk33addressindex_to_outputs_received.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2pk33
|
||||
.into_iter()
|
||||
.map(P2PK33AddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
s.spawn(|| {
|
||||
self.p2pk65addressindex_to_outputs_received.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2pk65
|
||||
.into_iter()
|
||||
.map(P2PK65AddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
s.spawn(|| {
|
||||
self.p2pkhaddressindex_to_outputs_received.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2pkh
|
||||
.into_iter()
|
||||
.map(P2PKHAddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
s.spawn(|| {
|
||||
self.p2shaddressindex_to_outputs_received.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2sh.into_iter()
|
||||
.map(P2SHAddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
s.spawn(|| {
|
||||
self.p2traddressindex_to_outputs_received.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2tr.into_iter()
|
||||
.map(P2TRAddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
s.spawn(|| {
|
||||
self.p2wpkhaddressindex_to_outputs_received.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2wpkh
|
||||
.into_iter()
|
||||
.map(P2WPKHAddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
s.spawn(|| {
|
||||
self.p2wshaddressindex_to_outputs_received.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2wsh
|
||||
.into_iter()
|
||||
.map(P2WSHAddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
});
|
||||
|
||||
thread::scope(|s| {
|
||||
let GroupedByAddressType {
|
||||
p2pk65,
|
||||
p2pk33,
|
||||
p2pkh,
|
||||
p2sh,
|
||||
p2wpkh,
|
||||
p2wsh,
|
||||
p2tr,
|
||||
p2a,
|
||||
} = sent.unwrap();
|
||||
|
||||
s.spawn(|| {
|
||||
self.p2aaddressindex_to_outputs_sent.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2a.into_iter()
|
||||
.map(P2AAddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
s.spawn(|| {
|
||||
self.p2pk33addressindex_to_outputs_sent.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2pk33
|
||||
.into_iter()
|
||||
.map(P2PK33AddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
s.spawn(|| {
|
||||
self.p2pk65addressindex_to_outputs_sent.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2pk65
|
||||
.into_iter()
|
||||
.map(P2PK65AddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
s.spawn(|| {
|
||||
self.p2pkhaddressindex_to_outputs_sent.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2pkh
|
||||
.into_iter()
|
||||
.map(P2PKHAddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
s.spawn(|| {
|
||||
self.p2shaddressindex_to_outputs_sent.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2sh.into_iter()
|
||||
.map(P2SHAddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
s.spawn(|| {
|
||||
self.p2traddressindex_to_outputs_sent.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2tr.into_iter()
|
||||
.map(P2TRAddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
s.spawn(|| {
|
||||
self.p2wpkhaddressindex_to_outputs_sent.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2wpkh
|
||||
.into_iter()
|
||||
.map(P2WPKHAddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
s.spawn(|| {
|
||||
self.p2wshaddressindex_to_outputs_sent.commit_(
|
||||
height,
|
||||
[].into_iter(),
|
||||
p2wsh
|
||||
.into_iter()
|
||||
.map(P2WSHAddressIndexOutputindex::from)
|
||||
.map(|i| (i, Unit)),
|
||||
)
|
||||
});
|
||||
});
|
||||
|
||||
self.keyspace
|
||||
.persist(PersistMode::SyncAll)
|
||||
.map_err(|e| e.into())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn rotate_memtables(&self) {
|
||||
@@ -1004,77 +572,45 @@ impl Stores {
|
||||
.for_each(|store| store.rotate_memtable());
|
||||
}
|
||||
|
||||
pub fn as_slice(&self) -> [&(dyn AnyStore + Send + Sync); 32] {
|
||||
pub fn as_slice(&self) -> [&(dyn AnyStore + Send + Sync); 16] {
|
||||
[
|
||||
&self.p2aaddressindex_to_addressdata,
|
||||
&self.p2aaddressindex_to_emptyaddressdata,
|
||||
&self.p2aaddressindex_to_outputs_received,
|
||||
&self.p2aaddressindex_to_outputs_sent,
|
||||
&self.p2pk33addressindex_to_addressdata,
|
||||
&self.p2pk33addressindex_to_emptyaddressdata,
|
||||
&self.p2pk33addressindex_to_outputs_received,
|
||||
&self.p2pk33addressindex_to_outputs_sent,
|
||||
&self.p2pk65addressindex_to_addressdata,
|
||||
&self.p2pk65addressindex_to_emptyaddressdata,
|
||||
&self.p2pk65addressindex_to_outputs_received,
|
||||
&self.p2pk65addressindex_to_outputs_sent,
|
||||
&self.p2pkhaddressindex_to_addressdata,
|
||||
&self.p2pkhaddressindex_to_emptyaddressdata,
|
||||
&self.p2pkhaddressindex_to_outputs_received,
|
||||
&self.p2pkhaddressindex_to_outputs_sent,
|
||||
&self.p2shaddressindex_to_addressdata,
|
||||
&self.p2shaddressindex_to_emptyaddressdata,
|
||||
&self.p2shaddressindex_to_outputs_received,
|
||||
&self.p2shaddressindex_to_outputs_sent,
|
||||
&self.p2traddressindex_to_addressdata,
|
||||
&self.p2traddressindex_to_emptyaddressdata,
|
||||
&self.p2traddressindex_to_outputs_received,
|
||||
&self.p2traddressindex_to_outputs_sent,
|
||||
&self.p2wpkhaddressindex_to_addressdata,
|
||||
&self.p2wpkhaddressindex_to_emptyaddressdata,
|
||||
&self.p2wpkhaddressindex_to_outputs_received,
|
||||
&self.p2wpkhaddressindex_to_outputs_sent,
|
||||
&self.p2wshaddressindex_to_addressdata,
|
||||
&self.p2wshaddressindex_to_emptyaddressdata,
|
||||
&self.p2wshaddressindex_to_outputs_received,
|
||||
&self.p2wshaddressindex_to_outputs_sent,
|
||||
]
|
||||
}
|
||||
|
||||
fn as_mut_slice(&mut self) -> [&mut (dyn AnyStore + Send + Sync); 32] {
|
||||
fn as_mut_slice(&mut self) -> [&mut (dyn AnyStore + Send + Sync); 16] {
|
||||
[
|
||||
&mut self.p2aaddressindex_to_addressdata,
|
||||
&mut self.p2aaddressindex_to_emptyaddressdata,
|
||||
&mut self.p2aaddressindex_to_outputs_received,
|
||||
&mut self.p2aaddressindex_to_outputs_sent,
|
||||
&mut self.p2pk33addressindex_to_addressdata,
|
||||
&mut self.p2pk33addressindex_to_emptyaddressdata,
|
||||
&mut self.p2pk33addressindex_to_outputs_received,
|
||||
&mut self.p2pk33addressindex_to_outputs_sent,
|
||||
&mut self.p2pk65addressindex_to_addressdata,
|
||||
&mut self.p2pk65addressindex_to_emptyaddressdata,
|
||||
&mut self.p2pk65addressindex_to_outputs_received,
|
||||
&mut self.p2pk65addressindex_to_outputs_sent,
|
||||
&mut self.p2pkhaddressindex_to_addressdata,
|
||||
&mut self.p2pkhaddressindex_to_emptyaddressdata,
|
||||
&mut self.p2pkhaddressindex_to_outputs_received,
|
||||
&mut self.p2pkhaddressindex_to_outputs_sent,
|
||||
&mut self.p2shaddressindex_to_addressdata,
|
||||
&mut self.p2shaddressindex_to_emptyaddressdata,
|
||||
&mut self.p2shaddressindex_to_outputs_received,
|
||||
&mut self.p2shaddressindex_to_outputs_sent,
|
||||
&mut self.p2traddressindex_to_addressdata,
|
||||
&mut self.p2traddressindex_to_emptyaddressdata,
|
||||
&mut self.p2traddressindex_to_outputs_received,
|
||||
&mut self.p2traddressindex_to_outputs_sent,
|
||||
&mut self.p2wpkhaddressindex_to_addressdata,
|
||||
&mut self.p2wpkhaddressindex_to_emptyaddressdata,
|
||||
&mut self.p2wpkhaddressindex_to_outputs_received,
|
||||
&mut self.p2wpkhaddressindex_to_outputs_sent,
|
||||
&mut self.p2wshaddressindex_to_addressdata,
|
||||
&mut self.p2wshaddressindex_to_emptyaddressdata,
|
||||
&mut self.p2wshaddressindex_to_outputs_received,
|
||||
&mut self.p2wshaddressindex_to_outputs_sent,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
use std::path::Path;
|
||||
|
||||
use brk_core::{Height, Result, Version};
|
||||
use brk_core::{
|
||||
AddressGroups, GroupFilter, GroupedByFromSize, GroupedBySizeRange, GroupedByUpToSize, Height,
|
||||
Result, Version,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use brk_vec::{Computation, Format};
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::{
|
||||
AddressGroups, GroupFilter, GroupedByFromSize, GroupedBySizeRange, GroupedByUpToSize,
|
||||
vecs::{
|
||||
Indexes, fetched,
|
||||
stateful::{address_cohort, r#trait::CohortVecs},
|
||||
},
|
||||
use crate::vecs::{
|
||||
Indexes, fetched,
|
||||
stateful::{address_cohort, r#trait::CohortVecs},
|
||||
};
|
||||
|
||||
const VERSION: Version = Version::new(0);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
use brk_core::{GroupedByAddressType, Height};
|
||||
use brk_vec::VecIterator;
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
|
||||
use crate::vecs::stateful::addresstype_to_addresscount_vec::AddressTypeToAddressCountVec;
|
||||
|
||||
#[derive(Debug, Default, Deref, DerefMut)]
|
||||
pub struct AddressTypeToAddressCount(GroupedByAddressType<usize>);
|
||||
|
||||
impl From<(&AddressTypeToAddressCountVec, Height)> for AddressTypeToAddressCount {
|
||||
fn from((groups, starting_height): (&AddressTypeToAddressCountVec, Height)) -> Self {
|
||||
if let Some(prev_height) = starting_height.decremented() {
|
||||
Self(GroupedByAddressType {
|
||||
p2pk65: groups
|
||||
.p2pk65
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height)
|
||||
.into(),
|
||||
p2pk33: groups
|
||||
.p2pk33
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height)
|
||||
.into(),
|
||||
p2pkh: groups
|
||||
.p2pkh
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height)
|
||||
.into(),
|
||||
p2sh: groups.p2sh.into_iter().unwrap_get_inner(prev_height).into(),
|
||||
p2wpkh: groups
|
||||
.p2wpkh
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height)
|
||||
.into(),
|
||||
p2wsh: groups
|
||||
.p2wsh
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height)
|
||||
.into(),
|
||||
p2tr: groups.p2tr.into_iter().unwrap_get_inner(prev_height).into(),
|
||||
p2a: groups.p2a.into_iter().unwrap_get_inner(prev_height).into(),
|
||||
})
|
||||
} else {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
use brk_core::{GroupedByAddressType, Height, Result, StoredUsize};
|
||||
use brk_exit::Exit;
|
||||
use brk_vec::EagerVec;
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
|
||||
use crate::vecs::stateful::addresstype_to_addresscount::AddressTypeToAddressCount;
|
||||
|
||||
#[derive(Debug, Clone, Deref, DerefMut)]
|
||||
pub struct AddressTypeToAddressCountVec(GroupedByAddressType<EagerVec<Height, StoredUsize>>);
|
||||
|
||||
impl From<GroupedByAddressType<EagerVec<Height, StoredUsize>>> for AddressTypeToAddressCountVec {
|
||||
fn from(value: GroupedByAddressType<EagerVec<Height, StoredUsize>>) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddressTypeToAddressCountVec {
|
||||
pub fn forced_push_at(
|
||||
&mut self,
|
||||
height: Height,
|
||||
addresstype_to_usize: &AddressTypeToAddressCount,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.p2pk65
|
||||
.forced_push_at(height, addresstype_to_usize.p2pk65.into(), exit)?;
|
||||
self.p2pk33
|
||||
.forced_push_at(height, addresstype_to_usize.p2pk33.into(), exit)?;
|
||||
self.p2pkh
|
||||
.forced_push_at(height, addresstype_to_usize.p2pkh.into(), exit)?;
|
||||
self.p2sh
|
||||
.forced_push_at(height, addresstype_to_usize.p2sh.into(), exit)?;
|
||||
self.p2wpkh
|
||||
.forced_push_at(height, addresstype_to_usize.p2wpkh.into(), exit)?;
|
||||
self.p2wsh
|
||||
.forced_push_at(height, addresstype_to_usize.p2wsh.into(), exit)?;
|
||||
self.p2tr
|
||||
.forced_push_at(height, addresstype_to_usize.p2tr.into(), exit)?;
|
||||
self.p2a
|
||||
.forced_push_at(height, addresstype_to_usize.p2a.into(), exit)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
use std::mem;
|
||||
|
||||
use brk_core::{AddressData, Dollars, OutputIndex, Sats, TypeIndex};
|
||||
use brk_core::TypeIndex;
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
|
||||
use crate::vecs::stateful::WithAddressDataSource;
|
||||
|
||||
use super::GroupedByAddressType;
|
||||
|
||||
#[derive(Debug, Default, Deref, DerefMut)]
|
||||
@@ -30,91 +28,4 @@ impl<T> AddressTypeToTypeIndexVec<T> {
|
||||
mem::swap(own, other);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unwrap(self) -> GroupedByAddressType<Vec<(TypeIndex, T)>> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AddressTypeToTypeIndexVec<OutputIndex> {
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn extend_from_sent(
|
||||
&mut self,
|
||||
other: &AddressTypeToTypeIndexVec<(
|
||||
OutputIndex,
|
||||
Sats,
|
||||
Option<WithAddressDataSource<AddressData>>,
|
||||
Option<Dollars>,
|
||||
usize,
|
||||
f64,
|
||||
bool,
|
||||
)>,
|
||||
) {
|
||||
Self::extend_from_sent_(&mut self.p2pk33, &other.p2pk33);
|
||||
Self::extend_from_sent_(&mut self.p2pkh, &other.p2pkh);
|
||||
Self::extend_from_sent_(&mut self.p2sh, &other.p2sh);
|
||||
Self::extend_from_sent_(&mut self.p2wpkh, &other.p2wpkh);
|
||||
Self::extend_from_sent_(&mut self.p2wsh, &other.p2wsh);
|
||||
Self::extend_from_sent_(&mut self.p2tr, &other.p2tr);
|
||||
Self::extend_from_sent_(&mut self.p2a, &other.p2a);
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn extend_from_sent_(
|
||||
own: &mut Vec<(TypeIndex, OutputIndex)>,
|
||||
other: &[(
|
||||
TypeIndex,
|
||||
(
|
||||
OutputIndex,
|
||||
Sats,
|
||||
Option<WithAddressDataSource<AddressData>>,
|
||||
Option<Dollars>,
|
||||
usize,
|
||||
f64,
|
||||
bool,
|
||||
),
|
||||
)],
|
||||
) {
|
||||
own.extend(
|
||||
other
|
||||
.iter()
|
||||
.map(|(type_index, (output_index, ..))| (*type_index, *output_index)),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn extend_from_received(
|
||||
&mut self,
|
||||
other: &AddressTypeToTypeIndexVec<(
|
||||
OutputIndex,
|
||||
Sats,
|
||||
Option<WithAddressDataSource<AddressData>>,
|
||||
)>,
|
||||
) {
|
||||
Self::extend_from_received_(&mut self.p2pk33, &other.p2pk33);
|
||||
Self::extend_from_received_(&mut self.p2pkh, &other.p2pkh);
|
||||
Self::extend_from_received_(&mut self.p2sh, &other.p2sh);
|
||||
Self::extend_from_received_(&mut self.p2wpkh, &other.p2wpkh);
|
||||
Self::extend_from_received_(&mut self.p2wsh, &other.p2wsh);
|
||||
Self::extend_from_received_(&mut self.p2tr, &other.p2tr);
|
||||
Self::extend_from_received_(&mut self.p2a, &other.p2a);
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn extend_from_received_(
|
||||
own: &mut Vec<(TypeIndex, OutputIndex)>,
|
||||
other: &[(
|
||||
TypeIndex,
|
||||
(
|
||||
OutputIndex,
|
||||
Sats,
|
||||
Option<WithAddressDataSource<AddressData>>,
|
||||
),
|
||||
)],
|
||||
) {
|
||||
own.extend(
|
||||
other
|
||||
.iter()
|
||||
.map(|(type_index, (output_index, ..))| (*type_index, *output_index)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::{cmp::Ordering, collections::BTreeMap, mem, path::Path, thread};
|
||||
|
||||
use brk_core::{
|
||||
AddressData, CheckedSub, DateIndex, Dollars, EmptyAddressData, Height, InputIndex, OutputIndex,
|
||||
OutputType, Result, Sats, StoredUsize, Version,
|
||||
AddressData, CheckedSub, DateIndex, Dollars, EmptyAddressData, GroupedByAddressType, Height,
|
||||
InputIndex, OutputIndex, OutputType, Result, Sats, Version,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
@@ -14,7 +14,15 @@ use log::info;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::{
|
||||
BlockState, GroupedByAddressType, SupplyState, Transacted, stores::Stores, vecs::market,
|
||||
BlockState, SupplyState, Transacted,
|
||||
stores::Stores,
|
||||
vecs::{
|
||||
market,
|
||||
stateful::{
|
||||
addresstype_to_addresscount::AddressTypeToAddressCount,
|
||||
addresstype_to_addresscount_vec::AddressTypeToAddressCountVec,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
use super::{
|
||||
@@ -25,6 +33,8 @@ use super::{
|
||||
|
||||
mod address_cohort;
|
||||
mod address_cohorts;
|
||||
mod addresstype_to_addresscount;
|
||||
mod addresstype_to_addresscount_vec;
|
||||
mod addresstype_to_typeindex_tree;
|
||||
mod addresstype_to_typeindex_vec;
|
||||
mod common;
|
||||
@@ -50,9 +60,8 @@ pub struct Vecs {
|
||||
pub indexes_to_opreturn_supply: ComputedValueVecsFromHeight,
|
||||
// pub height_to_address_count: EagerVec<Height, StoredUsize>,
|
||||
// pub height_to_empty_address_count: EagerVec<Height, StoredUsize>,
|
||||
pub addresstype_to_height_to_address_count: GroupedByAddressType<EagerVec<Height, StoredUsize>>,
|
||||
pub addresstype_to_height_to_empty_address_count:
|
||||
GroupedByAddressType<EagerVec<Height, StoredUsize>>,
|
||||
pub addresstype_to_height_to_address_count: AddressTypeToAddressCountVec,
|
||||
pub addresstype_to_height_to_empty_address_count: AddressTypeToAddressCountVec,
|
||||
pub utxo_vecs: utxo_cohorts::Vecs,
|
||||
pub address_vecs: address_cohorts::Vecs,
|
||||
}
|
||||
@@ -122,106 +131,110 @@ impl Vecs {
|
||||
// version + VERSION + Version::ZERO,
|
||||
// format,
|
||||
// )?,
|
||||
addresstype_to_height_to_address_count: GroupedByAddressType {
|
||||
p2pk65: EagerVec::forced_import(
|
||||
path,
|
||||
"p2pk65_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2pk33: EagerVec::forced_import(
|
||||
path,
|
||||
"p2pk33_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2pkh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2pkh_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2sh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2sh_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2wpkh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2wpkh_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2wsh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2wsh_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2tr: EagerVec::forced_import(
|
||||
path,
|
||||
"p2tr_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2a: EagerVec::forced_import(
|
||||
path,
|
||||
"p2a_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
},
|
||||
addresstype_to_height_to_empty_address_count: GroupedByAddressType {
|
||||
p2pk65: EagerVec::forced_import(
|
||||
path,
|
||||
"p2pk65_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2pk33: EagerVec::forced_import(
|
||||
path,
|
||||
"p2pk33_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2pkh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2pkh_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2sh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2sh_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2wpkh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2wpkh_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2wsh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2wsh_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2tr: EagerVec::forced_import(
|
||||
path,
|
||||
"p2tr_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2a: EagerVec::forced_import(
|
||||
path,
|
||||
"p2a_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
},
|
||||
addresstype_to_height_to_address_count: AddressTypeToAddressCountVec::from(
|
||||
GroupedByAddressType {
|
||||
p2pk65: EagerVec::forced_import(
|
||||
path,
|
||||
"p2pk65_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2pk33: EagerVec::forced_import(
|
||||
path,
|
||||
"p2pk33_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2pkh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2pkh_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2sh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2sh_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2wpkh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2wpkh_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2wsh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2wsh_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2tr: EagerVec::forced_import(
|
||||
path,
|
||||
"p2tr_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2a: EagerVec::forced_import(
|
||||
path,
|
||||
"p2a_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
},
|
||||
),
|
||||
addresstype_to_height_to_empty_address_count: AddressTypeToAddressCountVec::from(
|
||||
GroupedByAddressType {
|
||||
p2pk65: EagerVec::forced_import(
|
||||
path,
|
||||
"p2pk65_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2pk33: EagerVec::forced_import(
|
||||
path,
|
||||
"p2pk33_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2pkh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2pkh_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2sh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2sh_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2wpkh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2wpkh_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2wsh: EagerVec::forced_import(
|
||||
path,
|
||||
"p2wsh_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2tr: EagerVec::forced_import(
|
||||
path,
|
||||
"p2tr_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
p2a: EagerVec::forced_import(
|
||||
path,
|
||||
"p2a_empty_address_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
},
|
||||
),
|
||||
utxo_vecs: utxo_cohorts::Vecs::forced_import(
|
||||
path,
|
||||
version,
|
||||
@@ -439,21 +452,17 @@ impl Vecs {
|
||||
} else {
|
||||
Sats::ZERO
|
||||
};
|
||||
let mut addresstype_to_address_count = GroupedByAddressType::<usize>::from((
|
||||
let mut addresstype_to_address_count = AddressTypeToAddressCount::from((
|
||||
&self.addresstype_to_height_to_address_count,
|
||||
starting_height,
|
||||
));
|
||||
let mut addresstype_to_empty_address_count = GroupedByAddressType::<usize>::from((
|
||||
let mut addresstype_to_empty_address_count = AddressTypeToAddressCount::from((
|
||||
&self.addresstype_to_height_to_empty_address_count,
|
||||
starting_height,
|
||||
));
|
||||
|
||||
let mut height = starting_height;
|
||||
|
||||
let mut addresstype_to_typeindex_to_sent_outputindex =
|
||||
AddressTypeToTypeIndexVec::<OutputIndex>::default();
|
||||
let mut addresstype_to_typeindex_to_received_outputindex =
|
||||
AddressTypeToTypeIndexVec::<OutputIndex>::default();
|
||||
let mut addresstype_to_typeindex_to_addressdata =
|
||||
AddressTypeToTypeIndexTree::<WithAddressDataSource<AddressData>>::default();
|
||||
let mut addresstype_to_typeindex_to_emptyaddressdata =
|
||||
@@ -490,8 +499,8 @@ impl Vecs {
|
||||
let input_count = height_to_input_count_iter.unwrap_get_inner(height);
|
||||
|
||||
let (
|
||||
(mut height_to_sent, addresstype_to_typedindex_to_sent_outputindex, addresstype_to_typedindex_to_sent_data),
|
||||
(mut received, addresstype_to_typedindex_to_received_outputindex, addresstype_to_typedindex_to_received_data),
|
||||
(mut height_to_sent, addresstype_to_typedindex_to_sent_data),
|
||||
(mut received, addresstype_to_typedindex_to_received_data),
|
||||
) = thread::scope(|s| {
|
||||
if chain_state_starting_height <= height {
|
||||
s.spawn(|| {
|
||||
@@ -592,7 +601,6 @@ impl Vecs {
|
||||
value,
|
||||
input_type,
|
||||
typeindex,
|
||||
outputindex,
|
||||
addressdata_opt,
|
||||
prev_price,
|
||||
blocks_old,
|
||||
@@ -604,7 +612,6 @@ impl Vecs {
|
||||
|| {
|
||||
(
|
||||
BTreeMap::<Height, Transacted>::default(),
|
||||
AddressTypeToTypeIndexVec::<OutputIndex>::default(),
|
||||
AddressTypeToTypeIndexVec::<(
|
||||
Sats,
|
||||
Option<WithAddressDataSource<AddressData>>,
|
||||
@@ -616,13 +623,12 @@ impl Vecs {
|
||||
),
|
||||
)
|
||||
},
|
||||
|(mut tree, mut vecs, mut vecs2),
|
||||
|(mut tree, mut vecs),
|
||||
(
|
||||
height,
|
||||
value,
|
||||
input_type,
|
||||
typeindex,
|
||||
outputindex,
|
||||
addressdata_opt,
|
||||
prev_price,
|
||||
blocks_old,
|
||||
@@ -631,9 +637,6 @@ impl Vecs {
|
||||
)| {
|
||||
tree.entry(height).or_default().iterate(value, input_type);
|
||||
if let Some(vec) = vecs.get_mut(input_type) {
|
||||
vec.push((typeindex, outputindex));
|
||||
}
|
||||
if let Some(vec) = vecs2.get_mut(input_type) {
|
||||
vec.push((
|
||||
typeindex,
|
||||
(
|
||||
@@ -646,14 +649,13 @@ impl Vecs {
|
||||
),
|
||||
));
|
||||
}
|
||||
(tree, vecs, vecs2)
|
||||
(tree, vecs)
|
||||
},
|
||||
)
|
||||
.reduce(
|
||||
|| {
|
||||
(
|
||||
BTreeMap::<Height, Transacted>::default(),
|
||||
AddressTypeToTypeIndexVec::<OutputIndex>::default(),
|
||||
AddressTypeToTypeIndexVec::<(
|
||||
Sats,
|
||||
Option<WithAddressDataSource<AddressData>>,
|
||||
@@ -665,7 +667,7 @@ impl Vecs {
|
||||
),
|
||||
)
|
||||
},
|
||||
|(first_tree, mut source_vecs, mut source_vecs2), (second_tree, other_vecs, other_vecs2)| {
|
||||
|(first_tree, mut source_vecs), (second_tree, other_vecs)| {
|
||||
let (mut tree_source, tree_to_consume) =
|
||||
if first_tree.len() > second_tree.len() {
|
||||
(first_tree, second_tree)
|
||||
@@ -676,8 +678,7 @@ impl Vecs {
|
||||
*tree_source.entry(k).or_default() += v;
|
||||
});
|
||||
source_vecs.merge(other_vecs);
|
||||
source_vecs2.merge(other_vecs2);
|
||||
(tree_source, source_vecs, source_vecs2)
|
||||
(tree_source, source_vecs)
|
||||
},
|
||||
)
|
||||
});
|
||||
@@ -738,13 +739,12 @@ impl Vecs {
|
||||
None
|
||||
};
|
||||
|
||||
(value, output_type, typeindex, outputindex, addressdata_opt)
|
||||
(value, output_type, typeindex, addressdata_opt)
|
||||
})
|
||||
.fold(
|
||||
|| {
|
||||
(
|
||||
Transacted::default(),
|
||||
AddressTypeToTypeIndexVec::<OutputIndex>::default(),
|
||||
AddressTypeToTypeIndexVec::<(
|
||||
Sats,
|
||||
Option<WithAddressDataSource<AddressData>>,
|
||||
@@ -752,35 +752,27 @@ impl Vecs {
|
||||
),
|
||||
)
|
||||
},
|
||||
|(mut transacted, mut vecs, mut vecs2),
|
||||
|(mut transacted, mut vecs),
|
||||
(
|
||||
value,
|
||||
output_type,
|
||||
typeindex,
|
||||
outputindex,
|
||||
addressdata_opt,
|
||||
)| {
|
||||
transacted.iterate(value, output_type);
|
||||
if let Some(vec) = vecs.get_mut(output_type) {
|
||||
vec.push((
|
||||
typeindex,
|
||||
outputindex,
|
||||
));
|
||||
}
|
||||
if let Some(vec) = vecs2.get_mut(output_type) {
|
||||
vec.push((
|
||||
typeindex,
|
||||
(value, addressdata_opt),
|
||||
));
|
||||
}
|
||||
(transacted, vecs, vecs2)
|
||||
(transacted, vecs)
|
||||
},
|
||||
)
|
||||
.reduce(
|
||||
|| {
|
||||
(
|
||||
Transacted::default(),
|
||||
AddressTypeToTypeIndexVec::<OutputIndex>::default(),
|
||||
AddressTypeToTypeIndexVec::<(
|
||||
Sats,
|
||||
Option<WithAddressDataSource<AddressData>>,
|
||||
@@ -788,10 +780,9 @@ impl Vecs {
|
||||
),
|
||||
)
|
||||
},
|
||||
|(transacted, mut vecs, mut vecs2), (other_transacted, other_vecs, other_vecs2)| {
|
||||
|(transacted, mut vecs), (other_transacted, other_vecs)| {
|
||||
vecs.merge(other_vecs);
|
||||
vecs2.merge(other_vecs2);
|
||||
(transacted + other_transacted, vecs, vecs2)
|
||||
(transacted + other_transacted, vecs)
|
||||
},
|
||||
)
|
||||
});
|
||||
@@ -829,12 +820,6 @@ impl Vecs {
|
||||
};
|
||||
|
||||
thread::scope(|scope| -> Result<()> {
|
||||
scope.spawn(|| addresstype_to_typeindex_to_sent_outputindex
|
||||
.merge(addresstype_to_typedindex_to_sent_outputindex));
|
||||
|
||||
scope.spawn(|| addresstype_to_typeindex_to_received_outputindex
|
||||
.merge(addresstype_to_typedindex_to_received_outputindex));
|
||||
|
||||
scope.spawn(|| {
|
||||
// Push current block state before processing sends and receives
|
||||
chain_state.push(BlockState {
|
||||
@@ -956,8 +941,6 @@ impl Vecs {
|
||||
self.flush_states(height, &chain_state, exit)?;
|
||||
stores.commit(
|
||||
height,
|
||||
mem::take(&mut addresstype_to_typeindex_to_sent_outputindex),
|
||||
mem::take(&mut addresstype_to_typeindex_to_received_outputindex),
|
||||
mem::take(&mut addresstype_to_typeindex_to_addressdata),
|
||||
mem::take(&mut addresstype_to_typeindex_to_emptyaddressdata),
|
||||
)?;
|
||||
@@ -974,8 +957,6 @@ impl Vecs {
|
||||
self.flush_states(height, &chain_state, exit)?;
|
||||
stores.commit(
|
||||
height,
|
||||
mem::take(&mut addresstype_to_typeindex_to_sent_outputindex),
|
||||
mem::take(&mut addresstype_to_typeindex_to_received_outputindex),
|
||||
mem::take(&mut addresstype_to_typeindex_to_addressdata),
|
||||
mem::take(&mut addresstype_to_typeindex_to_emptyaddressdata),
|
||||
)?;
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
use std::{collections::BTreeMap, ops::ControlFlow, path::Path};
|
||||
|
||||
use brk_core::{CheckedSub, Dollars, HalvingEpoch, Height, Result, Timestamp, Version};
|
||||
use brk_core::{
|
||||
CheckedSub, Dollars, GroupFilter, GroupedByDateRange, GroupedByEpoch, GroupedByFromDate,
|
||||
GroupedByFromSize, GroupedBySizeRange, GroupedBySpendableType, GroupedByTerm,
|
||||
GroupedByUpToDate, GroupedByUpToSize, HalvingEpoch, Height, Result, Timestamp, UTXOGroups,
|
||||
Version,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use brk_vec::{Computation, Format, StoredIndex};
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::{
|
||||
GroupFilter, GroupedByDateRange, GroupedByEpoch, GroupedByFromDate, GroupedByFromSize,
|
||||
GroupedBySizeRange, GroupedBySpendableType, GroupedByTerm, GroupedByUpToDate,
|
||||
GroupedByUpToSize, UTXOGroups,
|
||||
states::{BlockState, Transacted},
|
||||
vecs::{Indexes, fetched},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user