Skip to content

Commit

Permalink
chore: move Header and SealedHeader to reth-primitives-traits (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
joshieDo authored Jun 14, 2024
1 parent ca574ed commit 217ff95
Show file tree
Hide file tree
Showing 14 changed files with 839 additions and 787 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,10 @@ alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "00d81d7",
"eth",
] }
alloy-rpc-types-anvil = { git = "https://github.com/alloy-rs/alloy", rev = "00d81d7", default-features = false }
alloy-rpc-types-trace = { git = "https://github.com/alloy-rs/alloy", rev = "00d81d7", default-features = false }
alloy-rpc-types-engine = { git = "https://github.com/alloy-rs/alloy", rev = "00d81d7", default-features = false }
alloy-rpc-types-beacon = { git = "https://github.com/alloy-rs/alloy", rev = "00d81d7", default-features = false }
alloy-rpc-types-engine = { git = "https://github.com/alloy-rs/alloy", rev = "00d81d7", default-features = false }
alloy-rpc-types-eth = { git = "https://github.com/alloy-rs/alloy", rev = "00d81d7", default-features = false }
alloy-rpc-types-trace = { git = "https://github.com/alloy-rs/alloy", rev = "00d81d7", default-features = false }
alloy-genesis = { git = "https://github.com/alloy-rs/alloy", rev = "00d81d7", default-features = false }
alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "00d81d7", default-features = false }
alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "00d81d7", default-features = false, features = [
Expand Down
12 changes: 10 additions & 2 deletions crates/primitives-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ workspace = true
[dependencies]
reth-codecs.workspace = true

alloy-consensus.workspace = true
alloy-eips.workspace = true
alloy-genesis.workspace = true
alloy-primitives.workspace = true
alloy-consensus.workspace = true
alloy-rlp.workspace = true
alloy-rpc-types-eth = { workspace = true, optional = true }

derive_more.workspace = true
revm-primitives.workspace = true

# required by reth-codecs
modular-bitfield.workspace = true
Expand All @@ -33,11 +39,13 @@ arbitrary = { workspace = true, features = ["derive"] }
proptest.workspace = true
proptest-derive.workspace = true
test-fuzz.workspace = true
rand.workspace = true

[features]
test-utils = ["arbitrary"]
arbitrary = [
"dep:arbitrary",
"dep:proptest",
"dep:proptest-derive"
]

alloy-compat = ["alloy-rpc-types-eth"]
48 changes: 48 additions & 0 deletions crates/primitives-traits/src/alloy_compat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use super::Header;
use alloy_rpc_types_eth::{ConversionError, Header as RpcHeader};

impl TryFrom<RpcHeader> for Header {
type Error = ConversionError;

fn try_from(header: RpcHeader) -> Result<Self, Self::Error> {
Ok(Self {
base_fee_per_gas: header
.base_fee_per_gas
.map(|base_fee_per_gas| {
base_fee_per_gas.try_into().map_err(ConversionError::BaseFeePerGasConversion)
})
.transpose()?,
beneficiary: header.miner,
blob_gas_used: header
.blob_gas_used
.map(|blob_gas_used| {
blob_gas_used.try_into().map_err(ConversionError::BlobGasUsedConversion)
})
.transpose()?,
difficulty: header.difficulty,
excess_blob_gas: header
.excess_blob_gas
.map(|excess_blob_gas| {
excess_blob_gas.try_into().map_err(ConversionError::ExcessBlobGasConversion)
})
.transpose()?,
extra_data: header.extra_data,
gas_limit: header.gas_limit.try_into().map_err(ConversionError::GasLimitConversion)?,
gas_used: header.gas_used.try_into().map_err(ConversionError::GasUsedConversion)?,
logs_bloom: header.logs_bloom,
mix_hash: header.mix_hash.unwrap_or_default(),
nonce: u64::from_be_bytes(header.nonce.unwrap_or_default().0),
number: header.number.ok_or(ConversionError::MissingBlockNumber)?,
ommers_hash: header.uncles_hash,
parent_beacon_block_root: header.parent_beacon_block_root,
parent_hash: header.parent_hash,
receipts_root: header.receipts_root,
state_root: header.state_root,
timestamp: header.timestamp,
transactions_root: header.transactions_root,
withdrawals_root: header.withdrawals_root,
// TODO: requests_root: header.requests_root,
requests_root: None,
})
}
}
8 changes: 8 additions & 0 deletions crates/primitives-traits/src/header/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// Errors that can occur during header sanity checks.
#[derive(Debug, PartialEq, Eq)]
pub enum HeaderError {
/// Represents an error when the block difficulty is too large.
LargeDifficulty,
/// Represents an error when the block extradata is too large.
LargeExtraData,
}
Loading

0 comments on commit 217ff95

Please sign in to comment.