1use {
4 num_derive::FromPrimitive,
5 gemachain_program::{decode_error::DecodeError, program_error::ProgramError},
6 thiserror::Error,
7};
8
9#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
11pub enum MathError {
12 #[error("Calculation overflowed the destination number")]
14 Overflow,
15 #[error("Calculation underflowed the destination number")]
17 Underflow,
18}
19impl From<MathError> for ProgramError {
20 fn from(e: MathError) -> Self {
21 ProgramError::Custom(e as u32)
22 }
23}
24impl<T> DecodeError<T> for MathError {
25 fn type_of() -> &'static str {
26 "Math Error"
27 }
28}