1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use fuel_types::Word;

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(fuel_types::canonical::Deserialize, fuel_types::canonical::Serialize)]
#[repr(u64)]
pub enum ScriptExecutionResult {
    Success,
    Revert,
    Panic,
    // Generic failure case since any u64 is valid here
    GenericFailure(u64),
}

impl From<ScriptExecutionResult> for Word {
    fn from(result: ScriptExecutionResult) -> Self {
        match result {
            ScriptExecutionResult::Success => 0x00,
            ScriptExecutionResult::Revert => 0x01,
            ScriptExecutionResult::Panic => 0x02,
            ScriptExecutionResult::GenericFailure(value) => value,
        }
    }
}

impl From<Word> for ScriptExecutionResult {
    fn from(value: u64) -> Self {
        match value {
            0x00 => Self::Success,
            0x01 => Self::Revert,
            0x02 => Self::Panic,
            value => Self::GenericFailure(value),
        }
    }
}