global: snapshot

This commit is contained in:
nym21
2025-08-29 22:49:26 +02:00
parent 30affc884b
commit e106d30852
28 changed files with 1120 additions and 827 deletions

View File

@@ -47,6 +47,10 @@ impl Date {
pub fn into_jiff(self) -> Date_ {
self.into()
}
pub fn today() -> Self {
Self::from(Timestamp::now())
}
}
impl Default for Date {

View File

@@ -12,9 +12,9 @@ use super::{Sats, StoredU64};
#[derive(
Debug, Clone, Copy, Serialize, FromBytes, Immutable, IntoBytes, KnownLayout, StoredCompressed,
)]
pub struct Feerate(f64);
pub struct FeeRate(f64);
impl From<(Sats, StoredU64)> for Feerate {
impl From<(Sats, StoredU64)> for FeeRate {
fn from((sats, vsize): (Sats, StoredU64)) -> Self {
let sats = u64::from(sats);
let vsize = u64::from(vsize);
@@ -22,44 +22,44 @@ impl From<(Sats, StoredU64)> for Feerate {
}
}
impl From<f64> for Feerate {
impl From<f64> for FeeRate {
fn from(value: f64) -> Self {
Self(value)
}
}
impl From<Feerate> for f64 {
fn from(value: Feerate) -> Self {
impl From<FeeRate> for f64 {
fn from(value: FeeRate) -> Self {
value.0
}
}
impl Add for Feerate {
impl Add for FeeRate {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self(self.0 + rhs.0)
}
}
impl AddAssign for Feerate {
impl AddAssign for FeeRate {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl Div<usize> for Feerate {
impl Div<usize> for FeeRate {
type Output = Self;
fn div(self, rhs: usize) -> Self::Output {
Self(self.0 / rhs as f64)
}
}
impl From<usize> for Feerate {
impl From<usize> for FeeRate {
fn from(value: usize) -> Self {
Self(value as f64)
}
}
impl PartialEq for Feerate {
impl PartialEq for FeeRate {
fn eq(&self, other: &Self) -> bool {
match (self.0.is_nan(), other.0.is_nan()) {
(true, true) => true,
@@ -70,17 +70,17 @@ impl PartialEq for Feerate {
}
}
impl Eq for Feerate {}
impl Eq for FeeRate {}
#[allow(clippy::derive_ord_xor_partial_ord)]
impl PartialOrd for Feerate {
impl PartialOrd for FeeRate {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
#[allow(clippy::derive_ord_xor_partial_ord)]
impl Ord for Feerate {
impl Ord for FeeRate {
fn cmp(&self, other: &Self) -> Ordering {
match (self.0.is_nan(), other.0.is_nan()) {
(true, true) => Ordering::Equal,

View File

@@ -36,6 +36,12 @@ impl From<f64> for StoredF64 {
}
}
impl From<f32> for StoredF64 {
fn from(value: f32) -> Self {
Self(value as f64)
}
}
impl From<usize> for StoredF64 {
fn from(value: usize) -> Self {
Self(value as f64)
@@ -88,6 +94,12 @@ impl From<StoredF64> for f64 {
}
}
impl From<StoredF64> for f32 {
fn from(value: StoredF64) -> Self {
value.0 as f32
}
}
impl From<Dollars> for StoredF64 {
fn from(value: Dollars) -> Self {
Self(f64::from(value))

View File

@@ -69,6 +69,18 @@ impl Timestamp {
pub fn is_more_than_hour(&self) -> bool {
self.0 >= ONE_HOUR_IN_SEC
}
pub fn now() -> Self {
Self::from(jiff::Timestamp::now())
}
pub fn day_completion(&self) -> f64 {
let rounded = jiff::Timestamp::from(Self::from(Date::from(*self)));
ONE_DAY_IN_SEC_F64
/ jiff::Timestamp::from(*self)
.duration_since(rounded)
.as_secs_f64()
}
}
impl From<u32> for Timestamp {