eest_types/
spec_name.rs

1use super::spec_id::SpecId;
2use serde::Deserialize;
3
4/// Ethereum specification names
5#[derive(
6    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Deserialize, Hash,
7)]
8pub enum SpecName {
9    Frontier,
10    FrontierToHomesteadAt5,
11    Homestead,
12    HomesteadToDaoAt5,
13    HomesteadToEIP150At5,
14    EIP150,
15    EIP158, // EIP-161: State trie clearing
16    EIP158ToByzantiumAt5,
17    Byzantium,
18    ByzantiumToConstantinopleAt5, // SKIPPED
19    ByzantiumToConstantinopleFixAt5,
20    Constantinople, // SKIPPED
21    ConstantinopleFix,
22    Istanbul,
23    Berlin,
24    BerlinToLondonAt5,
25    London,
26    Paris,
27    Merge,
28    Shanghai,
29    Cancun,
30    Prague,
31    Osaka,
32    #[serde(other)]
33    Unknown,
34}
35
36impl SpecName {
37    /// Converts to a [SpecId].
38    pub fn to_spec_id(&self) -> SpecId {
39        match self {
40            Self::Frontier => SpecId::FRONTIER,
41            Self::Homestead | Self::FrontierToHomesteadAt5 => SpecId::HOMESTEAD,
42            Self::EIP150
43            | Self::HomesteadToDaoAt5
44            | Self::HomesteadToEIP150At5 => SpecId::TANGERINE,
45            Self::EIP158 => SpecId::SPURIOUS_DRAGON,
46            Self::Byzantium | Self::EIP158ToByzantiumAt5 => SpecId::BYZANTIUM,
47            Self::ConstantinopleFix | Self::ByzantiumToConstantinopleFixAt5 => {
48                SpecId::PETERSBURG
49            }
50            Self::Istanbul => SpecId::ISTANBUL,
51            Self::Berlin => SpecId::BERLIN,
52            Self::London | Self::BerlinToLondonAt5 => SpecId::LONDON,
53            Self::Paris | Self::Merge => SpecId::MERGE,
54            Self::Shanghai => SpecId::SHANGHAI,
55            Self::Cancun => SpecId::CANCUN,
56            Self::Prague => SpecId::PRAGUE,
57            Self::Osaka => SpecId::OSAKA,
58            Self::ByzantiumToConstantinopleAt5 | Self::Constantinople => {
59                panic!("Overridden with PETERSBURG")
60            }
61            Self::Unknown => panic!("Unknown spec"),
62        }
63    }
64}
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_spec_format() {
72        let spec = SpecName::Frontier;
73        assert_eq!(format!("{:?}", spec), "Frontier");
74
75        let spec = SpecName::Istanbul;
76        assert_eq!(format!("{:?}", spec), "Istanbul");
77
78        let spec = SpecName::Unknown;
79        assert_eq!(format!("{:?}", spec), "Unknown");
80    }
81}