vec: iter + global: snapshot

This commit is contained in:
nym21
2025-04-27 00:21:21 +02:00
parent d55478da54
commit bdc3c19163
10 changed files with 389 additions and 155 deletions

View File

@@ -28,8 +28,8 @@ use crate::CheckedSub;
pub struct Height(u32);
impl Height {
pub const ZERO: Self = Height(0);
pub const MAX: Self = Height(u32::MAX);
pub const ZERO: Self = Self(0);
pub const MAX: Self = Self(u32::MAX);
pub fn new(height: u32) -> Self {
Self(height)

View File

@@ -29,6 +29,12 @@ use super::StoredU32;
pub struct TxIndex(u32);
impl TxIndex {
pub const ZERO: Self = Self(0);
pub fn new(txindex: u32) -> Self {
Self(txindex)
}
pub fn incremented(self) -> Self {
Self(*self + 1)
}

View File

@@ -19,36 +19,29 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
FromBytes,
Serialize,
)]
pub struct Weight(u32);
pub struct Weight(u64);
impl From<bitcoin::Weight> for Weight {
fn from(value: bitcoin::Weight) -> Self {
let wu = value.to_wu();
if wu > u32::MAX as u64 {
unreachable!("wu is too big, shouldn't happen")
}
Self(wu as u32)
Self(value.to_wu())
}
}
impl From<Weight> for bitcoin::Weight {
fn from(value: Weight) -> Self {
Self::from_wu(*value as u64)
Self::from_wu(value.0)
}
}
impl From<usize> for Weight {
fn from(value: usize) -> Self {
if value > u32::MAX as usize {
panic!()
}
Self(value as u32)
Self(value as u64)
}
}
impl From<f64> for Weight {
fn from(value: f64) -> Self {
Self(value as u32)
Self(value as u64)
}
}