units: Make block-related types have private inner fields

We recently added a bunch of types in the `block` module that are
wrappers around `u32`. When we did we slapped `pub` on the inner fields.

Lets be more mindful and make the inner fields private. Note all these
types have `to_u32`, `from_u32` and `From` in both directions.
This commit is contained in:
Tobin C. Harding 2025-05-14 14:56:28 +10:00
parent fc373f3a37
commit 9a9b41008f
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 4 additions and 8 deletions

View File

@ -85,8 +85,7 @@ impl_u32_wrapper! {
/// This is a thin wrapper around a `u32` that may take on all values of a `u32`. /// This is a thin wrapper around a `u32` that may take on all values of a `u32`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
// Public to try and make it really clear that there are no invariants. pub struct BlockHeight(u32);
pub struct BlockHeight(pub u32);
} }
impl BlockHeight { impl BlockHeight {
@ -130,8 +129,7 @@ impl_u32_wrapper! {
/// purpose block interval abstraction. For locktimes please see [`locktime::relative::Height`]. /// purpose block interval abstraction. For locktimes please see [`locktime::relative::Height`].
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
// Public to try and make it really clear that there are no invariants. pub struct BlockHeightInterval(u32);
pub struct BlockHeightInterval(pub u32);
} }
impl BlockHeightInterval { impl BlockHeightInterval {
@ -173,8 +171,7 @@ impl_u32_wrapper! {
/// This is a thin wrapper around a `u32` that may take on all values of a `u32`. /// This is a thin wrapper around a `u32` that may take on all values of a `u32`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
// Public to try and make it really clear that there are no invariants. pub struct BlockMtp(u32);
pub struct BlockMtp(pub u32);
} }
impl BlockMtp { impl BlockMtp {
@ -228,8 +225,7 @@ impl_u32_wrapper! {
/// This is a thin wrapper around a `u32` that may take on all values of a `u32`. /// This is a thin wrapper around a `u32` that may take on all values of a `u32`.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
// Public to try and make it really clear that there are no invariants. pub struct BlockMtpInterval(u32);
pub struct BlockMtpInterval(pub u32);
} }
impl BlockMtpInterval { impl BlockMtpInterval {