Skip to main content

bitcoin_rs_script/
opcodes.rs

1pub use bitcoin::blockdata::opcodes::all::*;
2
3/// Project-local opcode wrapper used by future hand-rolled interpreter code.
4#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
5pub struct OpCode(u8);
6
7impl OpCode {
8    /// Creates an opcode from its consensus byte.
9    #[must_use]
10    pub const fn new(value: u8) -> Self {
11        Self(value)
12    }
13
14    /// Returns the consensus opcode byte.
15    #[must_use]
16    pub const fn value(self) -> u8 {
17        self.0
18    }
19}
20
21impl From<bitcoin::blockdata::opcodes::Opcode> for OpCode {
22    fn from(opcode: bitcoin::blockdata::opcodes::Opcode) -> Self {
23        Self(opcode.to_u8())
24    }
25}
26
27impl From<OpCode> for bitcoin::blockdata::opcodes::Opcode {
28    fn from(opcode: OpCode) -> Self {
29        Self::from(opcode.value())
30    }
31}