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

chore: remove RichBlock and RichHeader types #1185

Merged
merged 1 commit into from
Aug 26, 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
19 changes: 7 additions & 12 deletions crates/rpc-types-eth/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::{ConversionError, Transaction, Withdrawal};
use alloy_network_primitives::{BlockResponse, BlockTransactions, HeaderResponse};
use alloy_primitives::{Address, BlockHash, Bloom, Bytes, B256, B64, U256};
use alloy_serde::WithOtherFields;
use serde::{ser::Error, Deserialize, Serialize, Serializer};
use std::{collections::BTreeMap, ops::Deref};

Expand Down Expand Up @@ -234,21 +235,15 @@ pub enum BlockError {
RlpDecodeRawBlock(alloy_rlp::Error),
}

/// A Block representation that allows to include additional fields
pub type RichBlock = Rich<Block>;

impl From<Block> for RichBlock {
impl From<Block> for WithOtherFields<Block> {
fn from(inner: Block) -> Self {
Self { inner, extra_info: Default::default() }
Self { inner, other: Default::default() }
}
}

/// Header representation with additional info.
pub type RichHeader = Rich<Header>;

impl From<Header> for RichHeader {
impl From<Header> for WithOtherFields<Header> {
fn from(inner: Header) -> Self {
Self { inner, extra_info: Default::default() }
Self { inner, other: Default::default() }
}
}

Expand Down Expand Up @@ -536,9 +531,9 @@ mod tests {
"size": "0xaeb6"
}"#;

let block = serde_json::from_str::<RichBlock>(s).unwrap();
let block = serde_json::from_str::<WithOtherFields<Block>>(s).unwrap();
let serialized = serde_json::to_string(&block).unwrap();
let block2 = serde_json::from_str::<RichBlock>(&serialized).unwrap();
let block2 = serde_json::from_str::<WithOtherFields<Block>>(&serialized).unwrap();
assert_eq!(block, block2);
}

Expand Down
5 changes: 3 additions & 2 deletions crates/rpc-types-eth/src/pubsub.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
//! Ethereum types for pub-sub

use crate::{Filter, Log, RichHeader, Transaction};
use crate::{Filter, Header, Log, Transaction};
use alloy_primitives::B256;
use alloy_serde::WithOtherFields;
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};

/// Subscription result.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
#[serde(untagged)]
pub enum SubscriptionResult<T = Transaction> {
/// New block header.
Header(Box<RichHeader>),
Header(Box<WithOtherFields<Header>>),
/// Log
Log(Box<Log>),
/// Transaction hash
Expand Down