global: snapshot

This commit is contained in:
nym21
2025-03-11 15:36:40 +01:00
parent db70b05088
commit 64d73b93e4
19 changed files with 275 additions and 324 deletions

View File

@@ -1,2 +1,5 @@
#[derive(Debug, Clone, Copy)]
use serde::Serialize;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
#[derive(Debug, Clone, Copy, Serialize, FromBytes, Immutable, IntoBytes, KnownLayout)]
pub struct Feerate(f32);

View File

@@ -1,12 +1,14 @@
use std::{
iter::Sum,
ops::{Add, AddAssign, Div, Mul, Sub, SubAssign},
ops::{Add, AddAssign, Div, Mul, SubAssign},
};
use bitcoin::Amount;
use serde::Serialize;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use super::{Bitcoin, Dollars, Height};
#[derive(
@@ -48,16 +50,15 @@ impl AddAssign for Sats {
}
}
impl Sub for Sats {
type Output = Sats;
fn sub(self, rhs: Sats) -> Self::Output {
Sats::from(self.0 - rhs.0)
impl CheckedSub<Sats> for Sats {
fn checked_sub(self, rhs: Sats) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Sats::from)
}
}
impl SubAssign for Sats {
fn sub_assign(&mut self, rhs: Self) {
*self = *self - rhs;
*self = self.checked_sub(rhs).unwrap();
}
}

View File

@@ -1,11 +1,11 @@
use std::ops::{Add, AddAssign, Sub};
use std::ops::{Add, AddAssign};
use byteview::ByteView;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::Error;
use crate::{CheckedSub, Error};
#[derive(
Debug,
@@ -52,10 +52,9 @@ impl AddAssign<Txindex> for Txindex {
}
}
impl Sub<Txindex> for Txindex {
type Output = Txindex;
fn sub(self, rhs: Txindex) -> Self::Output {
Self::from(*self - *rhs)
impl CheckedSub<Txindex> for Txindex {
fn checked_sub(self, rhs: Txindex) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Txindex::from)
}
}

View File

@@ -1,9 +1,11 @@
use std::ops::{Add, AddAssign, Sub};
use std::ops::{Add, AddAssign};
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use super::Vin;
#[derive(
@@ -58,10 +60,9 @@ impl AddAssign<Txinindex> for Txinindex {
}
}
impl Sub<Txinindex> for Txinindex {
type Output = Self;
fn sub(self, rhs: Txinindex) -> Self::Output {
Self(self.0 - rhs.0)
impl CheckedSub<Txinindex> for Txinindex {
fn checked_sub(self, rhs: Txinindex) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Txinindex::from)
}
}

View File

@@ -1,9 +1,11 @@
use std::ops::{Add, AddAssign, Sub};
use std::ops::{Add, AddAssign};
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use super::Vout;
#[derive(
@@ -64,10 +66,9 @@ impl AddAssign<Txoutindex> for Txoutindex {
}
}
impl Sub<Txoutindex> for Txoutindex {
type Output = Self;
fn sub(self, rhs: Txoutindex) -> Self::Output {
Self(self.0 - rhs.0)
impl CheckedSub<Txoutindex> for Txoutindex {
fn checked_sub(self, rhs: Txoutindex) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Txoutindex::from)
}
}