global: snapshot + pools + fixes

This commit is contained in:
nym21
2025-09-07 17:01:34 +02:00
parent e155a3dacf
commit 4049d694f7
69 changed files with 2768 additions and 1444 deletions
@@ -25,6 +25,25 @@ pub enum AddressBytes {
P2A(P2ABytes),
}
impl fmt::Display for AddressBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match self {
AddressBytes::P2PK65(bytes) => bytes.to_string(),
AddressBytes::P2PK33(bytes) => bytes.to_string(),
AddressBytes::P2PKH(bytes) => bytes.to_string(),
AddressBytes::P2SH(bytes) => bytes.to_string(),
AddressBytes::P2WPKH(bytes) => bytes.to_string(),
AddressBytes::P2WSH(bytes) => bytes.to_string(),
AddressBytes::P2TR(bytes) => bytes.to_string(),
AddressBytes::P2A(bytes) => bytes.to_string(),
}
)
}
}
impl AddressBytes {
pub fn as_slice(&self) -> &[u8] {
match self {
@@ -44,6 +44,7 @@ impl Serialize for AnyAddressIndex {
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum AnyAddressDataIndexEnum {
Loaded(LoadedAddressIndex),
Empty(EmptyAddressIndex),
@@ -3,6 +3,7 @@ use std::{
ops::{Add, AddAssign, Div, Mul},
};
use allocative::Allocative;
use serde::Serialize;
use vecdb::{CheckedSub, StoredCompressed};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -20,6 +21,7 @@ use super::{Sats, StoredF64};
KnownLayout,
Serialize,
StoredCompressed,
Allocative,
)]
pub struct Bitcoin(f64);
+3 -1
View File
@@ -3,10 +3,11 @@ use std::{
ops::{Add, Rem},
};
use allocative::Allocative;
use brk_error::Error;
use vecdb::{CheckedSub, FromCoarserIndex, Printable, StoredCompressed};
use jiff::Span;
use serde::Serialize;
use vecdb::{CheckedSub, FromCoarserIndex, Printable, StoredCompressed};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{DecadeIndex, MonthIndex, QuarterIndex, SemesterIndex, WeekIndex, YearIndex};
@@ -28,6 +29,7 @@ use super::Date;
KnownLayout,
Serialize,
StoredCompressed,
Allocative,
)]
pub struct DateIndex(u16);
@@ -3,8 +3,9 @@ use std::{
ops::{Add, AddAssign, Div},
};
use vecdb::{CheckedSub, Printable, StoredCompressed};
use allocative::Allocative;
use serde::{Deserialize, Serialize};
use vecdb::{CheckedSub, Printable, StoredCompressed};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use super::{Date, DateIndex, YearIndex};
@@ -25,6 +26,7 @@ use super::{Date, DateIndex, YearIndex};
IntoBytes,
KnownLayout,
StoredCompressed,
Allocative,
)]
pub struct DecadeIndex(u16);
@@ -3,6 +3,7 @@ use std::{
ops::{Add, AddAssign, Div},
};
use allocative::Allocative;
use serde::{Deserialize, Serialize};
use vecdb::{CheckedSub, Printable, StoredCompressed};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -25,6 +26,7 @@ use super::Height;
IntoBytes,
KnownLayout,
StoredCompressed,
Allocative,
)]
pub struct DifficultyEpoch(u16);
@@ -4,6 +4,7 @@ use std::{
ops::{Add, AddAssign, Div, Mul},
};
use allocative::Allocative;
use derive_deref::Deref;
use serde::{Deserialize, Serialize};
use vecdb::{CheckedSub, StoredCompressed};
@@ -24,6 +25,7 @@ use super::{Bitcoin, Cents, Close, High, Sats, StoredF32, StoredF64};
Serialize,
Deserialize,
StoredCompressed,
Allocative,
)]
pub struct Dollars(f64);
+11 -1
View File
@@ -3,6 +3,7 @@ use std::{
ops::{Add, AddAssign, Div},
};
use allocative::Allocative;
use serde::Serialize;
use vecdb::StoredCompressed;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -10,7 +11,16 @@ use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use super::{Sats, StoredU64};
#[derive(
Debug, Clone, Copy, Serialize, FromBytes, Immutable, IntoBytes, KnownLayout, StoredCompressed,
Debug,
Clone,
Copy,
Serialize,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
StoredCompressed,
Allocative,
)]
pub struct FeeRate(f64);
@@ -3,6 +3,7 @@ use std::{
ops::{Add, AddAssign, Div},
};
use allocative::Allocative;
use serde::{Deserialize, Serialize};
use vecdb::{CheckedSub, Printable, StoredCompressed};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -25,6 +26,7 @@ use super::Height;
IntoBytes,
KnownLayout,
StoredCompressed,
Allocative,
)]
pub struct HalvingEpoch(u16);
+2
View File
@@ -3,6 +3,7 @@ use std::{
ops::{Add, AddAssign, Rem},
};
use allocative::Allocative;
use bitcoincore_rpc::{Client, RpcApi};
use byteview::ByteView;
use derive_deref::Deref;
@@ -32,6 +33,7 @@ use super::StoredU64;
IntoBytes,
KnownLayout,
StoredCompressed,
Allocative,
)]
pub struct Height(u32);
@@ -1,5 +1,6 @@
use std::ops::{Add, AddAssign};
use allocative::Allocative;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use vecdb::{CheckedSub, Printable, StoredCompressed};
@@ -24,6 +25,7 @@ use super::Vin;
KnownLayout,
Serialize,
StoredCompressed,
Allocative,
)]
pub struct InputIndex(u64);
+3 -1
View File
@@ -3,8 +3,9 @@ use std::{
ops::{Add, AddAssign, Div},
};
use vecdb::{CheckedSub, Printable, StoredCompressed};
use allocative::Allocative;
use serde::{Deserialize, Serialize};
use vecdb::{CheckedSub, Printable, StoredCompressed};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use super::{Date, DateIndex, YearIndex};
@@ -25,6 +26,7 @@ use super::{Date, DateIndex, YearIndex};
IntoBytes,
KnownLayout,
StoredCompressed,
Allocative,
)]
pub struct MonthIndex(u16);
+2
View File
@@ -3,6 +3,7 @@ use std::{
ops::{Add, AddAssign, Div},
};
use allocative::Allocative;
use derive_deref::{Deref, DerefMut};
use serde::{Serialize, Serializer, ser::SerializeTuple};
use vecdb::StoredCompressed;
@@ -473,6 +474,7 @@ where
DerefMut,
Serialize,
StoredCompressed,
Allocative,
)]
#[repr(transparent)]
pub struct Close<T>(T);
@@ -1,5 +1,6 @@
use std::ops::{Add, AddAssign};
use allocative::Allocative;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use vecdb::{CheckedSub, Printable, StoredCompressed};
@@ -26,6 +27,7 @@ use super::Vout;
KnownLayout,
Serialize,
StoredCompressed,
Allocative,
)]
pub struct OutputIndex(u64);
@@ -16,6 +16,7 @@ use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
KnownLayout,
Serialize,
)]
#[serde(rename_all = "lowercase")]
#[repr(u8)]
pub enum OutputType {
P2PK65,
@@ -3,6 +3,7 @@ use std::{
ops::{Add, AddAssign, Div},
};
use allocative::Allocative;
use serde::{Deserialize, Serialize};
use vecdb::{CheckedSub, Printable, StoredCompressed};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -25,6 +26,7 @@ use super::MonthIndex;
IntoBytes,
KnownLayout,
StoredCompressed,
Allocative,
)]
pub struct QuarterIndex(u16);
+2
View File
@@ -3,6 +3,7 @@ use std::{
ops::{Add, AddAssign, Div, Mul, SubAssign},
};
use allocative::Allocative;
use bitcoin::Amount;
use derive_deref::Deref;
use serde::{Deserialize, Serialize};
@@ -30,6 +31,7 @@ use super::{Bitcoin, Cents, Dollars, Height};
Serialize,
Deserialize,
StoredCompressed,
Allocative,
)]
pub struct Sats(u64);
@@ -3,6 +3,7 @@ use std::{
ops::{Add, AddAssign, Div},
};
use allocative::Allocative;
use serde::{Deserialize, Serialize};
use vecdb::{CheckedSub, Printable, StoredCompressed};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -25,6 +26,7 @@ use super::MonthIndex;
IntoBytes,
KnownLayout,
StoredCompressed,
Allocative,
)]
pub struct SemesterIndex(u16);
@@ -1,3 +1,4 @@
use allocative::Allocative;
use derive_deref::Deref;
use serde::Serialize;
use vecdb::{Printable, StoredCompressed};
@@ -19,6 +20,7 @@ use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
KnownLayout,
Serialize,
StoredCompressed,
Allocative,
)]
pub struct StoredBool(u16);
@@ -6,11 +6,14 @@ use std::{
ops::{Add, AddAssign, Div, Mul, Sub},
};
use allocative::Allocative;
use derive_deref::Deref;
use serde::Serialize;
use vecdb::{CheckedSub, Printable, StoredCompressed};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{Close, StoredU32};
use super::{Dollars, StoredF64};
#[derive(
@@ -25,6 +28,7 @@ use super::{Dollars, StoredF64};
KnownLayout,
Serialize,
StoredCompressed,
Allocative,
)]
pub struct StoredF32(f32);
@@ -65,12 +69,24 @@ impl From<usize> for StoredF32 {
}
}
impl From<StoredU32> for StoredF32 {
fn from(value: StoredU32) -> Self {
Self(f32::from(value))
}
}
impl CheckedSub<StoredF32> for StoredF32 {
fn checked_sub(self, rhs: Self) -> Option<Self> {
Some(Self(self.0 - rhs.0))
}
}
impl CheckedSub<usize> for StoredF32 {
fn checked_sub(self, rhs: usize) -> Option<Self> {
Some(Self(self.0 - rhs as f32))
}
}
impl Div<usize> for StoredF32 {
type Output = Self;
fn div(self, rhs: usize) -> Self::Output {
@@ -78,6 +94,13 @@ impl Div<usize> for StoredF32 {
}
}
impl Div<StoredU32> for StoredF32 {
type Output = Self;
fn div(self, rhs: StoredU32) -> Self::Output {
Self(self.0 / f32::from(rhs))
}
}
impl Add for StoredF32 {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
@@ -103,6 +126,12 @@ impl From<Dollars> for StoredF32 {
}
}
impl From<Close<Dollars>> for StoredF32 {
fn from(value: Close<Dollars>) -> Self {
Self::from(*value)
}
}
impl Div<Dollars> for StoredF32 {
type Output = Self;
fn div(self, rhs: Dollars) -> Self::Output {
@@ -4,6 +4,7 @@ use std::{
ops::{Add, AddAssign, Div, Mul},
};
use allocative::Allocative;
use derive_deref::Deref;
use serde::Serialize;
use vecdb::{CheckedSub, Printable, StoredCompressed};
@@ -23,6 +24,7 @@ use crate::{Bitcoin, Dollars};
KnownLayout,
Serialize,
StoredCompressed,
Allocative,
)]
pub struct StoredF64(f64);
@@ -1,3 +1,5 @@
use std::borrow::Cow;
use byteview::ByteView;
use derive_deref::Deref;
use serde::Serialize;
@@ -26,6 +28,12 @@ impl From<String> for StoredString {
}
}
impl From<Cow<'_, str>> for StoredString {
fn from(value: Cow<'_, str>) -> Self {
Self(value.to_string())
}
}
impl From<ByteView> for StoredString {
fn from(value: ByteView) -> Self {
let bytes = &*value;
@@ -1,5 +1,6 @@
use std::ops::{Add, AddAssign, Div};
use allocative::Allocative;
use derive_deref::Deref;
use serde::Serialize;
use vecdb::{CheckedSub, Printable, StoredCompressed};
@@ -27,11 +28,13 @@ use super::{
KnownLayout,
Serialize,
StoredCompressed,
Allocative,
)]
pub struct StoredU16(u16);
impl StoredU16 {
pub const ZERO: Self = Self(0);
pub const ONE: Self = Self(1);
pub fn new(v: u16) -> Self {
Self(v)
+34 -1
View File
@@ -1,5 +1,6 @@
use std::ops::{Add, AddAssign, Div};
use std::ops::{Add, AddAssign, Div, Mul};
use allocative::Allocative;
use derive_deref::Deref;
use serde::Serialize;
use vecdb::{CheckedSub, Printable, StoredCompressed};
@@ -27,15 +28,21 @@ use super::{
KnownLayout,
Serialize,
StoredCompressed,
Allocative,
)]
pub struct StoredU32(u32);
impl StoredU32 {
pub const ZERO: Self = Self(0);
pub const ONE: Self = Self(1);
pub fn new(counter: u32) -> Self {
Self(counter)
}
pub fn is_zero(&self) -> bool {
self.0 == 0
}
}
impl From<u32> for StoredU32 {
@@ -44,6 +51,12 @@ impl From<u32> for StoredU32 {
}
}
impl From<StoredU32> for f32 {
fn from(value: StoredU32) -> Self {
value.0 as f32
}
}
impl From<usize> for StoredU32 {
fn from(value: usize) -> Self {
if value > u32::MAX as usize {
@@ -59,6 +72,15 @@ impl CheckedSub<StoredU32> for StoredU32 {
}
}
impl CheckedSub<usize> for StoredU32 {
fn checked_sub(self, rhs: usize) -> Option<Self> {
if rhs > u32::MAX as usize {
panic!()
}
self.0.checked_sub(rhs as u32).map(Self)
}
}
impl Div<usize> for StoredU32 {
type Output = Self;
fn div(self, rhs: usize) -> Self::Output {
@@ -79,6 +101,17 @@ impl AddAssign for StoredU32 {
}
}
impl Mul<usize> for StoredU32 {
type Output = Self;
fn mul(self, rhs: usize) -> Self::Output {
let res = self.0 as usize * rhs;
if res > u32::MAX as usize {
panic!()
}
Self::from(res)
}
}
impl From<f64> for StoredU32 {
fn from(value: f64) -> Self {
if value < 0.0 || value > u32::MAX as f64 {
@@ -1,5 +1,6 @@
use std::ops::{Add, AddAssign, Div};
use allocative::Allocative;
use derive_deref::Deref;
use serde::Serialize;
use vecdb::{CheckedSub, Printable, StoredCompressed};
@@ -28,6 +29,7 @@ use super::{
KnownLayout,
Serialize,
StoredCompressed,
Allocative,
)]
pub struct StoredU64(u64);
@@ -1,5 +1,6 @@
use std::ops::{Add, AddAssign, Div};
use allocative::Allocative;
use derive_deref::Deref;
use jiff::{civil::date, tz::TimeZone};
use serde::Serialize;
@@ -23,6 +24,7 @@ use super::Date;
KnownLayout,
Serialize,
StoredCompressed,
Allocative,
)]
pub struct Timestamp(u32);
@@ -1,5 +1,6 @@
use std::ops::{Add, AddAssign};
use allocative::Allocative;
use byteview::ByteView;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
@@ -27,6 +28,7 @@ use super::StoredU32;
KnownLayout,
Serialize,
StoredCompressed,
Allocative,
)]
pub struct TxIndex(u32);
@@ -3,6 +3,7 @@ use std::{
ops::{Add, AddAssign, Div},
};
use allocative::Allocative;
use serde::{Deserialize, Serialize};
use vecdb::{CheckedSub, Printable, StoredCompressed};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -25,6 +26,7 @@ use super::{Date, DateIndex};
IntoBytes,
KnownLayout,
StoredCompressed,
Allocative,
)]
pub struct WeekIndex(u16);
+2
View File
@@ -1,5 +1,6 @@
use std::ops::{Add, AddAssign, Div};
use allocative::Allocative;
use derive_deref::Deref;
use serde::Serialize;
use vecdb::StoredCompressed;
@@ -20,6 +21,7 @@ use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
FromBytes,
Serialize,
StoredCompressed,
Allocative,
)]
pub struct Weight(u64);
@@ -3,6 +3,7 @@ use std::{
ops::{Add, AddAssign, Div},
};
use allocative::Allocative;
use serde::{Deserialize, Serialize};
use vecdb::{CheckedSub, Printable, StoredCompressed};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -25,6 +26,7 @@ use super::{Date, DateIndex, MonthIndex};
IntoBytes,
KnownLayout,
StoredCompressed,
Allocative,
)]
pub struct YearIndex(u16);