pub struct BlockMtp(/* private fields */);Expand description
The median timestamp of 11 consecutive blocks.
This type is not meant for constructing time-based timelocks. It is a general purpose
MTP abstraction. For locktimes please see locktime::absolute::MedianTimePast.
This is a thin wrapper around a u32 that may take on all values of a u32.
Implementations§
Source§impl BlockMtp
impl BlockMtp
Sourcepub const ZERO: Self
pub const ZERO: Self
Block MTP 0.
Since MTP is a timestamp, 0 is before Bitcoin was invented. This const may still be useful for some use cases e.g., folding a sum of intervals.
Sourcepub fn new(timestamps: [BlockTime; 11]) -> Self
pub fn new(timestamps: [BlockTime; 11]) -> Self
Constructs a BlockMtp by computing the median‐time‐past from the last 11 block timestamps
Because block timestamps are not monotonic, this function internally sorts them; it is therefore not important what order they appear in the array; use whatever is most convenient.
Sourcepub fn checked_sub(self, other: Self) -> Option<BlockMtpInterval>
pub fn checked_sub(self, other: Self) -> Option<BlockMtpInterval>
Attempt to subtract two BlockMtps, returning None if overflow occurred.
Sourcepub fn checked_add(self, other: BlockMtpInterval) -> Option<Self>
pub fn checked_add(self, other: BlockMtpInterval) -> Option<Self>
Attempt to add an interval to this BlockMtp, returning None if overflow occurred.
Trait Implementations§
Source§impl<'a> Add<&'a BlockMtpInterval> for &BlockMtp
impl<'a> Add<&'a BlockMtpInterval> for &BlockMtp
Source§impl Add<&BlockMtpInterval> for BlockMtp
impl Add<&BlockMtpInterval> for BlockMtp
Source§impl Add<BlockMtpInterval> for &BlockMtp
impl Add<BlockMtpInterval> for &BlockMtp
Source§impl Add<BlockMtpInterval> for BlockMtp
impl Add<BlockMtpInterval> for BlockMtp
Source§impl<'a> Arbitrary<'a> for BlockMtp
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for BlockMtp
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl<'de> Deserialize<'de> for BlockMtp
Available on crate feature serde only.
impl<'de> Deserialize<'de> for BlockMtp
serde only.Source§fn deserialize<D>(d: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(d: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl From<MedianTimePast> for BlockMtp
impl From<MedianTimePast> for BlockMtp
Source§fn from(h: MedianTimePast) -> Self
fn from(h: MedianTimePast) -> Self
Converts a locktime::absolute::MedianTimePast to a BlockMtp.
An absolute locktime MTP has a minimum value of absolute::LOCK_TIME_THRESHOLD,
while BlockMtp may take the full range of u32.
Source§impl Ord for BlockMtp
impl Ord for BlockMtp
Source§impl PartialOrd for BlockMtp
impl PartialOrd for BlockMtp
Source§impl<'a> Sub<&'a BlockMtpInterval> for &BlockMtp
impl<'a> Sub<&'a BlockMtpInterval> for &BlockMtp
Source§impl Sub<&BlockMtpInterval> for BlockMtp
impl Sub<&BlockMtpInterval> for BlockMtp
Source§impl Sub<BlockMtpInterval> for &BlockMtp
impl Sub<BlockMtpInterval> for &BlockMtp
Source§impl Sub<BlockMtpInterval> for BlockMtp
impl Sub<BlockMtpInterval> for BlockMtp
Source§impl TryFrom<BlockMtp> for MedianTimePast
impl TryFrom<BlockMtp> for MedianTimePast
Source§fn try_from(h: BlockMtp) -> Result<Self, Self::Error>
fn try_from(h: BlockMtp) -> Result<Self, Self::Error>
Converts a BlockHeight to a locktime::absolute::Height.
An absolute locktime MTP has a minimum value of absolute::LOCK_TIME_THRESHOLD,
while BlockMtp may take the full range of u32.