feat: add activation_block method for Ethereum hardforks (#5723)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Thomas Coratger
2024-01-13 11:26:32 +01:00
committed by GitHub
parent 8761072977
commit b08371b565
3 changed files with 41 additions and 1 deletions

1
Cargo.lock generated
View File

@ -6114,6 +6114,7 @@ dependencies = [
name = "reth-ethereum-forks" name = "reth-ethereum-forks"
version = "0.1.0-alpha.14" version = "0.1.0-alpha.14"
dependencies = [ dependencies = [
"alloy-chains",
"alloy-primitives", "alloy-primitives",
"alloy-rlp", "alloy-rlp",
"arbitrary", "arbitrary",

View File

@ -16,6 +16,7 @@ workspace = true
reth-codecs.workspace = true reth-codecs.workspace = true
# ethereum # ethereum
alloy-chains.workspace = true
alloy-primitives = { workspace = true, features = ["rand", "rlp"] } alloy-primitives = { workspace = true, features = ["rand", "rlp"] }
alloy-rlp = { workspace = true, features = ["arrayvec"] } alloy-rlp = { workspace = true, features = ["arrayvec"] }

View File

@ -1,5 +1,5 @@
use alloy_chains::Chain;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{fmt::Display, str::FromStr}; use std::{fmt::Display, str::FromStr};
/// The name of an Ethereum hardfork. /// The name of an Ethereum hardfork.
@ -51,6 +51,44 @@ pub enum Hardfork {
Cancun, Cancun,
} }
impl Hardfork {
/// Retrieves the activation block for the specified hardfork on the Ethereum mainnet.
pub fn mainnet_activation_block(&self, chain: Chain) -> Option<u64> {
if chain != Chain::mainnet() {
return None;
}
match self {
Hardfork::Frontier => Some(0),
Hardfork::Homestead => Some(1150000),
Hardfork::Dao => Some(1920000),
Hardfork::Tangerine => Some(2463000),
Hardfork::SpuriousDragon => Some(2675000),
Hardfork::Byzantium => Some(4370000),
Hardfork::Constantinople => Some(7280000),
Hardfork::Petersburg => Some(7280000),
Hardfork::Istanbul => Some(9069000),
Hardfork::MuirGlacier => Some(9200000),
Hardfork::Berlin => Some(12244000),
Hardfork::London => Some(12965000),
Hardfork::ArrowGlacier => Some(13773000),
Hardfork::GrayGlacier => Some(15050000),
Hardfork::Paris => Some(15537394),
Hardfork::Shanghai => Some(17034870),
// upcoming hardforks
Hardfork::Cancun => None,
// optimism hardforks
#[cfg(feature = "optimism")]
Hardfork::Bedrock => None,
#[cfg(feature = "optimism")]
Hardfork::Regolith => None,
#[cfg(feature = "optimism")]
Hardfork::Canyon => None,
}
}
}
impl FromStr for Hardfork { impl FromStr for Hardfork {
type Err = String; type Err = String;