What changed, and why it matters
This commit is a routine internal code reorganization. It moves the implementation of a function that returns the human-readable name of a Bitcoin script opcode from one place in the source file to another. The public behavior of the library does not change, and there is no security relevance.
No security action required. Treat as normal maintenance/refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors Opcode::as_str() in bitcoin/src/blockdata/opcodes.rs. Previously, as_str was defined inside a macro-generated impl Opcode block within the all module. The change introduces a pub(super) helper opcode_to_str inside the all module and redefines Opcode::as_str outside the module to call that helper. This is a pure refactor to prepare for moving code to a future primitives crate/extension trait. The generated match arms and return type (&'static str) are identical; no logic or API contract changes.
Changed components
bitcoin/src/blockdata/opcodes.rsInspect captured patch +21 / −21
diff --git a/bitcoin/src/blockdata/opcodes.rs b/bitcoin/src/blockdata/opcodes.rs
index ac8dfa02..ea69a258 100644
--- a/bitcoin/src/blockdata/opcodes.rs
+++ b/bitcoin/src/blockdata/opcodes.rs
@@ -45,27 +45,12 @@ macro_rules! all_opcodes {
pub const $op: Opcode = Opcode { code: $val};
)*
- impl Opcode {
- /// Returns the string representation of the opcode.
- ///
- /// This function maps the `Opcode`'s `code` value (a `u8`) to its corresponding
- /// Bitcoin Script opcode name.
- ///
- /// # Example
- /// ```
- /// use bitcoin::opcodes::all::*;
- ///
- /// assert_eq!(OP_1.as_str(), "OP_1");
- /// assert_eq!(OP_1NEGATE.as_str(), "OP_1NEGATE");
- /// assert_eq!(OP_CHECKMULTISIG.as_str(), "OP_CHECKMULTISIG");
- /// ```
- #[inline]
- pub fn as_str(&self) -> &'static str {
- match *self {
- $(
- $op => stringify!($op),
- )+
- }
+ /// Helper function for as_str in OpcodeExt.
+ pub(super) fn opcode_to_str(opcode: Opcode) -> &'static str {
+ match opcode {
+ $(
+ $op => stringify!($op),
+ )+
}
}
@@ -501,6 +486,21 @@ impl Opcode {
_ => None,
}
}
+ /// Returns the string representation of the opcode.
+ ///
+ /// This function maps the `Opcode`'s `code` value (a `u8`) to its corresponding
+ /// Bitcoin Script opcode name.
+ ///
+ /// # Example
+ /// ```
+ /// use bitcoin::opcodes::all::*;
+ ///
+ /// assert_eq!(OP_1.as_str(), "OP_1");
+ /// assert_eq!(OP_1NEGATE.as_str(), "OP_1NEGATE");
+ /// assert_eq!(OP_CHECKMULTISIG.as_str(), "OP_CHECKMULTISIG");
+ /// ```
+ #[inline]
+ pub fn as_str(&self) -> &'static str { all::opcode_to_str(*self) }
}
impl From<u8> for Opcode {
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.