Skip to content

Commit

Permalink
feat: make block struct generic over header type (#1179)
Browse files Browse the repository at this point in the history
* make block struct generic over header type

* add generic default, make some changes

* change generic name and self
  • Loading branch information
mvares authored Aug 23, 2024
1 parent 974684b commit 8a06509
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
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

0 comments on commit 8a06509

Please sign in to comment.