mini_bitcoin_script/
error.rs1#[derive(Debug, Clone, PartialEq, Eq)]
3pub enum ScriptError {
4 StackUnderflow,
6
7 UnexpectedEndOfScript,
9
10 InvalidPushData,
12
13 UnsupportedOpcode(u8),
15
16 VerifyFailed,
18
19 ScriptFailed,
21
22 OpReturnEncountered,
24
25 UnbalancedConditional,
27
28 InvalidHex,
30}
31
32impl std::fmt::Display for ScriptError {
33 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 match self {
35 ScriptError::StackUnderflow => {
36 write!(f, "stack underflow: not enough elements on the stack")
37 }
38 ScriptError::UnexpectedEndOfScript => {
39 write!(f, "unexpected end of script")
40 }
41 ScriptError::InvalidPushData => {
42 write!(f, "invalid push data encoding")
43 }
44 ScriptError::UnsupportedOpcode(b) => {
45 write!(f, "unsupported opcode: 0x{b:02x}")
46 }
47 ScriptError::VerifyFailed => {
48 write!(f, "verify failed: top stack element is false")
49 }
50 ScriptError::ScriptFailed => {
51 write!(f, "script failed: final stack state is false")
52 }
53 ScriptError::OpReturnEncountered => {
54 write!(f, "OP_RETURN encountered: script is unspendable")
55 }
56 ScriptError::UnbalancedConditional => {
57 write!(f, "unbalanced conditional: mismatched IF/ELSE/ENDIF")
58 }
59 ScriptError::InvalidHex => {
60 write!(f, "invalid hex string")
61 }
62 }
63 }
64}
65
66impl std::error::Error for ScriptError {}