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}
47
48impl TryFrom<&str> for EVMVersion {
49    type Error = anyhow::Error;
50
51    fn try_from(value: &str) -> Result<Self, Self::Error> {
52        Ok(match value {
53            "homestead" => Self::Homestead,
54            "tangerineWhistle" => Self::TangerineWhistle,
55            "spuriousDragon" => Self::SpuriousDragon,
56            "byzantium" => Self::Byzantium,
57            "constantinople" => Self::Constantinople,
58            "petersburg" => Self::Petersburg,
59            "istanbul" => Self::Istanbul,
60            "berlin" => Self::Berlin,
61            "london" => Self::London,
62            "paris" => Self::Paris,
63            "shanghai" => Self::Shanghai,
64            "cancun" => Self::Cancun,
65            _ => anyhow::bail!("Invalid EVM version: {}", value),
66        })
67    }
68}
69
70impl std::fmt::Display for EVMVersion {
71    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
72        match self {
73            Self::Homestead => write!(f, "homestead"),
74            Self::TangerineWhistle => write!(f, "tangerineWhistle"),
75            Self::SpuriousDragon => write!(f, "spuriousDragon"),
76            Self::Byzantium => write!(f, "byzantium"),
77            Self::Constantinople => write!(f, "constantinople"),
78            Self::Petersburg => write!(f, "petersburg"),
79            Self::Istanbul => write!(f, "istanbul"),
80            Self::Berlin => write!(f, "berlin"),
81            Self::London => write!(f, "london"),
82            Self::Paris => write!(f, "paris"),
83            Self::Shanghai => write!(f, "shanghai"),
84            Self::Cancun => write!(f, "cancun"),
85        }
86    }
87}