diff --git a/crates/network-primitives/src/traits.rs b/crates/network-primitives/src/traits.rs index 64fc692cfa6..de6f4788796 100644 --- a/crates/network-primitives/src/traits.rs +++ b/crates/network-primitives/src/traits.rs @@ -1,4 +1,4 @@ -use alloy_primitives::{Address, BlockHash, Bytes, TxHash, U256}; +use alloy_primitives::{Address, BlockHash, Bytes, TxHash, B256, U256}; use alloy_serde::WithOtherFields; use crate::BlockTransactions; @@ -67,6 +67,30 @@ pub trait HeaderResponse { /// Blob fee for the next block (if EIP-4844 is supported) fn next_block_blob_fee(&self) -> Option; + + /// Coinbase/Miner of the block + fn coinbase(&self) -> Address; + + /// Gas limit of the block + fn gas_limit(&self) -> u128; + + /// Mix hash of the block + /// + /// Before the merge this proves, combined with the nonce, that a sufficient amount of + /// computation has been carried out on this block: the Proof-of-Work (PoW). + /// + /// After the merge this is `prevRandao`: Randomness value for the generated payload. + /// + /// This is an Option because it is not always set by non-ethereum networks. + /// + /// See also + /// And + fn mix_hash(&self) -> Option; + + /// Difficulty of the block + /// + /// Unused after the Paris (AKA the merge) upgrade, and replaced by `prevrandao`. + fn difficulty(&self) -> U256; } /// Block JSON-RPC response. @@ -84,6 +108,11 @@ pub trait BlockResponse { /// Mutable reference to block transactions fn transactions_mut(&mut self) -> &mut BlockTransactions; + + /// Returns the `other` field from `WithOtherFields` type. + fn other_fields(&self) -> Option<&alloy_serde::OtherFields> { + None + } } impl TransactionResponse for WithOtherFields { @@ -145,6 +174,10 @@ impl BlockResponse for WithOtherFields { fn transactions_mut(&mut self) -> &mut BlockTransactions { self.inner.transactions_mut() } + + fn other_fields(&self) -> Option<&alloy_serde::OtherFields> { + Some(&self.other) + } } impl HeaderResponse for WithOtherFields { @@ -171,4 +204,20 @@ impl HeaderResponse for WithOtherFields { fn next_block_blob_fee(&self) -> Option { self.inner.next_block_blob_fee() } + + fn coinbase(&self) -> Address { + self.inner.coinbase() + } + + fn gas_limit(&self) -> u128 { + self.inner.gas_limit() + } + + fn mix_hash(&self) -> Option { + self.inner.mix_hash() + } + + fn difficulty(&self) -> U256 { + self.inner.difficulty() + } } diff --git a/crates/rpc-types-eth/src/block.rs b/crates/rpc-types-eth/src/block.rs index 42474cdb549..5fd1cfa00e3 100644 --- a/crates/rpc-types-eth/src/block.rs +++ b/crates/rpc-types-eth/src/block.rs @@ -228,6 +228,22 @@ impl HeaderResponse for Header { fn next_block_blob_fee(&self) -> Option { self.next_block_blob_fee() } + + fn coinbase(&self) -> Address { + self.miner + } + + fn gas_limit(&self) -> u128 { + self.gas_limit + } + + fn mix_hash(&self) -> Option { + self.mix_hash + } + + fn difficulty(&self) -> U256 { + self.difficulty + } } /// Error that can occur when converting other types to blocks