mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 14:49:58 -07:00
vec: iter + global: snapshot
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user