Skip to content

Commit

Permalink
feat: extract optimism genesis info
Browse files Browse the repository at this point in the history
  • Loading branch information
Vid201 committed Jun 27, 2024
1 parent 5010111 commit bc76d55
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ alloy-primitives = { version = "0.7.1", default-features = false }

alloy = { version = "0.1" }
alloy-consensus = { version = "0.1", default-features = false}
alloy-genesis = { version = "0.1", default-features = false }
alloy-network = { version = "0.1", default-features = false }
alloy-rpc-types = { version = "0.1" }
alloy-rpc-types-eth = { version = "0.1" }
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exclude.workspace = true
[dependencies]
op-alloy-consensus = { workspace = true, features = ["serde"] }

alloy-genesis.workspace = true
alloy-primitives = { workspace = true, features = ["rlp", "serde", "std"] }
alloy-rpc-types-eth.workspace = true
alloy-network.workspace = true
Expand Down
21 changes: 21 additions & 0 deletions crates/rpc-types/src/genesis.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! OP types for genesis data.

use alloy_genesis::Genesis;

/// Genesis info for Optimism.
#[derive(Default, Debug, Clone, Copy, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -27,3 +29,22 @@ pub struct OptimismBaseFeeInfo {
/// EIP-1559 denominator after canyon
pub eip1559_denominator_canyon: Option<u64>,
}

impl OptimismGenesisInfo {
/// Extract the Optimism genesis info from the genesis.
pub fn extract_from(genesis: &Genesis) -> Option<Self> {
genesis.config.extra_fields.deserialize_as().ok()
}
}

impl OptimismBaseFeeInfo {
/// Extract the Optimism base fee info from the genesis.
pub fn extract_from(genesis: &Genesis) -> Option<Self> {
if let Some(Ok(optimism_base_fee_info)) =
genesis.config.extra_fields.get_deserialized::<OptimismBaseFeeInfo>("optimism")
{
return Some(optimism_base_fee_info);
}
None
}
}

0 comments on commit bc76d55

Please sign in to comment.