Skip to main content

revive_common/
evm_version.rs

1//! The EVM version.
2
3use serde::Deserialize;
4use serde::Serialize;
5
6/// The EVM version.
7#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
8#[serde(rename_all = "camelCase")]
9pub enum EVMVersion {
10    /// The corresponding EVM version.
11    #[serde(rename = "homestead")]
12    Homestead,
13    /// The corresponding EVM version.
14    #[serde(rename = "tangerineWhistle")]
15    TangerineWhistle,
16    /// The corresponding EVM version.
17    #[serde(rename = "spuriousDragon")]
18    SpuriousDragon,
19    /// The corresponding EVM version.
20    #[serde(rename = "byzantium")]
21    Byzantium,
22    /// The corresponding EVM version.
23    #[serde(rename = "constantinople")]
24    Constantinople,
25    /// The corresponding EVM version.
26    #[serde(rename = "petersburg")]
27    Petersburg,
28    /// The corresponding EVM version.
29    #[serde(rename = "istanbul")]
30    Istanbul,
31    /// The corresponding EVM version.
32    #[serde(rename = "berlin")]
33    Berlin,
34    /// The corresponding EVM version.
35    #[serde(rename = "london")]
36    London,
37    /// The corresponding EVM version.
38    #[serde(rename = "paris")]
39    Paris,
40    /// The corresponding EVM version.
41    #[serde(rename = "shanghai")]
42    Shanghai,
43    /// The corresponding EVM version.
44    #[serde(rename = "cancun")]
45    Cancun,
46    /// The corresponding EVM version.
47    #[serde(rename = "prague")]
48    Prague,
49    /// The corresponding EVM version.
50    #[serde(rename = "osaka")]
51    Osaka,
52}
53
54impl TryFrom<&str> for EVMVersion {
55    type Error = anyhow::Error;
56
57    fn try_from(value: &str) -> Result<Self, Self::Error> {
58        Ok(match value {
59            "homestead" => Self::Homestead,
60            "tangerineWhistle" => Self::TangerineWhistle,
61            "spuriousDragon" => Self::SpuriousDragon,
62            "byzantium" => Self::Byzantium,
63            "constantinople" => Self::Constantinople,
64            "petersburg" => Self::Petersburg,
65            "istanbul" => Self::Istanbul,
66            "berlin" => Self::Berlin,
67            "london" => Self::London,
68            "paris" => Self::Paris,
69            "shanghai" => Self::Shanghai,
70            "cancun" => Self::Cancun,
71            "prague" => Self::Prague,
72            "osaka" => Self::Osaka,
73            _ => anyhow::bail!("Invalid EVM version: {}", value),
74        })
75    }
76}
77
78impl std::fmt::Display for EVMVersion {
79    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80        match self {
81            Self::Homestead => write!(f, "homestead"),
82            Self::TangerineWhistle => write!(f, "tangerineWhistle"),
83            Self::SpuriousDragon => write!(f, "spuriousDragon"),
84            Self::Byzantium => write!(f, "byzantium"),
85            Self::Constantinople => write!(f, "constantinople"),
86            Self::Petersburg => write!(f, "petersburg"),
87            Self::Istanbul => write!(f, "istanbul"),
88            Self::Berlin => write!(f, "berlin"),
89            Self::London => write!(f, "london"),
90            Self::Paris => write!(f, "paris"),
91            Self::Shanghai => write!(f, "shanghai"),
92            Self::Cancun => write!(f, "cancun"),
93            Self::Prague => write!(f, "prague"),
94            Self::Osaka => write!(f, "osaka"),
95        }
96    }
97}