mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-07 20:59:09 -07:00
computer: store part 6
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
use crate::{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,170 +0,0 @@
|
||||
use std::{
|
||||
mem,
|
||||
ops::{Add, AddAssign},
|
||||
};
|
||||
|
||||
use crate::OutputType;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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 crate::{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 crate::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 crate::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 crate::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 crate::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 crate::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 crate::{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),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
#![doc = include_str!("../README.md")]
|
||||
|
||||
mod error;
|
||||
mod groups;
|
||||
mod structs;
|
||||
mod traits;
|
||||
mod utils;
|
||||
|
||||
pub use error::*;
|
||||
pub use groups::*;
|
||||
pub use structs::*;
|
||||
pub use traits::*;
|
||||
pub use utils::*;
|
||||
|
||||
@@ -19,16 +19,13 @@ impl AddressData {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
if self.amount() == Sats::ZERO {
|
||||
if self.outputs_len != 0 {
|
||||
unreachable!();
|
||||
}
|
||||
pub fn has_0_sats(&self) -> bool {
|
||||
self.amount() == Sats::ZERO
|
||||
}
|
||||
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn has_0_utxos(&self) -> bool {
|
||||
self.outputs_len == 0
|
||||
}
|
||||
|
||||
pub fn receive(&mut self, amount: Sats, price: Option<Dollars>) {
|
||||
|
||||
@@ -75,6 +75,10 @@ impl Timestamp {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_more_than_hour(&self) -> bool {
|
||||
jiff::Timestamp::from(*self).as_second() >= 60 * 60
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u32> for Timestamp {
|
||||
|
||||
Reference in New Issue
Block a user