relative locktime: add is_implied_by method for sequences

This gives a way to determine whether a CSV will pass, given a sequence
number, in a type-safe way where you can't get the two things backward.
This commit is contained in:
Andrew Poelstra 2024-03-07 17:28:54 +00:00
parent 319e102fed
commit c2f87c7ab3
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 14 additions and 0 deletions

View File

@ -211,6 +211,20 @@ impl LockTime {
}
}
/// Returns true if satisfaction of the sequence number implies satisfaction of this lock time.
///
/// When deciding whether an instance of `<n> CHECKSEQUENCEVERIFY` will pass, this
/// method can be used by parsing `n` as a [`LockTime`] and calling this method
/// with the sequence number of the input which spends the script.
#[inline]
pub fn is_implied_by_sequence(&self, other: Sequence) -> bool {
if let Ok(other) = LockTime::from_sequence(other) {
self.is_implied_by(other)
} else {
false
}
}
/// Returns true if this [`relative::LockTime`] is satisfied by [`Height`].
///
/// # Errors