Add method relative::LockTime::is_implied_by

As we just did for `absolute::LockTime` add a method `is_implied_by` and
deprecate `is_satisfied_by_lock`.

Reasoning: it is odd to think of a lock satisfying another lock but it
is clear to see that satisfaction of one lock can imply satisfaction of
another.
This commit is contained in:
Tobin C. Harding 2022-09-15 09:21:24 +10:00
parent d5492b8a25
commit b8721bf244
1 changed files with 7 additions and 6 deletions

View File

@ -62,11 +62,12 @@ impl LockTime {
} }
} }
/// Returns true if this [`relative::LockTime`] is satisfied by `other` lock. /// Returns true if satisfaction of `other` lock time implies satisfaction of this
/// [`relative::LockTime`].
/// ///
/// This function is useful when checking sequence values against a lock, first one checks the /// 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 /// sequence represents a relative lock time by converting to `LockTime` then use this function
/// to see if [`LockTime`] is satisfied by the newly created lock. /// to see if satisfaction of the newly created lock time would imply satisfaction of `self`.
/// ///
/// # Examples /// # Examples
/// ///
@ -80,16 +81,16 @@ impl LockTime {
/// ///
/// let satisfied = match test_sequence.to_relative_lock_time() { /// let satisfied = match test_sequence.to_relative_lock_time() {
/// None => false, // Handle non-lock-time case. /// None => false, // Handle non-lock-time case.
/// Some(test_lock) => lock.is_satisfied_by_lock(test_lock), /// Some(test_lock) => lock.is_implied_by(test_lock),
/// }; /// };
/// assert!(satisfied); /// assert!(satisfied);
/// ``` /// ```
pub fn is_satisfied_by_lock(&self, other: LockTime) -> bool { pub fn is_implied_by(&self, other: LockTime) -> bool {
use LockTime::*; use LockTime::*;
match (*self, other) { match (*self, other) {
(Blocks(n), Blocks(m)) => n.value() <= m.value(), (Blocks(this), Blocks(other)) => this.value() <= other.value(),
(Time(n), Time(m)) => n.value() <= m.value(), (Time(this), Time(other)) => this.value() <= other.value(),
_ => false, // Not the same units. _ => false, // Not the same units.
} }
} }