simplify is_op_return() using map_or instead of match
What changed, and why it matters
This is a minor code cleanup that rewrites one function to use a more modern Rust helper method. It does not change what the function does or fix any security issue.
No action needed; this is a non-security refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors is_op_return() in bitcoin/src/blockdata/script/borrowed.rs to replace an explicit match on self.as_bytes().first() with is_some_and(|&b| b == OP_RETURN.to_u8()). The logic is identical: return true if and only if the first script byte equals the OP_RETURN opcode. There is no behavioral change, no boundary condition altered, and no security fix.
Changed components
bitcoin/src/blockdata/script/borrowed.rsInspect captured patch +1 / −4
diff --git a/bitcoin/src/blockdata/script/borrowed.rs b/bitcoin/src/blockdata/script/borrowed.rs
index ecace353..6cfcf4d8 100644
--- a/bitcoin/src/blockdata/script/borrowed.rs
+++ b/bitcoin/src/blockdata/script/borrowed.rs
@@ -401,10 +401,7 @@ internal_macros::define_extension_trait! {
/// [`is_standard_op_return()`](Self::is_standard_op_return) instead.
#[inline]
fn is_op_return(&self) -> bool {
- match self.as_bytes().first() {
- Some(b) => *b == OP_RETURN.to_u8(),
- None => false,
- }
+ self.as_bytes().first().is_some_and(|&b| b == OP_RETURN.to_u8())
}
/// Check if this is an OP_RETURN that obeys Bitcoin Core standardness policy.
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.