What changed, and why it matters
This commit simply moves the definition of the Opcode type from one internal module to another and re-exports it so existing code keeps working. It is a routine code reorganization with no functional or security changes.
No action required; this is a non-security refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit relocates the Opcode struct, its derive macros, and its inherent/From
Changed components
bitcoin/src/blockdata/opcodes.rsprimitives/src/opcodes.rsInspect captured patch +33 / −32
diff --git a/bitcoin/src/blockdata/opcodes.rs b/bitcoin/src/blockdata/opcodes.rs
index 0e09310e..f7a4527b 100644
--- a/bitcoin/src/blockdata/opcodes.rs
+++ b/bitcoin/src/blockdata/opcodes.rs
@@ -9,23 +9,7 @@
use core::fmt;
-/// A script Opcode.
-///
-/// We do not implement Ord on this type because there is no natural ordering on opcodes, but there
-/// may appear to be one (e.g. because all the push opcodes appear in a consecutive block) and we
-/// don't want to encourage subtly buggy code. Please use [`Opcode::classify`] to distinguish different
-/// types of opcodes.
-///
-/// <details>
-/// <summary>Example of Core bug caused by assuming ordering</summary>
-///
-/// Bitcoin Core's `IsPushOnly` considers `OP_RESERVED` to be a "push code", allowing this opcode
-/// in contexts where only pushes are supposed to be allowed.
-/// </details>
-#[derive(Debug, Copy, Clone, PartialEq, Eq)]
-pub struct Opcode {
- code: u8,
-}
+pub use primitives::opcodes::Opcode;
use self::all::*;
@@ -394,21 +378,6 @@ pub enum ClassifyContext {
Legacy,
}
-impl Opcode {
- /// Encodes [`Opcode`] as a byte.
- #[inline]
- pub const fn to_u8(self) -> u8 { self.code }
-
- /// Constructs an [`Opcode`] from a byte.
- #[inline]
- pub const fn from_u8(b: u8) -> Self { Self { code: b } }
-}
-
-impl From<u8> for Opcode {
- #[inline]
- fn from(b: u8) -> Self { Self::from_u8(b) }
-}
-
mod sealed {
pub trait Sealed {}
impl Sealed for super::Opcode {}
diff --git a/primitives/src/opcodes.rs b/primitives/src/opcodes.rs
index 02f83d99..01680d33 100644
--- a/primitives/src/opcodes.rs
+++ b/primitives/src/opcodes.rs
@@ -10,6 +10,38 @@
#[cfg(feature = "alloc")]
use core::fmt;
+/// A script opcode.
+///
+/// We do not implement `Ord` on this type because there is no natural ordering on opcodes, but there
+/// may appear to be one (e.g. because all the push opcodes appear in a consecutive block) and we
+/// don't want to encourage subtly buggy code.
+///
+/// <details>
+/// <summary>Example of Core bug caused by assuming ordering</summary>
+///
+/// Bitcoin Core's `IsPushOnly` considers `OP_RESERVED` to be a "push code", allowing this opcode
+/// in contexts where only pushes are supposed to be allowed.
+/// </details>
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
+pub struct Opcode {
+ code: u8,
+}
+
+impl Opcode {
+ /// Encodes [`Opcode`] as a byte.
+ #[inline]
+ pub const fn to_u8(self) -> u8 { self.code }
+
+ /// Constructs an [`Opcode`] from a byte.
+ #[inline]
+ pub const fn from_u8(b: u8) -> Self { Self { code: b } }
+}
+
+impl From<u8> for Opcode {
+ #[inline]
+ fn from(b: u8) -> Self { Self::from_u8(b) }
+}
+
/// Read the following byte as a length, and read the following
/// bytes as a push of that length.
#[cfg(feature = "alloc")]
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.