Skip to content

Commit 3003963

Browse files
committed
locktime: replace serde impl with u32-based one
This completely changes the serde format for `LockTime`, which in turn changes the format for `Transaction`. This will break e.g. hal-elements. However, the existing format is kinda ridiculous and I don't believe it is used anywhere. Alarmingly this change does not break a single test. We should add some regression tests.
1 parent 186515f commit 3003963

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/locktime.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ pub const LOCK_TIME_THRESHOLD: u32 = 500_000_000;
6666
/// ```
6767
#[allow(clippy::derive_ord_xor_partial_ord)]
6868
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
69-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7069
pub enum LockTime {
7170
/// A block height lock time value.
7271
///
@@ -275,6 +274,24 @@ impl fmt::Display for LockTime {
275274
}
276275
}
277276

277+
#[cfg(feature = "serde")]
278+
impl serde::Serialize for LockTime {
279+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
280+
where
281+
S: serde::Serializer {
282+
self.to_consensus_u32().serialize(serializer)
283+
}
284+
}
285+
286+
#[cfg(feature = "serde")]
287+
impl<'de> serde::Deserialize<'de> for LockTime {
288+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
289+
where
290+
D: serde::Deserializer<'de> {
291+
u32::deserialize(deserializer).map(Self::from_consensus)
292+
}
293+
}
294+
278295
impl Encodable for LockTime {
279296
#[inline]
280297
fn consensus_encode<W: Write>(&self, w: W) -> Result<usize, encode::Error> {

0 commit comments

Comments
 (0)