Simplify control flow using Option and Result combinators
What changed, and why it matters
This commit is a pure code-style refactor. It rewrites two small functions in the relative locktime module to use Rust's functional method chaining instead of 'if let' and 'match' blocks. The behavior is unchanged: the same inputs produce the same outputs, and no security-sensitive logic was added or removed.
No security action needed. Treat as a normal readability refactor during code review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch replaces imperative control flow with Option/Result combinators in units/src/locktime/relative/mod.rs. is_implied_by_sequence now uses Result::is_ok_and. NumberOf512Seconds::is_satisfied_by now uses Option::ok_or followed by Result::map. These are semantically equivalent transformations; no arithmetic, validation rules, or error handling behavior changed.
Changed components
units/src/locktime/relative/mod.rsInspect captured patch +5 / −13
diff --git a/units/src/locktime/relative/mod.rs b/units/src/locktime/relative/mod.rs
index afeac947..837fd4e2 100644
--- a/units/src/locktime/relative/mod.rs
+++ b/units/src/locktime/relative/mod.rs
@@ -325,11 +325,7 @@ impl LockTime {
/// ```
#[inline]
pub fn is_implied_by_sequence(self, other: Sequence) -> bool {
- if let Ok(other) = Self::from_sequence(other) {
- self.is_implied_by(other)
- } else {
- false
- }
+ Self::from_sequence(other).is_ok_and(|other| self.is_implied_by(other))
}
}
@@ -620,14 +616,10 @@ impl NumberOf512Seconds {
chain_tip: crate::BlockMtp,
utxo_mined_at: crate::BlockMtp,
) -> Result<bool, InvalidTimeError> {
- match chain_tip.checked_sub(utxo_mined_at) {
- Some(diff) => {
- // The locktime check in Core during block validation uses the MTP of the previous
- // block - which is `chain_tip` here.
- Ok(self.to_seconds() <= diff.to_u32())
- }
- None => Err(InvalidTimeError { chain_tip, utxo_mined_at }),
- }
+ chain_tip
+ .checked_sub(utxo_mined_at)
+ .ok_or(InvalidTimeError { chain_tip, utxo_mined_at })
+ .map(|diff| self.to_seconds() <= diff.to_u32())
}
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.