From 2d8227f09127383ac22464a45250ef1adad79242 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 21 Feb 2025 09:32:35 +1100 Subject: [PATCH] Hide relative locktime error internals As part of the 1.0 effort and forward maintainability hide the internals of the two error types in the `relative` locktime module. Doing so allows us to remove the `non_exhaustive` attribute. Add getters to get at the error innards. --- primitives/src/locktime/relative.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/primitives/src/locktime/relative.rs b/primitives/src/locktime/relative.rs index 663223efe..5acd78169 100644 --- a/primitives/src/locktime/relative.rs +++ b/primitives/src/locktime/relative.rs @@ -401,12 +401,19 @@ impl std::error::Error for DisabledLockTimeError {} /// Tried to satisfy a lock-by-blocktime lock using a height value. #[derive(Debug, Clone, PartialEq, Eq)] -#[non_exhaustive] pub struct IncompatibleHeightError { /// Attempted to satisfy a lock-by-blocktime lock with this height. - pub height: Height, + height: Height, /// The inner time value of the lock-by-blocktime lock. - pub time: Time, + time: Time, +} + +impl IncompatibleHeightError { + /// Returns the height that was erroneously used to try and satisfy a lock-by-blocktime lock. + pub fn incompatible(&self) -> Height { self.height } + + /// Returns the time value of the lock-by-blocktime lock. + pub fn expected(&self) -> Time { self.time } } impl fmt::Display for IncompatibleHeightError { @@ -424,12 +431,19 @@ impl std::error::Error for IncompatibleHeightError {} /// Tried to satisfy a lock-by-blockheight lock using a time value. #[derive(Debug, Clone, PartialEq, Eq)] -#[non_exhaustive] pub struct IncompatibleTimeError { /// Attempted to satisfy a lock-by-blockheight lock with this time. - pub time: Time, + time: Time, /// The inner height value of the lock-by-blockheight lock. - pub height: Height, + height: Height, +} + +impl IncompatibleTimeError { + /// Returns the time that was erroneously used to try and satisfy a lock-by-blockheight lock. + pub fn incompatible(&self) -> Time { self.time } + + /// Returns the height value of the lock-by-blockheight lock. + pub fn expected(&self) -> Height { self.height } } impl fmt::Display for IncompatibleTimeError {