relative locktime: use From/TryFrom to convert between relative locktimes and Sequence

This commit is contained in:
Andrew Poelstra 2024-03-07 17:24:43 +00:00
parent 0ed26915f6
commit 319e102fed
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 12 additions and 1 deletions

View File

@ -6,7 +6,7 @@
//! whether bit 22 of the `u32` consensus value is set. //! whether bit 22 of the `u32` consensus value is set.
//! //!
use core::{cmp, fmt}; use core::{cmp, convert, fmt};
#[cfg(all(test, mutate))] #[cfg(all(test, mutate))]
use mutagen::mutate; use mutagen::mutate;
@ -307,6 +307,17 @@ impl fmt::Display for LockTime {
} }
} }
impl convert::TryFrom<Sequence> for LockTime {
type Error = DisabledLockTimeError;
fn try_from(seq: Sequence) -> Result<LockTime, DisabledLockTimeError> {
LockTime::from_sequence(seq)
}
}
impl From<LockTime> for Sequence {
fn from(lt: LockTime) -> Sequence { lt.to_sequence() }
}
/// Error returned when a sequence number is parsed as a lock time, but its /// Error returned when a sequence number is parsed as a lock time, but its
/// "disable" flag is set. /// "disable" flag is set.
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq)]