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§
Source§impl LockTime
impl LockTime
Sourcepub 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()));Sourcepub 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);Sourcepub 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"));Sourcepub 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"));