Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make block struct generic over header type #1179

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/network/src/any/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ impl Network for AnyNetwork {

type HeaderResponse = Header;

type BlockResponse = WithOtherFields<Block<Self::TransactionResponse>>;
type BlockResponse = WithOtherFields<Block<Self::HeaderResponse, Self::TransactionResponse>>;
}
10 changes: 5 additions & 5 deletions crates/rpc-types-eth/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ pub use alloy_eips::{
/// Block representation
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Block<T = Transaction> {
pub struct Block<H = Header, T = Transaction> {
/// Header of the block.
#[serde(flatten)]
pub header: Header,
pub header: H,
/// Uncles' hashes.
#[serde(default)]
pub uncles: Vec<B256>,
Expand All @@ -36,7 +36,7 @@ pub struct Block<T = Transaction> {
pub withdrawals: Option<Vec<Withdrawal>>,
}

impl Block {
impl<H> Block<H> {
/// Converts a block with Tx hashes into a full block.
pub fn into_full_block(self, txs: Vec<Transaction>) -> Self {
Self { transactions: txs.into(), ..self }
Expand Down Expand Up @@ -334,9 +334,9 @@ pub struct BlockOverrides {
pub block_hash: Option<BTreeMap<u64, B256>>,
}

impl<T> BlockResponse for Block<T> {
impl<H, T> BlockResponse for Block<H, T> {
type Transaction = T;
type Header = Header;
type Header = H;

fn header(&self) -> &Self::Header {
&self.header
Expand Down