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 fn from_hex(s: &str) -> Result<BlockMtp, PrefixedHexError>
pub fn from_hex(s: &str) -> Result<BlockMtp, PrefixedHexError>
Constructs a new BlockMtp from an unprefixed hex string.
§Errors
If the input string is not a valid hex representation of a BlockMtp or it does not include the 0x prefix.
Sourcepub fn from_unprefixed_hex(s: &str) -> Result<BlockMtp, UnprefixedHexError>
pub fn from_unprefixed_hex(s: &str) -> Result<BlockMtp, UnprefixedHexError>
Constructs a new BlockMtp from a prefixed hex string.
§Errors
If the input string is not a valid hex representation of a BlockMtp or if it includes the 0x prefix.
Source§impl BlockMtp
impl BlockMtp
Sourcepub const ZERO: BlockMtp
pub const ZERO: BlockMtp
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]) -> BlockMtp
pub fn new(timestamps: [BlockTime; 11]) -> BlockMtp
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: BlockMtp) -> Option<BlockMtpInterval>
pub fn checked_sub(self, other: BlockMtp) -> Option<BlockMtpInterval>
Attempt to subtract two BlockMtps, returning None if overflow occurred.
Sourcepub fn checked_add(self, other: BlockMtpInterval) -> Option<BlockMtp>
pub fn checked_add(self, other: BlockMtpInterval) -> Option<BlockMtp>
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<BlockMtp, Error>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<BlockMtp, Error>
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 moreimpl Copy for BlockMtp
Source§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<BlockMtp, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(d: D) -> Result<BlockMtp, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl Eq for BlockMtp
Source§impl From<MedianTimePast> for BlockMtp
impl From<MedianTimePast> for BlockMtp
Source§fn from(h: MedianTimePast) -> BlockMtp
fn from(h: MedianTimePast) -> BlockMtp
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
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for BlockMtp
impl PartialOrd for BlockMtp
Source§impl Serialize for BlockMtp
Available on crate feature serde only.
impl Serialize for BlockMtp
serde only.Source§fn serialize<S>(
&self,
s: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
s: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl StructuralPartialEq 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<MedianTimePast, <MedianTimePast as TryFrom<BlockMtp>>::Error>
fn try_from( h: BlockMtp, ) -> Result<MedianTimePast, <MedianTimePast as TryFrom<BlockMtp>>::Error>
Converts a BlockMtp to a [locktime::absolute::MedianTimePast].
An absolute locktime MTP has a minimum value of absolute::LOCK_TIME_THRESHOLD,
while BlockMtp may take the full range of u32.