Add privacy boundary to BlockTime
As per policy in #4090 add a privacy boundary to the `BlockTime` type. Use the module name `encapsulate` as is done in `amount` - its private so the name can easily be changed later if needed. Explicitly do not run the formatter or update rustdoc column width so that review is easier.
This commit is contained in:
parent
b3dfe0df3f
commit
f7f1a0be8c
|
@ -9,26 +9,28 @@
|
|||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
use arbitrary::{Arbitrary, Unstructured};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// A Bitcoin block timestamp.
|
||||
///
|
||||
/// > Each block contains a Unix time timestamp. In addition to serving as a source of variation for
|
||||
/// > the block hash, they also make it more difficult for an adversary to manipulate the block chain.
|
||||
/// >
|
||||
/// > A timestamp is accepted as valid if it is greater than the median timestamp of previous 11
|
||||
/// > blocks, and less than the network-adjusted time + 2 hours. "Network-adjusted time" is the
|
||||
/// > median of the timestamps returned by all nodes connected to you. As a result block timestamps
|
||||
/// > are not exactly accurate, and they do not need to be. Block times are accurate only to within
|
||||
/// > an hour or two.
|
||||
///
|
||||
/// ref: <https://en.bitcoin.it/wiki/Block_timestamp>
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct BlockTime(u32);
|
||||
mod encapsulate {
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
impl BlockTime {
|
||||
/// A Bitcoin block timestamp.
|
||||
///
|
||||
/// > Each block contains a Unix time timestamp. In addition to serving as a source of variation for
|
||||
/// > the block hash, they also make it more difficult for an adversary to manipulate the block chain.
|
||||
/// >
|
||||
/// > A timestamp is accepted as valid if it is greater than the median timestamp of previous 11
|
||||
/// > blocks, and less than the network-adjusted time + 2 hours. "Network-adjusted time" is the
|
||||
/// > median of the timestamps returned by all nodes connected to you. As a result block timestamps
|
||||
/// > are not exactly accurate, and they do not need to be. Block times are accurate only to within
|
||||
/// > an hour or two.
|
||||
///
|
||||
/// ref: <https://en.bitcoin.it/wiki/Block_timestamp>
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct BlockTime(u32);
|
||||
|
||||
impl BlockTime {
|
||||
/// Constructs a new [`BlockTime`] from an unsigned 32 bit integer value.
|
||||
#[inline]
|
||||
pub const fn from_u32(t: u32) -> Self { BlockTime(t) }
|
||||
|
@ -36,7 +38,10 @@ impl BlockTime {
|
|||
/// Returns the inner `u32` value.
|
||||
#[inline]
|
||||
pub const fn to_u32(self) -> u32 { self.0 }
|
||||
}
|
||||
}
|
||||
#[doc(inline)]
|
||||
pub use encapsulate::BlockTime;
|
||||
|
||||
impl From<u32> for BlockTime {
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in New Issue