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
//! Events interface and errors.

/// Event interface
pub trait Event {
    /// Emits &self in the current environment.
    fn emit(&self);
    /// Returns the event name.
    fn name(&self) -> String;
}

/// Event-related errors.
#[derive(Debug, PartialEq, Eq, PartialOrd)]
pub enum EventError {
    /// The type of event is different than expected.
    UnexpectedType(String),
    /// Index of the event is out of bounds.
    IndexOutOfBounds,
    /// Formatting error while deserializing.
    Formatting,
    /// Unexpected error while deserializing.
    Parsing,
}

impl From<casper_types::bytesrepr::Error> for EventError {
    fn from(err: casper_types::bytesrepr::Error) -> Self {
        match err {
            casper_types::bytesrepr::Error::Formatting => Self::Formatting,
            _ => Self::Parsing,
        }
    }
}