locktime: add `FromHexStr` impl for `LockTime`

This will be tested in a later commit, when `PackedLockTime` is folded
into this type so all its tests apply to `LockTime`.
This commit is contained in:
Andrew Poelstra 2022-12-11 18:59:24 +00:00
parent 74ff4946e4
commit fa81568fb6
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 9 additions and 0 deletions

View File

@ -423,6 +423,15 @@ impl fmt::Display for LockTime {
}
}
impl FromHexStr for LockTime {
type Error = Error;
fn from_hex_str_no_prefix<S: AsRef<str> + Into<String>>(s: S) -> Result<Self, Self::Error> {
let packed_lock_time = crate::parse::hex_u32(s)?;
Ok(Self::from_consensus(packed_lock_time))
}
}
impl Encodable for LockTime {
#[inline]
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {