multiversx_sc_meta_lib/ei/
ei_version.rs

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