diff --git a/primitives/src/locktime/relative.rs b/primitives/src/locktime/relative.rs index 56edad60b..fd58ff1db 100644 --- a/primitives/src/locktime/relative.rs +++ b/primitives/src/locktime/relative.rs @@ -213,6 +213,54 @@ impl LockTime { } } + /// Returns true if an output with this locktime can be spent in the next block. + /// + /// If this function returns true then an output with this locktime can be spent in the next + /// block. + /// + /// # Errors + /// + /// Returns an error if this lock is not lock-by-height. + #[inline] + pub fn is_satisfied_by_height( + self, + chain_tip: BlockHeight, + utxo_mined_at: BlockHeight, + ) -> Result { + use LockTime as L; + + match self { + L::Blocks(blocks) => blocks + .is_satisfied_by(chain_tip, utxo_mined_at) + .map_err(IsSatisfiedByHeightError::Satisfaction), + L::Time(time) => Err(IsSatisfiedByHeightError::Incompatible(time)), + } + } + + /// Returns true if an output with this locktime can be spent in the next block. + /// + /// If this function returns true then an output with this locktime can be spent in the next + /// block. + /// + /// # Errors + /// + /// Returns an error if this lock is not lock-by-time. + #[inline] + pub fn is_satisfied_by_time( + self, + chain_tip: BlockMtp, + utxo_mined_at: BlockMtp, + ) -> Result { + use LockTime as L; + + match self { + L::Time(time) => time + .is_satisfied_by(chain_tip, utxo_mined_at) + .map_err(IsSatisfiedByTimeError::Satisfaction), + L::Blocks(blocks) => Err(IsSatisfiedByTimeError::Incompatible(blocks)), + } + } + /// Returns true if satisfaction of `other` lock time implies satisfaction of this /// [`relative::LockTime`]. /// @@ -281,54 +329,6 @@ impl LockTime { false } } - - /// Returns true if an output with this locktime can be spent in the next block. - /// - /// If this function returns true then an output with this locktime can be spent in the next - /// block. - /// - /// # Errors - /// - /// Returns an error if this lock is not lock-by-height. - #[inline] - pub fn is_satisfied_by_height( - self, - chain_tip: BlockHeight, - utxo_mined_at: BlockHeight, - ) -> Result { - use LockTime as L; - - match self { - L::Blocks(blocks) => blocks - .is_satisfied_by(chain_tip, utxo_mined_at) - .map_err(IsSatisfiedByHeightError::Satisfaction), - L::Time(time) => Err(IsSatisfiedByHeightError::Incompatible(time)), - } - } - - /// Returns true if an output with this locktime can be spent in the next block. - /// - /// If this function returns true then an output with this locktime can be spent in the next - /// block. - /// - /// # Errors - /// - /// Returns an error if this lock is not lock-by-time. - #[inline] - pub fn is_satisfied_by_time( - self, - chain_tip: BlockMtp, - utxo_mined_at: BlockMtp, - ) -> Result { - use LockTime as L; - - match self { - L::Time(time) => time - .is_satisfied_by(chain_tip, utxo_mined_at) - .map_err(IsSatisfiedByTimeError::Satisfaction), - L::Blocks(blocks) => Err(IsSatisfiedByTimeError::Incompatible(blocks)), - } - } } impl From for LockTime {