Skip to content

Commit

Permalink
chore(consensus): less derives for bincode compatible types (#1401)
Browse files Browse the repository at this point in the history
* chore(consensus): less derives for bincode compatible types

* less derives on doctests too
  • Loading branch information
shekhirin authored Sep 30, 2024
1 parent 16dbd30 commit f6a8e63
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 18 deletions.
6 changes: 2 additions & 4 deletions crates/consensus/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,15 +838,13 @@ pub(super) mod serde_bincode_compat {
/// use serde_with::serde_as;
///
/// #[serde_as]
/// #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
/// #[derive(Serialize, Deserialize)]
/// struct Data {
/// #[serde_as(as = "serde_bincode_compat::Header")]
/// header: Header,
/// }
/// ```
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[derive(Debug, Serialize, Deserialize)]
pub struct Header<'a> {
parent_hash: B256,
ommers_hash: B256,
Expand Down
3 changes: 2 additions & 1 deletion crates/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub use signed::Signed;
#[cfg(all(feature = "serde", feature = "serde-bincode-compat"))]
pub mod serde_bincode_compat {
pub use super::{
header::serde_bincode_compat::*, transaction::serde_bincode_compat as transaction,
header::serde_bincode_compat::*,
transaction::{serde_bincode_compat as transaction, serde_bincode_compat::*},
};
}
6 changes: 2 additions & 4 deletions crates/consensus/src/transaction/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,13 @@ pub(super) mod serde_bincode_compat {
/// use serde_with::serde_as;
///
/// #[serde_as]
/// #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
/// #[derive(Serialize, Deserialize)]
/// struct Data {
/// #[serde_as(as = "serde_bincode_compat::transaction::TxEip1559")]
/// transaction: TxEip1559,
/// }
/// ```
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[derive(Debug, Serialize, Deserialize)]
pub struct TxEip1559<'a> {
chain_id: ChainId,
nonce: u64,
Expand Down
6 changes: 2 additions & 4 deletions crates/consensus/src/transaction/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,13 @@ pub(super) mod serde_bincode_compat {
/// use serde_with::serde_as;
///
/// #[serde_as]
/// #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
/// #[derive(Serialize, Deserialize)]
/// struct Data {
/// #[serde_as(as = "serde_bincode_compat::transaction::TxEip2930")]
/// transaction: TxEip2930,
/// }
/// ```
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[derive(Debug, Serialize, Deserialize)]
pub struct TxEip2930<'a> {
chain_id: ChainId,
nonce: u64,
Expand Down
8 changes: 3 additions & 5 deletions crates/consensus/src/transaction/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,13 @@ pub(super) mod serde_bincode_compat {
/// use serde_with::serde_as;
///
/// #[serde_as]
/// #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
/// #[derive(Serialize, Deserialize)]
/// struct Data {
/// #[serde_as(as = "serde_bincode_compat::transaction::TxLegacy")]
/// header: TxLegacy,
/// }
/// ```
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[derive(Debug, Serialize, Deserialize)]
pub struct TxLegacy<'a> {
#[serde(default, with = "alloy_serde::quantity::opt")]
chain_id: Option<ChainId>,
Expand Down Expand Up @@ -484,7 +482,7 @@ pub(super) mod serde_bincode_compat {
use super::super::{serde_bincode_compat, TxLegacy};

#[test]
fn test_tx_eip1559_bincode_roundtrip() {
fn test_tx_legacy_bincode_roundtrip() {
#[serde_as]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
struct Data {
Expand Down

0 comments on commit f6a8e63

Please sign in to comment.