mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-26 17:54:44 -07:00
server: api doc part 4
This commit is contained in:
15
crates/brk_grouper/Cargo.toml
Normal file
15
crates/brk_grouper/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "brk_grouper"
|
||||
description = "Groups used throughout BRK"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
rust-version.workspace = true
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
brk_structs = { workspace = true }
|
||||
brk_traversable = { workspace = true }
|
||||
vecdb = { workspace = true }
|
||||
1
crates/brk_grouper/README.md
Normal file
1
crates/brk_grouper/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# brk_grouper
|
||||
8
crates/brk_grouper/build.rs
Normal file
8
crates/brk_grouper/build.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
let profile = std::env::var("PROFILE").unwrap_or_default();
|
||||
|
||||
if profile == "release" {
|
||||
println!("cargo:rustc-flag=-C");
|
||||
println!("cargo:rustc-flag=target-cpu=native");
|
||||
}
|
||||
}
|
||||
83
crates/brk_grouper/src/address.rs
Normal file
83
crates/brk_grouper/src/address.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use crate::Filtered;
|
||||
|
||||
use super::{ByAmountRange, ByGreatEqualAmount, ByLowerThanAmount};
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct AddressGroups<T> {
|
||||
pub ge_amount: ByGreatEqualAmount<T>,
|
||||
pub amount_range: ByAmountRange<T>,
|
||||
pub lt_amount: ByLowerThanAmount<T>,
|
||||
}
|
||||
|
||||
impl<T> AddressGroups<T> {
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
self.ge_amount
|
||||
.iter_mut()
|
||||
.chain(self.amount_range.iter_mut())
|
||||
.chain(self.lt_amount.iter_mut())
|
||||
}
|
||||
|
||||
pub fn iter_separate_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
self.amount_range.iter_mut()
|
||||
}
|
||||
|
||||
pub fn iter_overlapping_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
self.lt_amount.iter_mut().chain(self.ge_amount.iter_mut())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AddressGroups<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
self.amount_range
|
||||
.iter_right()
|
||||
.chain(self.lt_amount.iter_right())
|
||||
.chain(self.ge_amount.iter_right())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<AddressGroups<T>> for AddressGroups<Filtered<T>> {
|
||||
fn from(value: AddressGroups<T>) -> Self {
|
||||
Self {
|
||||
amount_range: ByAmountRange::from(value.amount_range),
|
||||
lt_amount: ByLowerThanAmount::from(value.lt_amount),
|
||||
ge_amount: ByGreatEqualAmount::from(value.ge_amount),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Traversable for AddressGroups<T>
|
||||
where
|
||||
ByGreatEqualAmount<T>: brk_traversable::Traversable,
|
||||
ByAmountRange<T>: brk_traversable::Traversable,
|
||||
ByLowerThanAmount<T>: brk_traversable::Traversable,
|
||||
T: Send + Sync,
|
||||
{
|
||||
fn to_tree_node(&self) -> brk_traversable::TreeNode {
|
||||
brk_traversable::TreeNode::Branch(
|
||||
[
|
||||
(String::from("ge_amount"), self.ge_amount.to_tree_node()),
|
||||
(
|
||||
String::from("amount_range"),
|
||||
self.amount_range.to_tree_node(),
|
||||
),
|
||||
(String::from("lt_amount"), self.lt_amount.to_tree_node()),
|
||||
]
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn vecdb::AnyCollectableVec> {
|
||||
[
|
||||
Box::new(self.ge_amount.iter_any_collectable())
|
||||
as Box<dyn Iterator<Item = &dyn vecdb::AnyCollectableVec>>,
|
||||
Box::new(self.amount_range.iter_any_collectable())
|
||||
as Box<dyn Iterator<Item = &dyn vecdb::AnyCollectableVec>>,
|
||||
Box::new(self.lt_amount.iter_any_collectable())
|
||||
as Box<dyn Iterator<Item = &dyn vecdb::AnyCollectableVec>>,
|
||||
]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
}
|
||||
}
|
||||
230
crates/brk_grouper/src/by_address_type.rs
Normal file
230
crates/brk_grouper/src/by_address_type.rs
Normal file
@@ -0,0 +1,230 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
use brk_structs::OutputType;
|
||||
use brk_traversable::{Traversable, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
|
||||
use super::{Filter, Filtered};
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct ByAddressType<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> ByAddressType<T> {
|
||||
pub fn get_unwrap(&self, address_type: OutputType) -> &T {
|
||||
self.get(address_type).unwrap()
|
||||
}
|
||||
|
||||
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 iter(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self.p2pk65,
|
||||
&self.p2pk33,
|
||||
&self.p2pkh,
|
||||
&self.p2sh,
|
||||
&self.p2wpkh,
|
||||
&self.p2wsh,
|
||||
&self.p2tr,
|
||||
&self.p2a,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
[
|
||||
&mut self.p2pk65,
|
||||
&mut self.p2pk33,
|
||||
&mut self.p2pkh,
|
||||
&mut self.p2sh,
|
||||
&mut self.p2wpkh,
|
||||
&mut self.p2wsh,
|
||||
&mut self.p2tr,
|
||||
&mut self.p2a,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
||||
pub fn iter_typed(&self) -> impl Iterator<Item = (OutputType, &T)> {
|
||||
[
|
||||
(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),
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
||||
pub fn into_iter_typed(self) -> impl Iterator<Item = (OutputType, T)> {
|
||||
[
|
||||
(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),
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
||||
pub fn iter_typed_mut(&mut self) -> impl Iterator<Item = (OutputType, &mut T)> {
|
||||
[
|
||||
(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),
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByAddressType<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self.p2pk65.1,
|
||||
&self.p2pk33.1,
|
||||
&self.p2pkh.1,
|
||||
&self.p2sh.1,
|
||||
&self.p2wpkh.1,
|
||||
&self.p2wsh.1,
|
||||
&self.p2tr.1,
|
||||
&self.p2a.1,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<ByAddressType<T>> for ByAddressType<Filtered<T>> {
|
||||
fn from(value: ByAddressType<T>) -> Self {
|
||||
Self {
|
||||
p2pk65: (Filter::Type(OutputType::P2PK65), value.p2pk65).into(),
|
||||
p2pk33: (Filter::Type(OutputType::P2PK33), value.p2pk33).into(),
|
||||
p2pkh: (Filter::Type(OutputType::P2PKH), value.p2pkh).into(),
|
||||
p2sh: (Filter::Type(OutputType::P2SH), value.p2sh).into(),
|
||||
p2wpkh: (Filter::Type(OutputType::P2WPKH), value.p2wpkh).into(),
|
||||
p2wsh: (Filter::Type(OutputType::P2WSH), value.p2wsh).into(),
|
||||
p2tr: (Filter::Type(OutputType::P2TR), value.p2tr).into(),
|
||||
p2a: (Filter::Type(OutputType::P2A), value.p2a).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Add for ByAddressType<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 ByAddressType<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<T> ByAddressType<Option<T>> {
|
||||
pub fn take(&mut self) {
|
||||
self.iter_mut().for_each(|opt| {
|
||||
opt.take();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Traversable> Traversable for ByAddressType<T> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[
|
||||
("p2pk65", &self.p2pk65),
|
||||
("p2pk33", &self.p2pk33),
|
||||
("p2pkh", &self.p2pkh),
|
||||
("p2sh", &self.p2sh),
|
||||
("p2wpkh", &self.p2wpkh),
|
||||
("p2wsh", &self.p2wsh),
|
||||
("p2tr", &self.p2tr),
|
||||
("p2a", &self.p2a),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, field)| (name.to_string(), field.to_tree_node()))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
|
||||
Box::new(self.p2pk65.iter_any_collectable());
|
||||
iter = Box::new(iter.chain(self.p2pk33.iter_any_collectable()));
|
||||
iter = Box::new(iter.chain(self.p2pkh.iter_any_collectable()));
|
||||
iter = Box::new(iter.chain(self.p2sh.iter_any_collectable()));
|
||||
iter = Box::new(iter.chain(self.p2wpkh.iter_any_collectable()));
|
||||
iter = Box::new(iter.chain(self.p2wsh.iter_any_collectable()));
|
||||
iter = Box::new(iter.chain(self.p2tr.iter_any_collectable()));
|
||||
iter = Box::new(iter.chain(self.p2a.iter_any_collectable()));
|
||||
iter
|
||||
}
|
||||
}
|
||||
138
crates/brk_grouper/src/by_age_range.rs
Normal file
138
crates/brk_grouper/src/by_age_range.rs
Normal file
@@ -0,0 +1,138 @@
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use crate::Filtered;
|
||||
|
||||
use super::Filter;
|
||||
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct ByAgeRange<T> {
|
||||
pub up_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_12y: T,
|
||||
pub _12y_to_15y: T,
|
||||
pub from_15y: T,
|
||||
}
|
||||
|
||||
impl<T> From<ByAgeRange<T>> for ByAgeRange<Filtered<T>> {
|
||||
fn from(value: ByAgeRange<T>) -> Self {
|
||||
Self {
|
||||
up_to_1d: (Filter::LowerThan(1), value.up_to_1d).into(),
|
||||
_1d_to_1w: (Filter::Range(1..7), value._1d_to_1w).into(),
|
||||
_1w_to_1m: (Filter::Range(7..30), value._1w_to_1m).into(),
|
||||
_1m_to_2m: (Filter::Range(30..2 * 30), value._1m_to_2m).into(),
|
||||
_2m_to_3m: (Filter::Range(2 * 30..3 * 30), value._2m_to_3m).into(),
|
||||
_3m_to_4m: (Filter::Range(3 * 30..4 * 30), value._3m_to_4m).into(),
|
||||
_4m_to_5m: (Filter::Range(4 * 30..5 * 30), value._4m_to_5m).into(),
|
||||
_5m_to_6m: (Filter::Range(5 * 30..6 * 30), value._5m_to_6m).into(),
|
||||
_6m_to_1y: (Filter::Range(6 * 30..365), value._6m_to_1y).into(),
|
||||
_1y_to_2y: (Filter::Range(365..2 * 365), value._1y_to_2y).into(),
|
||||
_2y_to_3y: (Filter::Range(2 * 365..3 * 365), value._2y_to_3y).into(),
|
||||
_3y_to_4y: (Filter::Range(3 * 365..4 * 365), value._3y_to_4y).into(),
|
||||
_4y_to_5y: (Filter::Range(4 * 365..5 * 365), value._4y_to_5y).into(),
|
||||
_5y_to_6y: (Filter::Range(5 * 365..6 * 365), value._5y_to_6y).into(),
|
||||
_6y_to_7y: (Filter::Range(6 * 365..7 * 365), value._6y_to_7y).into(),
|
||||
_7y_to_8y: (Filter::Range(7 * 365..8 * 365), value._7y_to_8y).into(),
|
||||
_8y_to_10y: (Filter::Range(8 * 365..10 * 365), value._8y_to_10y).into(),
|
||||
_10y_to_12y: (Filter::Range(10 * 365..12 * 365), value._10y_to_12y).into(),
|
||||
_12y_to_15y: (Filter::Range(12 * 365..15 * 365), value._12y_to_15y).into(),
|
||||
from_15y: (Filter::GreaterOrEqual(15 * 365), value.from_15y).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByAgeRange<T> {
|
||||
pub fn iter(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self.up_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_12y,
|
||||
&self._12y_to_15y,
|
||||
&self.from_15y,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
[
|
||||
&mut self.up_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_12y,
|
||||
&mut self._12y_to_15y,
|
||||
&mut self.from_15y,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByAgeRange<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self.up_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_12y.1,
|
||||
&self._12y_to_15y.1,
|
||||
&self.from_15y.1,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
276
crates/brk_grouper/src/by_amount_range.rs
Normal file
276
crates/brk_grouper/src/by_amount_range.rs
Normal file
@@ -0,0 +1,276 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
use brk_structs::Sats;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use super::{Filter, Filtered};
|
||||
|
||||
#[derive(Debug, Default, Clone, Traversable)]
|
||||
pub struct ByAmountRange<T> {
|
||||
pub _0sats: T,
|
||||
pub _1sat_to_10sats: T,
|
||||
pub _10sats_to_100sats: T,
|
||||
pub _100sats_to_1k_sats: T,
|
||||
pub _1k_sats_to_10k_sats: T,
|
||||
pub _10k_sats_to_100k_sats: T,
|
||||
pub _100k_sats_to_1m_sats: T,
|
||||
pub _1m_sats_to_10m_sats: T,
|
||||
pub _10m_sats_to_1btc: T,
|
||||
pub _1btc_to_10btc: T,
|
||||
pub _10btc_to_100btc: T,
|
||||
pub _100btc_to_1k_btc: T,
|
||||
pub _1k_btc_to_10k_btc: T,
|
||||
pub _10k_btc_to_100k_btc: T,
|
||||
pub _100k_btc_or_more: T,
|
||||
}
|
||||
|
||||
impl<T> From<ByAmountRange<T>> for ByAmountRange<Filtered<T>> {
|
||||
fn from(value: ByAmountRange<T>) -> Self {
|
||||
#[allow(clippy::inconsistent_digit_grouping)]
|
||||
Self {
|
||||
_0sats: (Filter::LowerThan(Sats::_1.into()), value._0sats).into(),
|
||||
_1sat_to_10sats: (
|
||||
Filter::Range(Sats::_1.into()..Sats::_10.into()),
|
||||
value._1sat_to_10sats,
|
||||
)
|
||||
.into(),
|
||||
_10sats_to_100sats: (
|
||||
Filter::Range(Sats::_10.into()..Sats::_100.into()),
|
||||
value._10sats_to_100sats,
|
||||
)
|
||||
.into(),
|
||||
_100sats_to_1k_sats: (
|
||||
Filter::Range(Sats::_100.into()..Sats::_1K.into()),
|
||||
value._100sats_to_1k_sats,
|
||||
)
|
||||
.into(),
|
||||
_1k_sats_to_10k_sats: (
|
||||
Filter::Range(Sats::_1K.into()..Sats::_10K.into()),
|
||||
value._1k_sats_to_10k_sats,
|
||||
)
|
||||
.into(),
|
||||
_10k_sats_to_100k_sats: (
|
||||
Filter::Range(Sats::_10K.into()..Sats::_100K.into()),
|
||||
value._10k_sats_to_100k_sats,
|
||||
)
|
||||
.into(),
|
||||
_100k_sats_to_1m_sats: (
|
||||
Filter::Range(Sats::_100K.into()..Sats::_1M.into()),
|
||||
value._100k_sats_to_1m_sats,
|
||||
)
|
||||
.into(),
|
||||
_1m_sats_to_10m_sats: (
|
||||
Filter::Range(Sats::_1M.into()..Sats::_10M.into()),
|
||||
value._1m_sats_to_10m_sats,
|
||||
)
|
||||
.into(),
|
||||
_10m_sats_to_1btc: (
|
||||
Filter::Range(Sats::_10M.into()..Sats::_1BTC.into()),
|
||||
value._10m_sats_to_1btc,
|
||||
)
|
||||
.into(),
|
||||
_1btc_to_10btc: (
|
||||
Filter::Range(Sats::_1BTC.into()..Sats::_10BTC.into()),
|
||||
value._1btc_to_10btc,
|
||||
)
|
||||
.into(),
|
||||
_10btc_to_100btc: (
|
||||
Filter::Range(Sats::_10BTC.into()..Sats::_100BTC.into()),
|
||||
value._10btc_to_100btc,
|
||||
)
|
||||
.into(),
|
||||
_100btc_to_1k_btc: (
|
||||
Filter::Range(Sats::_100BTC.into()..Sats::_1K_BTC.into()),
|
||||
value._100btc_to_1k_btc,
|
||||
)
|
||||
.into(),
|
||||
_1k_btc_to_10k_btc: (
|
||||
Filter::Range(Sats::_1K_BTC.into()..Sats::_10K_BTC.into()),
|
||||
value._1k_btc_to_10k_btc,
|
||||
)
|
||||
.into(),
|
||||
_10k_btc_to_100k_btc: (
|
||||
Filter::Range(Sats::_10K_BTC.into()..Sats::_100K_BTC.into()),
|
||||
value._10k_btc_to_100k_btc,
|
||||
)
|
||||
.into(),
|
||||
_100k_btc_or_more: (
|
||||
Filter::GreaterOrEqual(Sats::_100K_BTC.into()),
|
||||
value._100k_btc_or_more,
|
||||
)
|
||||
.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByAmountRange<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._1sat_to_10sats
|
||||
} else if value < Sats::_100 {
|
||||
&mut self._10sats_to_100sats
|
||||
} else if value < Sats::_1K {
|
||||
&mut self._100sats_to_1k_sats
|
||||
} else if value < Sats::_10K {
|
||||
&mut self._1k_sats_to_10k_sats
|
||||
} else if value < Sats::_100K {
|
||||
&mut self._10k_sats_to_100k_sats
|
||||
} else if value < Sats::_1M {
|
||||
&mut self._100k_sats_to_1m_sats
|
||||
} else if value < Sats::_10M {
|
||||
&mut self._1m_sats_to_10m_sats
|
||||
} else if value < Sats::_1BTC {
|
||||
&mut self._10m_sats_to_1btc
|
||||
} else if value < Sats::_10BTC {
|
||||
&mut self._1btc_to_10btc
|
||||
} else if value < Sats::_100BTC {
|
||||
&mut self._10btc_to_100btc
|
||||
} else if value < Sats::_1K_BTC {
|
||||
&mut self._100btc_to_1k_btc
|
||||
} else if value < Sats::_10K_BTC {
|
||||
&mut self._1k_btc_to_10k_btc
|
||||
} else if value < Sats::_100K_BTC {
|
||||
&mut self._10k_btc_to_100k_btc
|
||||
} else {
|
||||
&mut self._100k_btc_or_more
|
||||
}
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self._0sats,
|
||||
&self._1sat_to_10sats,
|
||||
&self._10sats_to_100sats,
|
||||
&self._100sats_to_1k_sats,
|
||||
&self._1k_sats_to_10k_sats,
|
||||
&self._10k_sats_to_100k_sats,
|
||||
&self._100k_sats_to_1m_sats,
|
||||
&self._1m_sats_to_10m_sats,
|
||||
&self._10m_sats_to_1btc,
|
||||
&self._1btc_to_10btc,
|
||||
&self._10btc_to_100btc,
|
||||
&self._100btc_to_1k_btc,
|
||||
&self._1k_btc_to_10k_btc,
|
||||
&self._10k_btc_to_100k_btc,
|
||||
&self._100k_btc_or_more,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
||||
pub fn iter_typed(&self) -> impl Iterator<Item = (Sats, &T)> {
|
||||
[
|
||||
(Sats::ZERO, &self._0sats),
|
||||
(Sats::_1, &self._1sat_to_10sats),
|
||||
(Sats::_10, &self._10sats_to_100sats),
|
||||
(Sats::_100, &self._100sats_to_1k_sats),
|
||||
(Sats::_1K, &self._1k_sats_to_10k_sats),
|
||||
(Sats::_10K, &self._10k_sats_to_100k_sats),
|
||||
(Sats::_100K, &self._100k_sats_to_1m_sats),
|
||||
(Sats::_1M, &self._1m_sats_to_10m_sats),
|
||||
(Sats::_10M, &self._10m_sats_to_1btc),
|
||||
(Sats::_1BTC, &self._1btc_to_10btc),
|
||||
(Sats::_10BTC, &self._10btc_to_100btc),
|
||||
(Sats::_100BTC, &self._100btc_to_1k_btc),
|
||||
(Sats::_1K_BTC, &self._1k_btc_to_10k_btc),
|
||||
(Sats::_10K_BTC, &self._10k_btc_to_100k_btc),
|
||||
(Sats::_100K_BTC, &self._100k_btc_or_more),
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
[
|
||||
&mut self._0sats,
|
||||
&mut self._1sat_to_10sats,
|
||||
&mut self._10sats_to_100sats,
|
||||
&mut self._100sats_to_1k_sats,
|
||||
&mut self._1k_sats_to_10k_sats,
|
||||
&mut self._10k_sats_to_100k_sats,
|
||||
&mut self._100k_sats_to_1m_sats,
|
||||
&mut self._1m_sats_to_10m_sats,
|
||||
&mut self._10m_sats_to_1btc,
|
||||
&mut self._1btc_to_10btc,
|
||||
&mut self._10btc_to_100btc,
|
||||
&mut self._100btc_to_1k_btc,
|
||||
&mut self._1k_btc_to_10k_btc,
|
||||
&mut self._10k_btc_to_100k_btc,
|
||||
&mut self._100k_btc_or_more,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByAmountRange<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self._0sats.1,
|
||||
&self._1sat_to_10sats.1,
|
||||
&self._10sats_to_100sats.1,
|
||||
&self._100sats_to_1k_sats.1,
|
||||
&self._1k_sats_to_10k_sats.1,
|
||||
&self._10k_sats_to_100k_sats.1,
|
||||
&self._100k_sats_to_1m_sats.1,
|
||||
&self._1m_sats_to_10m_sats.1,
|
||||
&self._10m_sats_to_1btc.1,
|
||||
&self._1btc_to_10btc.1,
|
||||
&self._10btc_to_100btc.1,
|
||||
&self._100btc_to_1k_btc.1,
|
||||
&self._1k_btc_to_10k_btc.1,
|
||||
&self._10k_btc_to_100k_btc.1,
|
||||
&self._100k_btc_or_more.1,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Add for ByAmountRange<T>
|
||||
where
|
||||
T: Add<Output = T>,
|
||||
{
|
||||
type Output = Self;
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self {
|
||||
_0sats: self._0sats + rhs._0sats,
|
||||
_1sat_to_10sats: self._1sat_to_10sats + rhs._1sat_to_10sats,
|
||||
_10sats_to_100sats: self._10sats_to_100sats + rhs._10sats_to_100sats,
|
||||
_100sats_to_1k_sats: self._100sats_to_1k_sats + rhs._100sats_to_1k_sats,
|
||||
_1k_sats_to_10k_sats: self._1k_sats_to_10k_sats + rhs._1k_sats_to_10k_sats,
|
||||
_10k_sats_to_100k_sats: self._10k_sats_to_100k_sats + rhs._10k_sats_to_100k_sats,
|
||||
_100k_sats_to_1m_sats: self._100k_sats_to_1m_sats + rhs._100k_sats_to_1m_sats,
|
||||
_1m_sats_to_10m_sats: self._1m_sats_to_10m_sats + rhs._1m_sats_to_10m_sats,
|
||||
_10m_sats_to_1btc: self._10m_sats_to_1btc + rhs._10m_sats_to_1btc,
|
||||
_1btc_to_10btc: self._1btc_to_10btc + rhs._1btc_to_10btc,
|
||||
_10btc_to_100btc: self._10btc_to_100btc + rhs._10btc_to_100btc,
|
||||
_100btc_to_1k_btc: self._100btc_to_1k_btc + rhs._100btc_to_1k_btc,
|
||||
_1k_btc_to_10k_btc: self._1k_btc_to_10k_btc + rhs._1k_btc_to_10k_btc,
|
||||
_10k_btc_to_100k_btc: self._10k_btc_to_100k_btc + rhs._10k_btc_to_100k_btc,
|
||||
_100k_btc_or_more: self._100k_btc_or_more + rhs._100k_btc_or_more,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AddAssign for ByAmountRange<T>
|
||||
where
|
||||
T: AddAssign,
|
||||
{
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
self._0sats += rhs._0sats;
|
||||
self._1sat_to_10sats += rhs._1sat_to_10sats;
|
||||
self._10sats_to_100sats += rhs._10sats_to_100sats;
|
||||
self._100sats_to_1k_sats += rhs._100sats_to_1k_sats;
|
||||
self._1k_sats_to_10k_sats += rhs._1k_sats_to_10k_sats;
|
||||
self._10k_sats_to_100k_sats += rhs._10k_sats_to_100k_sats;
|
||||
self._100k_sats_to_1m_sats += rhs._100k_sats_to_1m_sats;
|
||||
self._1m_sats_to_10m_sats += rhs._1m_sats_to_10m_sats;
|
||||
self._10m_sats_to_1btc += rhs._10m_sats_to_1btc;
|
||||
self._1btc_to_10btc += rhs._1btc_to_10btc;
|
||||
self._10btc_to_100btc += rhs._10btc_to_100btc;
|
||||
self._100btc_to_1k_btc += rhs._100btc_to_1k_btc;
|
||||
self._1k_btc_to_10k_btc += rhs._1k_btc_to_10k_btc;
|
||||
self._10k_btc_to_100k_btc += rhs._10k_btc_to_100k_btc;
|
||||
self._100k_btc_or_more += rhs._100k_btc_or_more;
|
||||
}
|
||||
}
|
||||
14
crates/brk_grouper/src/by_any_address.rs
Normal file
14
crates/brk_grouper/src/by_any_address.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
#[derive(Debug, Default, Traversable)]
|
||||
pub struct ByAnyAddress<T> {
|
||||
pub loaded: T,
|
||||
pub empty: T,
|
||||
}
|
||||
|
||||
impl<T> ByAnyAddress<Option<T>> {
|
||||
pub fn take(&mut self) {
|
||||
self.loaded.take();
|
||||
self.empty.take();
|
||||
}
|
||||
}
|
||||
61
crates/brk_grouper/src/by_epoch.rs
Normal file
61
crates/brk_grouper/src/by_epoch.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use brk_structs::{HalvingEpoch, Height};
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use super::{Filter, Filtered};
|
||||
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct ByEpoch<T> {
|
||||
pub _0: T,
|
||||
pub _1: T,
|
||||
pub _2: T,
|
||||
pub _3: T,
|
||||
pub _4: T,
|
||||
}
|
||||
|
||||
impl<T> From<ByEpoch<T>> for ByEpoch<Filtered<T>> {
|
||||
fn from(value: ByEpoch<T>) -> Self {
|
||||
Self {
|
||||
_0: (Filter::Epoch(HalvingEpoch::new(0)), value._0).into(),
|
||||
_1: (Filter::Epoch(HalvingEpoch::new(1)), value._1).into(),
|
||||
_2: (Filter::Epoch(HalvingEpoch::new(2)), value._2).into(),
|
||||
_3: (Filter::Epoch(HalvingEpoch::new(3)), value._3).into(),
|
||||
_4: (Filter::Epoch(HalvingEpoch::new(4)), value._4).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByEpoch<T> {
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
[
|
||||
&mut self._0,
|
||||
&mut self._1,
|
||||
&mut self._2,
|
||||
&mut self._3,
|
||||
&mut self._4,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
||||
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> ByEpoch<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[&self._0.1, &self._1.1, &self._2.1, &self._3.1, &self._4.1].into_iter()
|
||||
}
|
||||
}
|
||||
87
crates/brk_grouper/src/by_ge_amount.rs
Normal file
87
crates/brk_grouper/src/by_ge_amount.rs
Normal file
@@ -0,0 +1,87 @@
|
||||
use brk_structs::Sats;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use super::{Filter, Filtered};
|
||||
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct ByGreatEqualAmount<T> {
|
||||
pub _1sat: T,
|
||||
pub _10sats: T,
|
||||
pub _100sats: T,
|
||||
pub _1k_sats: T,
|
||||
pub _10k_sats: T,
|
||||
pub _100k_sats: T,
|
||||
pub _1m_sats: T,
|
||||
pub _10m_sats: T,
|
||||
pub _1btc: T,
|
||||
pub _10btc: T,
|
||||
pub _100btc: T,
|
||||
pub _1k_btc: T,
|
||||
pub _10k_btc: T,
|
||||
}
|
||||
|
||||
impl<T> ByGreatEqualAmount<T> {
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
[
|
||||
&mut self._1sat,
|
||||
&mut self._10sats,
|
||||
&mut self._100sats,
|
||||
&mut self._1k_sats,
|
||||
&mut self._10k_sats,
|
||||
&mut self._100k_sats,
|
||||
&mut self._1m_sats,
|
||||
&mut self._10m_sats,
|
||||
&mut self._1btc,
|
||||
&mut self._10btc,
|
||||
&mut self._100btc,
|
||||
&mut self._1k_btc,
|
||||
&mut self._10k_btc,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByGreatEqualAmount<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self._1sat.1,
|
||||
&self._10sats.1,
|
||||
&self._100sats.1,
|
||||
&self._1k_sats.1,
|
||||
&self._10k_sats.1,
|
||||
&self._100k_sats.1,
|
||||
&self._1m_sats.1,
|
||||
&self._10m_sats.1,
|
||||
&self._1btc.1,
|
||||
&self._10btc.1,
|
||||
&self._100btc.1,
|
||||
&self._1k_btc.1,
|
||||
&self._10k_btc.1,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<ByGreatEqualAmount<T>> for ByGreatEqualAmount<Filtered<T>> {
|
||||
fn from(value: ByGreatEqualAmount<T>) -> Self {
|
||||
Self {
|
||||
_1sat: (Filter::GreaterOrEqual(Sats::_1.into()), value._1sat).into(),
|
||||
_10sats: (Filter::GreaterOrEqual(Sats::_10.into()), value._10sats).into(),
|
||||
_100sats: (Filter::GreaterOrEqual(Sats::_100.into()), value._100sats).into(),
|
||||
_1k_sats: (Filter::GreaterOrEqual(Sats::_1K.into()), value._1k_sats).into(),
|
||||
_10k_sats: (Filter::GreaterOrEqual(Sats::_10K.into()), value._10k_sats).into(),
|
||||
_100k_sats: (Filter::GreaterOrEqual(Sats::_100K.into()), value._100k_sats).into(),
|
||||
_1m_sats: (Filter::GreaterOrEqual(Sats::_1M.into()), value._1m_sats).into(),
|
||||
_10m_sats: (Filter::GreaterOrEqual(Sats::_10M.into()), value._10m_sats).into(),
|
||||
_1btc: (Filter::GreaterOrEqual(Sats::_1BTC.into()), value._1btc).into(),
|
||||
_10btc: (Filter::GreaterOrEqual(Sats::_10BTC.into()), value._10btc).into(),
|
||||
_100btc: (Filter::GreaterOrEqual(Sats::_100BTC.into()), value._100btc).into(),
|
||||
_1k_btc: (Filter::GreaterOrEqual(Sats::_1K_BTC.into()), value._1k_btc).into(),
|
||||
_10k_btc: (
|
||||
Filter::GreaterOrEqual(Sats::_10K_BTC.into()),
|
||||
value._10k_btc,
|
||||
)
|
||||
.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
83
crates/brk_grouper/src/by_lt_amount.rs
Normal file
83
crates/brk_grouper/src/by_lt_amount.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
use brk_structs::Sats;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use super::{Filter, Filtered};
|
||||
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct ByLowerThanAmount<T> {
|
||||
pub _10sats: T,
|
||||
pub _100sats: T,
|
||||
pub _1k_sats: T,
|
||||
pub _10k_sats: T,
|
||||
pub _100k_sats: T,
|
||||
pub _1m_sats: T,
|
||||
pub _10m_sats: T,
|
||||
pub _1btc: T,
|
||||
pub _10btc: T,
|
||||
pub _100btc: T,
|
||||
pub _1k_btc: T,
|
||||
pub _10k_btc: T,
|
||||
pub _100k_btc: T,
|
||||
}
|
||||
|
||||
impl<T> ByLowerThanAmount<T> {
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
[
|
||||
&mut self._10sats,
|
||||
&mut self._100sats,
|
||||
&mut self._1k_sats,
|
||||
&mut self._10k_sats,
|
||||
&mut self._100k_sats,
|
||||
&mut self._1m_sats,
|
||||
&mut self._10m_sats,
|
||||
&mut self._1btc,
|
||||
&mut self._10btc,
|
||||
&mut self._100btc,
|
||||
&mut self._1k_btc,
|
||||
&mut self._10k_btc,
|
||||
&mut self._100k_btc,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByLowerThanAmount<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self._10sats.1,
|
||||
&self._100sats.1,
|
||||
&self._1k_sats.1,
|
||||
&self._10k_sats.1,
|
||||
&self._100k_sats.1,
|
||||
&self._1m_sats.1,
|
||||
&self._10m_sats.1,
|
||||
&self._1btc.1,
|
||||
&self._10btc.1,
|
||||
&self._100btc.1,
|
||||
&self._1k_btc.1,
|
||||
&self._10k_btc.1,
|
||||
&self._100k_btc.1,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<ByLowerThanAmount<T>> for ByLowerThanAmount<Filtered<T>> {
|
||||
fn from(value: ByLowerThanAmount<T>) -> Self {
|
||||
Self {
|
||||
_10sats: (Filter::LowerThan(Sats::_10.into()), value._10sats).into(),
|
||||
_100sats: (Filter::LowerThan(Sats::_100.into()), value._100sats).into(),
|
||||
_1k_sats: (Filter::LowerThan(Sats::_1K.into()), value._1k_sats).into(),
|
||||
_10k_sats: (Filter::LowerThan(Sats::_10K.into()), value._10k_sats).into(),
|
||||
_100k_sats: (Filter::LowerThan(Sats::_100K.into()), value._100k_sats).into(),
|
||||
_1m_sats: (Filter::LowerThan(Sats::_1M.into()), value._1m_sats).into(),
|
||||
_10m_sats: (Filter::LowerThan(Sats::_10M.into()), value._10m_sats).into(),
|
||||
_1btc: (Filter::LowerThan(Sats::_1BTC.into()), value._1btc).into(),
|
||||
_10btc: (Filter::LowerThan(Sats::_10BTC.into()), value._10btc).into(),
|
||||
_100btc: (Filter::LowerThan(Sats::_100BTC.into()), value._100btc).into(),
|
||||
_1k_btc: (Filter::LowerThan(Sats::_1K_BTC.into()), value._1k_btc).into(),
|
||||
_10k_btc: (Filter::LowerThan(Sats::_10K_BTC.into()), value._10k_btc).into(),
|
||||
_100k_btc: (Filter::LowerThan(Sats::_100K_BTC.into()), value._100k_btc).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
103
crates/brk_grouper/src/by_max_age.rs
Normal file
103
crates/brk_grouper/src/by_max_age.rs
Normal file
@@ -0,0 +1,103 @@
|
||||
use crate::Filtered;
|
||||
|
||||
use super::Filter;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct ByMaxAge<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 _12y: T,
|
||||
pub _15y: T,
|
||||
}
|
||||
|
||||
impl<T> ByMaxAge<T> {
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
[
|
||||
&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._12y,
|
||||
&mut self._15y,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByMaxAge<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&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._12y.1,
|
||||
&self._15y.1,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<ByMaxAge<T>> for ByMaxAge<Filtered<T>> {
|
||||
fn from(value: ByMaxAge<T>) -> Self {
|
||||
Self {
|
||||
_1w: (Filter::LowerThan(7), value._1w).into(),
|
||||
_1m: (Filter::LowerThan(30), value._1m).into(),
|
||||
_2m: (Filter::LowerThan(2 * 30), value._2m).into(),
|
||||
_3m: (Filter::LowerThan(3 * 30), value._3m).into(),
|
||||
_4m: (Filter::LowerThan(4 * 30), value._4m).into(),
|
||||
_5m: (Filter::LowerThan(5 * 30), value._5m).into(),
|
||||
_6m: (Filter::LowerThan(6 * 30), value._6m).into(),
|
||||
_1y: (Filter::LowerThan(365), value._1y).into(),
|
||||
_2y: (Filter::LowerThan(2 * 365), value._2y).into(),
|
||||
_3y: (Filter::LowerThan(3 * 365), value._3y).into(),
|
||||
_4y: (Filter::LowerThan(4 * 365), value._4y).into(),
|
||||
_5y: (Filter::LowerThan(5 * 365), value._5y).into(),
|
||||
_6y: (Filter::LowerThan(6 * 365), value._6y).into(),
|
||||
_7y: (Filter::LowerThan(7 * 365), value._7y).into(),
|
||||
_8y: (Filter::LowerThan(8 * 365), value._8y).into(),
|
||||
_10y: (Filter::LowerThan(10 * 365), value._10y).into(),
|
||||
_12y: (Filter::LowerThan(12 * 365), value._12y).into(),
|
||||
_15y: (Filter::LowerThan(15 * 365), value._15y).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
104
crates/brk_grouper/src/by_min_age.rs
Normal file
104
crates/brk_grouper/src/by_min_age.rs
Normal file
@@ -0,0 +1,104 @@
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use crate::Filtered;
|
||||
|
||||
use super::Filter;
|
||||
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct ByMinAge<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 _12y: T,
|
||||
}
|
||||
|
||||
impl<T> ByMinAge<T> {
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
[
|
||||
&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._12y,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByMinAge<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&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._12y.1,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<ByMinAge<T>> for ByMinAge<Filtered<T>> {
|
||||
fn from(value: ByMinAge<T>) -> Self {
|
||||
Self {
|
||||
_1d: (Filter::GreaterOrEqual(1), value._1d).into(),
|
||||
_1w: (Filter::GreaterOrEqual(7), value._1w).into(),
|
||||
_1m: (Filter::GreaterOrEqual(30), value._1m).into(),
|
||||
_2m: (Filter::GreaterOrEqual(2 * 30), value._2m).into(),
|
||||
_3m: (Filter::GreaterOrEqual(3 * 30), value._3m).into(),
|
||||
_4m: (Filter::GreaterOrEqual(4 * 30), value._4m).into(),
|
||||
_5m: (Filter::GreaterOrEqual(5 * 30), value._5m).into(),
|
||||
_6m: (Filter::GreaterOrEqual(6 * 30), value._6m).into(),
|
||||
_1y: (Filter::GreaterOrEqual(365), value._1y).into(),
|
||||
_2y: (Filter::GreaterOrEqual(2 * 365), value._2y).into(),
|
||||
_3y: (Filter::GreaterOrEqual(3 * 365), value._3y).into(),
|
||||
_4y: (Filter::GreaterOrEqual(4 * 365), value._4y).into(),
|
||||
_5y: (Filter::GreaterOrEqual(5 * 365), value._5y).into(),
|
||||
_6y: (Filter::GreaterOrEqual(6 * 365), value._6y).into(),
|
||||
_7y: (Filter::GreaterOrEqual(7 * 365), value._7y).into(),
|
||||
_8y: (Filter::GreaterOrEqual(8 * 365), value._8y).into(),
|
||||
_10y: (Filter::GreaterOrEqual(10 * 365), value._10y).into(),
|
||||
_12y: (Filter::GreaterOrEqual(12 * 365), value._12y).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
152
crates/brk_grouper/src/by_spendable_type.rs
Normal file
152
crates/brk_grouper/src/by_spendable_type.rs
Normal file
@@ -0,0 +1,152 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
use brk_structs::OutputType;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use super::{Filter, Filtered};
|
||||
|
||||
#[derive(Default, Clone, Debug, Traversable)]
|
||||
pub struct BySpendableType<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> BySpendableType<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 iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
[
|
||||
&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,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
|
||||
pub fn iter_typed(&self) -> impl Iterator<Item = (OutputType, &T)> {
|
||||
[
|
||||
(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),
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> BySpendableType<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&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,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<BySpendableType<T>> for BySpendableType<Filtered<T>> {
|
||||
fn from(value: BySpendableType<T>) -> Self {
|
||||
Self {
|
||||
p2pk65: (Filter::Type(OutputType::P2PK65), value.p2pk65).into(),
|
||||
p2pk33: (Filter::Type(OutputType::P2PK33), value.p2pk33).into(),
|
||||
p2pkh: (Filter::Type(OutputType::P2PKH), value.p2pkh).into(),
|
||||
p2ms: (Filter::Type(OutputType::P2MS), value.p2ms).into(),
|
||||
p2sh: (Filter::Type(OutputType::P2SH), value.p2sh).into(),
|
||||
p2wpkh: (Filter::Type(OutputType::P2WPKH), value.p2wpkh).into(),
|
||||
p2wsh: (Filter::Type(OutputType::P2WSH), value.p2wsh).into(),
|
||||
p2tr: (Filter::Type(OutputType::P2TR), value.p2tr).into(),
|
||||
p2a: (Filter::Type(OutputType::P2A), value.p2a).into(),
|
||||
unknown: (Filter::Type(OutputType::Unknown), value.unknown).into(),
|
||||
empty: (Filter::Type(OutputType::Empty), value.empty).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Add for BySpendableType<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 BySpendableType<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;
|
||||
}
|
||||
}
|
||||
32
crates/brk_grouper/src/by_term.rs
Normal file
32
crates/brk_grouper/src/by_term.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use crate::Filtered;
|
||||
|
||||
use super::Filter;
|
||||
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct ByTerm<T> {
|
||||
pub short: T,
|
||||
pub long: T,
|
||||
}
|
||||
|
||||
impl<T> ByTerm<T> {
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
[&mut self.short, &mut self.long].into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByTerm<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[&self.short.1, &self.long.1].into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<ByTerm<T>> for ByTerm<Filtered<T>> {
|
||||
fn from(value: ByTerm<T>) -> Self {
|
||||
Self {
|
||||
short: (Filter::LowerThan(5 * 30), value.short).into(),
|
||||
long: (Filter::GreaterOrEqual(5 * 30), value.long).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
72
crates/brk_grouper/src/by_type.rs
Normal file
72
crates/brk_grouper/src/by_type.rs
Normal file
@@ -0,0 +1,72 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
use brk_structs::OutputType;
|
||||
|
||||
use super::{BySpendableType, ByUnspendableType};
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct GroupedByType<T> {
|
||||
pub spendable: BySpendableType<T>,
|
||||
pub unspendable: ByUnspendableType<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,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
35
crates/brk_grouper/src/by_unspendable_type.rs
Normal file
35
crates/brk_grouper/src/by_unspendable_type.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
#[derive(Default, Clone, Debug, Traversable)]
|
||||
pub struct ByUnspendableType<T> {
|
||||
pub opreturn: T,
|
||||
}
|
||||
|
||||
impl<T> ByUnspendableType<T> {
|
||||
pub fn as_vec(&self) -> [&T; 1] {
|
||||
[&self.opreturn]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Add for ByUnspendableType<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 ByUnspendableType<T>
|
||||
where
|
||||
T: AddAssign,
|
||||
{
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
self.opreturn += rhs.opreturn;
|
||||
}
|
||||
}
|
||||
37
crates/brk_grouper/src/by_value.rs
Normal file
37
crates/brk_grouper/src/by_value.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
#[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,
|
||||
]
|
||||
}
|
||||
}
|
||||
87
crates/brk_grouper/src/filter.rs
Normal file
87
crates/brk_grouper/src/filter.rs
Normal file
@@ -0,0 +1,87 @@
|
||||
use std::ops::Range;
|
||||
|
||||
use brk_structs::{HalvingEpoch, OutputType};
|
||||
use brk_traversable::{Traversable, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Filter {
|
||||
All,
|
||||
LowerThan(usize),
|
||||
Range(Range<usize>),
|
||||
GreaterOrEqual(usize),
|
||||
Epoch(HalvingEpoch),
|
||||
Type(OutputType),
|
||||
}
|
||||
|
||||
impl Filter {
|
||||
pub fn contains(&self, value: usize) -> bool {
|
||||
match self {
|
||||
Filter::Range(r) => r.contains(&value),
|
||||
Filter::LowerThan(max) => *max > value,
|
||||
Filter::GreaterOrEqual(min) => *min <= value,
|
||||
Filter::All => true,
|
||||
Filter::Epoch(_) | Filter::Type(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn includes(&self, other: &Filter) -> bool {
|
||||
match self {
|
||||
Filter::All => true,
|
||||
Filter::LowerThan(max) => match other {
|
||||
Filter::LowerThan(max2) => max >= max2,
|
||||
Filter::Range(range) => range.end <= *max,
|
||||
Filter::All | Filter::GreaterOrEqual(_) | Filter::Epoch(_) | Filter::Type(_) => {
|
||||
false
|
||||
}
|
||||
},
|
||||
Filter::GreaterOrEqual(min) => match other {
|
||||
Filter::Range(range) => range.start >= *min,
|
||||
Filter::GreaterOrEqual(min2) => min <= min2,
|
||||
Filter::All | Filter::LowerThan(_) | Filter::Epoch(_) | Filter::Type(_) => false,
|
||||
},
|
||||
Filter::Range(_) | Filter::Epoch(_) | Filter::Type(_) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Filtered<T>(pub Filter, pub T);
|
||||
|
||||
impl<T> Filtered<T> {
|
||||
pub fn includes(&self, other: &Filter) -> bool {
|
||||
self.0.includes(other)
|
||||
}
|
||||
|
||||
pub fn filter(&self) -> &Filter {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn unwrap(self) -> T {
|
||||
self.1
|
||||
}
|
||||
|
||||
pub fn t(&self) -> &T {
|
||||
&self.1
|
||||
}
|
||||
|
||||
pub fn mut_t(&mut self) -> &mut T {
|
||||
&mut self.1
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<(Filter, T)> for Filtered<T> {
|
||||
fn from(value: (Filter, T)) -> Self {
|
||||
Self(value.0, value.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Traversable> Traversable for Filtered<T> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
self.1.to_tree_node()
|
||||
}
|
||||
|
||||
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
self.1.iter_any_collectable()
|
||||
}
|
||||
}
|
||||
35
crates/brk_grouper/src/lib.rs
Normal file
35
crates/brk_grouper/src/lib.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
#![doc = include_str!("../README.md")]
|
||||
|
||||
mod address;
|
||||
mod by_address_type;
|
||||
mod by_age_range;
|
||||
mod by_amount_range;
|
||||
mod by_any_address;
|
||||
mod by_epoch;
|
||||
mod by_ge_amount;
|
||||
mod by_lt_amount;
|
||||
mod by_max_age;
|
||||
mod by_min_age;
|
||||
mod by_spendable_type;
|
||||
mod by_term;
|
||||
mod by_type;
|
||||
mod by_unspendable_type;
|
||||
mod filter;
|
||||
mod utxo;
|
||||
|
||||
pub use address::*;
|
||||
pub use by_address_type::*;
|
||||
pub use by_age_range::*;
|
||||
pub use by_amount_range::*;
|
||||
pub use by_any_address::*;
|
||||
pub use by_epoch::*;
|
||||
pub use by_ge_amount::*;
|
||||
pub use by_lt_amount::*;
|
||||
pub use by_max_age::*;
|
||||
pub use by_min_age::*;
|
||||
pub use by_spendable_type::*;
|
||||
pub use by_term::*;
|
||||
pub use by_type::*;
|
||||
pub use by_unspendable_type::*;
|
||||
pub use filter::*;
|
||||
pub use utxo::*;
|
||||
87
crates/brk_grouper/src/utxo.rs
Normal file
87
crates/brk_grouper/src/utxo.rs
Normal file
@@ -0,0 +1,87 @@
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use crate::{
|
||||
ByAgeRange, ByAmountRange, ByEpoch, ByGreatEqualAmount, ByLowerThanAmount, ByMaxAge, ByMinAge,
|
||||
BySpendableType, ByTerm, Filter, Filtered,
|
||||
};
|
||||
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct UTXOGroups<T> {
|
||||
pub all: T,
|
||||
pub age_range: ByAgeRange<T>,
|
||||
pub epoch: ByEpoch<T>,
|
||||
pub min_age: ByMinAge<T>,
|
||||
pub ge_amount: ByGreatEqualAmount<T>,
|
||||
pub amount_range: ByAmountRange<T>,
|
||||
pub term: ByTerm<T>,
|
||||
pub _type: BySpendableType<T>,
|
||||
pub max_age: ByMaxAge<T>,
|
||||
pub lt_amount: ByLowerThanAmount<T>,
|
||||
}
|
||||
|
||||
impl<T> UTXOGroups<T> {
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
[&mut self.all]
|
||||
.into_iter()
|
||||
.chain(self.term.iter_mut())
|
||||
.chain(self.max_age.iter_mut())
|
||||
.chain(self.min_age.iter_mut())
|
||||
.chain(self.ge_amount.iter_mut())
|
||||
.chain(self.age_range.iter_mut())
|
||||
.chain(self.epoch.iter_mut())
|
||||
.chain(self.amount_range.iter_mut())
|
||||
.chain(self.lt_amount.iter_mut())
|
||||
.chain(self._type.iter_mut())
|
||||
}
|
||||
|
||||
pub fn iter_separate_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
self.age_range
|
||||
.iter_mut()
|
||||
.chain(self.epoch.iter_mut())
|
||||
.chain(self.amount_range.iter_mut())
|
||||
.chain(self._type.iter_mut())
|
||||
}
|
||||
|
||||
pub fn iter_overlapping_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
[&mut self.all]
|
||||
.into_iter()
|
||||
.chain(self.term.iter_mut())
|
||||
.chain(self.max_age.iter_mut())
|
||||
.chain(self.min_age.iter_mut())
|
||||
.chain(self.lt_amount.iter_mut())
|
||||
.chain(self.ge_amount.iter_mut())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> UTXOGroups<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[&self.all.1]
|
||||
.into_iter()
|
||||
.chain(self.term.iter_right())
|
||||
.chain(self.max_age.iter_right())
|
||||
.chain(self.min_age.iter_right())
|
||||
.chain(self.age_range.iter_right())
|
||||
.chain(self.epoch.iter_right())
|
||||
.chain(self.amount_range.iter_right())
|
||||
.chain(self._type.iter_right())
|
||||
.chain(self.lt_amount.iter_right())
|
||||
.chain(self.ge_amount.iter_right())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<UTXOGroups<T>> for UTXOGroups<Filtered<T>> {
|
||||
fn from(value: UTXOGroups<T>) -> Self {
|
||||
Self {
|
||||
all: (Filter::All, value.all).into(),
|
||||
term: ByTerm::from(value.term),
|
||||
max_age: ByMaxAge::from(value.max_age),
|
||||
min_age: ByMinAge::from(value.min_age),
|
||||
age_range: ByAgeRange::from(value.age_range),
|
||||
epoch: ByEpoch::from(value.epoch),
|
||||
amount_range: ByAmountRange::from(value.amount_range),
|
||||
lt_amount: ByLowerThanAmount::from(value.lt_amount),
|
||||
ge_amount: ByGreatEqualAmount::from(value.ge_amount),
|
||||
_type: BySpendableType::from(value._type),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user