Skip to content

Commit b08371b

Browse files
tcoratgermattsse
andauthored
feat: add activation_block method for Ethereum hardforks (paradigmxyz#5723)
Co-authored-by: Matthias Seitz <[email protected]>
1 parent 8761072 commit b08371b

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ethereum-forks/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ workspace = true
1616
reth-codecs.workspace = true
1717

1818
# ethereum
19+
alloy-chains.workspace = true
1920
alloy-primitives = { workspace = true, features = ["rand", "rlp"] }
2021
alloy-rlp = { workspace = true, features = ["arrayvec"] }
2122

crates/ethereum-forks/src/hardfork.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use alloy_chains::Chain;
12
use serde::{Deserialize, Serialize};
2-
33
use std::{fmt::Display, str::FromStr};
44

55
/// The name of an Ethereum hardfork.
@@ -51,6 +51,44 @@ pub enum Hardfork {
5151
Cancun,
5252
}
5353

54+
impl Hardfork {
55+
/// Retrieves the activation block for the specified hardfork on the Ethereum mainnet.
56+
pub fn mainnet_activation_block(&self, chain: Chain) -> Option<u64> {
57+
if chain != Chain::mainnet() {
58+
return None;
59+
}
60+
match self {
61+
Hardfork::Frontier => Some(0),
62+
Hardfork::Homestead => Some(1150000),
63+
Hardfork::Dao => Some(1920000),
64+
Hardfork::Tangerine => Some(2463000),
65+
Hardfork::SpuriousDragon => Some(2675000),
66+
Hardfork::Byzantium => Some(4370000),
67+
Hardfork::Constantinople => Some(7280000),
68+
Hardfork::Petersburg => Some(7280000),
69+
Hardfork::Istanbul => Some(9069000),
70+
Hardfork::MuirGlacier => Some(9200000),
71+
Hardfork::Berlin => Some(12244000),
72+
Hardfork::London => Some(12965000),
73+
Hardfork::ArrowGlacier => Some(13773000),
74+
Hardfork::GrayGlacier => Some(15050000),
75+
Hardfork::Paris => Some(15537394),
76+
Hardfork::Shanghai => Some(17034870),
77+
78+
// upcoming hardforks
79+
Hardfork::Cancun => None,
80+
81+
// optimism hardforks
82+
#[cfg(feature = "optimism")]
83+
Hardfork::Bedrock => None,
84+
#[cfg(feature = "optimism")]
85+
Hardfork::Regolith => None,
86+
#[cfg(feature = "optimism")]
87+
Hardfork::Canyon => None,
88+
}
89+
}
90+
}
91+
5492
impl FromStr for Hardfork {
5593
type Err = String;
5694

0 commit comments

Comments
 (0)