global: add some market charts

This commit is contained in:
nym21
2025-05-09 16:04:54 +02:00
parent 851a6aac0e
commit 9f20664c6e
17 changed files with 449 additions and 46 deletions
+15
View File
@@ -59,3 +59,18 @@ impl Div<usize> for Cents {
Self(self.0 / rhs as u64)
}
}
impl From<u128> for Cents {
fn from(value: u128) -> Self {
if value > u64::MAX as u128 {
panic!("u128 bigger than u64")
}
Self(value as u64)
}
}
impl From<Cents> for u128 {
fn from(value: Cents) -> Self {
value.0 as u128
}
}
+5 -1
View File
@@ -22,6 +22,10 @@ use super::{Bitcoin, Cents, Sats};
)]
pub struct Dollars(f64);
impl Dollars {
pub const ZERO: Self = Self(0.0);
}
impl From<f64> for Dollars {
fn from(value: f64) -> Self {
Self(value)
@@ -73,7 +77,7 @@ impl Mul<Bitcoin> for Dollars {
type Output = Dollars;
fn mul(self, rhs: Bitcoin) -> Self::Output {
Self::from(Cents::from(
u64::from(Sats::from(rhs)) * u64::from(Cents::from(self)) / u64::from(Sats::ONE_BTC),
u128::from(Sats::from(rhs)) * u128::from(Cents::from(self)) / u128::from(Sats::ONE_BTC),
))
}
}
+15
View File
@@ -156,3 +156,18 @@ impl From<Sats> for u64 {
value.0
}
}
impl From<u128> for Sats {
fn from(value: u128) -> Self {
if value > u64::MAX as u128 {
panic!("u128 bigger than u64")
}
Self(value as u64)
}
}
impl From<Sats> for u128 {
fn from(value: Sats) -> Self {
value.0 as u128
}
}
@@ -9,6 +9,7 @@ use crate::CheckedSub;
#[derive(
Debug,
Deref,
Default,
Clone,
Copy,
PartialEq,
@@ -16,6 +16,7 @@ use super::{
Debug,
Deref,
Clone,
Default,
Copy,
PartialEq,
Eq,