use std::num::TryFromIntError;
use serde::{Deserialize, Serialize};
use tari_utilities::ByteArrayError;
use thiserror::Error;
#[derive(Debug, Clone, Error, PartialEq, Eq, Serialize, Deserialize)]
pub enum ScriptError {
#[error("The script failed with an explicit Return")]
Return,
#[error("The stack cannot exceed MAX_STACK_SIZE items")]
StackOverflow,
#[error("The script completed execution with a stack size other than one")]
NonUnitLengthStack,
#[error("Tried to pop an element off an empty stack")]
StackUnderflow,
#[error("An operand was applied to incompatible types")]
IncompatibleTypes,
#[error("A script opcode resulted in a value that exceeded the maximum or minimum value")]
ValueExceedsBounds,
#[error("The script encountered an invalid opcode")]
InvalidOpcode,
#[error("The script is missing closing opcodes (Else or EndIf)")]
MissingOpcode,
#[error("The script contained an invalid signature")]
InvalidSignature,
#[error("The serialised stack contained invalid input")]
InvalidInput,
#[error("The script contained invalid data")]
InvalidData,
#[error("A verification opcode failed, aborting the script immediately")]
VerifyFailed,
#[error("as_hash requires a Digest function that returns at least 32 bytes")]
InvalidDigest,
}
impl From<TryFromIntError> for ScriptError {
fn from(_err: TryFromIntError) -> ScriptError {
ScriptError::ValueExceedsBounds
}
}
impl From<ByteArrayError> for ScriptError {
fn from(_err: ByteArrayError) -> ScriptError {
ScriptError::InvalidData
}
}