multiversx_sc_scenario/scenario/model/esdt_data/
esdt_map_check.rs

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
36
37
38
39
40
41
42
use crate::scenario_format::{
    interpret_trait::{InterpretableFrom, InterpreterContext, IntoRaw},
    serde_raw::CheckEsdtMapRaw,
};

use super::CheckEsdtMapContents;

#[derive(Debug, Clone, Default)]
pub enum CheckEsdtMap {
    #[default]
    Unspecified,
    Star,
    Equal(CheckEsdtMapContents),
}

impl CheckEsdtMap {
    pub fn is_star(&self) -> bool {
        matches!(self, CheckEsdtMap::Star)
    }
}

impl InterpretableFrom<CheckEsdtMapRaw> for CheckEsdtMap {
    fn interpret_from(from: CheckEsdtMapRaw, context: &InterpreterContext) -> Self {
        match from {
            CheckEsdtMapRaw::Unspecified => CheckEsdtMap::Unspecified,
            CheckEsdtMapRaw::Star => CheckEsdtMap::Star,
            CheckEsdtMapRaw::Equal(m) => {
                CheckEsdtMap::Equal(CheckEsdtMapContents::interpret_from(m, context))
            },
        }
    }
}

impl IntoRaw<CheckEsdtMapRaw> for CheckEsdtMap {
    fn into_raw(self) -> CheckEsdtMapRaw {
        match self {
            CheckEsdtMap::Unspecified => CheckEsdtMapRaw::Unspecified,
            CheckEsdtMap::Star => CheckEsdtMapRaw::Star,
            CheckEsdtMap::Equal(value) => CheckEsdtMapRaw::Equal(value.into_raw()),
        }
    }
}