multiversx_sc_meta_lib/ei/
ei_version.rs

1/// The version of the SC environment interface (EI), it deals with the VM hooks available at a certain point in time.
2///
3/// It is not tied to the version of the VM, hence the different numbering.
4#[derive(Clone, Copy, Default, Debug, PartialEq, Eq)]
5pub enum EIVersion {
6    /// This is not necessarily the first version of the EI,
7    /// but rather the oldest version when we started keeping track of the EI.
8    V1_0,
9
10    /// New hooks added in Q4 2021.
11    ///
12    /// Added a few more managed type & ESDT utilities.
13    V1_1,
14
15    /// New hooks added in Q2 2022. This is the EI version of VM 1.4.
16    ///
17    /// This is the version currently on mainnet.
18    ///
19    /// Added:
20    /// - more managed type conversions
21    /// - more managed crypto hooks
22    /// - big floats
23    /// - some managed ESDT properties.
24    V1_2,
25
26    /// Latest VM Hooks version, released with VM 1.5 in January 2024: https://multiversx.com/release/release-sirius-v1-6-7
27    ///
28    /// It adds the new async call functionality (promises).
29    V1_3,
30
31    /// Hooks made available in the Spica release, November 12, 2024: https://multiversx.com/release/release-spica-v1-8-4-0
32    V1_4,
33
34    /// Hooks made available in the Barnard release, activated July 26 2025: https://multiversx.com/release/release-barnard-v1-10-4
35    #[default]
36    V1_5,
37}
38
39impl EIVersion {
40    pub fn from_name(name: &str) -> Option<Self> {
41        match name {
42            "1.0" => Some(EIVersion::V1_0),
43            "1.1" => Some(EIVersion::V1_1),
44            "1.2" => Some(EIVersion::V1_2),
45            "1.3" => Some(EIVersion::V1_3),
46            "1.4" => Some(EIVersion::V1_4),
47            "1.5" => Some(EIVersion::V1_5),
48            _ => None,
49        }
50    }
51
52    pub fn name(&self) -> &'static str {
53        match self {
54            EIVersion::V1_0 => "1.0",
55            EIVersion::V1_1 => "1.1",
56            EIVersion::V1_2 => "1.2",
57            EIVersion::V1_3 => "1.3",
58            EIVersion::V1_4 => "1.4",
59            EIVersion::V1_5 => "1.5",
60        }
61    }
62
63    pub fn vm_hook_names(&self) -> &'static [&'static str] {
64        match self {
65            EIVersion::V1_0 => super::EI_1_0_NAMES,
66            EIVersion::V1_1 => super::EI_1_1_NAMES,
67            EIVersion::V1_2 => super::EI_1_2_NAMES,
68            EIVersion::V1_3 => super::EI_1_3_NAMES,
69            EIVersion::V1_4 => super::EI_1_4_NAMES,
70            EIVersion::V1_5 => super::EI_1_5_NAMES,
71        }
72    }
73
74    pub fn contains_vm_hook(&self, vm_hook_names: &str) -> bool {
75        self.vm_hook_names().contains(&vm_hook_names)
76    }
77}
78
79/// Parses an EIVersion, or returns None, if "ignore" was specifically stated.
80pub fn parse_check_ei(ei: &Option<String>) -> Option<EIVersion> {
81    if let Some(ei_name) = ei {
82        if ei_name == "ignore" {
83            None
84        } else {
85            let ei_version = EIVersion::from_name(ei_name)
86                .unwrap_or_else(|| panic!("invalid EI version: {ei_name}"));
87            Some(ei_version)
88        }
89    } else {
90        Some(EIVersion::default())
91    }
92}