Enum LockTime
pub enum LockTime {
Blocks(Height),
Time(Time),
}Expand description
A relative lock time value, representing either a block height or time (512 second intervals).
The relative::LockTime type does not have any constructors, this is by design, please use
Sequence::to_relative_lock_time to create a relative lock time.
§Relevant BIPs
Variants§
Implementations§
§impl LockTime
impl LockTime
pub fn is_satisfied_by(&self, h: Height, t: Time) -> bool
pub fn is_satisfied_by(&self, h: Height, t: Time) -> bool
Returns true if this [relative::LockTime] is satisfied by either height or time.
§Examples
// Users that have chain data can get the current height and time to check against a lock.
let height_and_time = (current_time(), current_height()); // tuple order does not matter.
assert!(lock.is_satisfied_by(current_height(), current_time()));pub fn is_implied_by(&self, other: LockTime) -> bool
pub fn is_implied_by(&self, other: LockTime) -> bool
Returns true if satisfaction of other lock time implies satisfaction of this
[relative::LockTime].
A lock time can only be satisfied by n blocks being mined or n seconds passing. If you have two lock times (same unit) then the larger lock time being satisfied implies (in a mathematical sense) the smaller one being satisfied.
This function is useful when checking sequence values against a lock, first one checks the
sequence represents a relative lock time by converting to LockTime then use this function
to see if satisfaction of the newly created lock time would imply satisfaction of self.
Can also be used to remove the smaller value of two OP_CHECKSEQUENCEVERIFY operations
within one branch of the script.
§Examples
let satisfied = match test_sequence.to_relative_lock_time() {
None => false, // Handle non-lock-time case.
Some(test_lock) => lock.is_implied_by(test_lock),
};
assert!(satisfied);pub fn is_satisfied_by_height(&self, h: Height) -> Result<bool, Error>
pub fn is_satisfied_by_height(&self, h: Height) -> Result<bool, Error>
Returns true if this [relative::LockTime] is satisfied by Height.
§Errors
Returns an error if this lock is not lock-by-height.
§Examples
let height: u16 = 100;
let lock = Sequence::from_height(height).to_relative_lock_time().expect("valid height");
assert!(lock.is_satisfied_by_height(Height::from(height+1)).expect("a height"));pub fn is_satisfied_by_time(&self, t: Time) -> Result<bool, Error>
pub fn is_satisfied_by_time(&self, t: Time) -> Result<bool, Error>
Returns true if this [relative::LockTime] is satisfied by Time.
§Errors
Returns an error if this lock is not lock-by-time.
§Examples
let intervals: u16 = 70; // approx 10 hours;
let lock = Sequence::from_512_second_intervals(intervals).to_relative_lock_time().expect("valid time");
assert!(lock.is_satisfied_by_time(Time::from_512_second_intervals(intervals + 10)).expect("a time"));Trait Implementations§
§impl<'de> Deserialize<'de> for LockTime
impl<'de> Deserialize<'de> for LockTime
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<LockTime, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<LockTime, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl Serialize for LockTime
impl Serialize for LockTime
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for LockTime
impl Eq for LockTime
impl StructuralPartialEq for LockTime
Auto Trait Implementations§
impl Freeze for LockTime
impl RefUnwindSafe for LockTime
impl Send for LockTime
impl Sync for LockTime
impl Unpin for LockTime
impl UnwindSafe for LockTime
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: AsAny + ?Sized,
impl<T> Downcast for Twhere
T: AsAny + ?Sized,
§fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
Any.§fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
Any.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.