diff --git a/crates/primitives-traits/src/account.rs b/crates/primitives-traits/src/account.rs index 2a6546cc7..84192846d 100644 --- a/crates/primitives-traits/src/account.rs +++ b/crates/primitives-traits/src/account.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; /// An Ethereum account. #[reth_codec] -#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Serialize, Deserialize)] pub struct Account { /// Account nonce. pub nonce: u64, diff --git a/crates/primitives-traits/src/header/mod.rs b/crates/primitives-traits/src/header/mod.rs index 018ac5490..d6356805d 100644 --- a/crates/primitives-traits/src/header/mod.rs +++ b/crates/primitives-traits/src/header/mod.rs @@ -18,11 +18,12 @@ use bytes::BufMut; use core::mem; use reth_codecs::{add_arbitrary_tests, reth_codec, Compact}; use revm_primitives::{calc_blob_gasprice, calc_excess_blob_gas}; +use serde::{Deserialize, Serialize}; /// Block header #[reth_codec(no_arbitrary)] #[add_arbitrary_tests(rlp, 25)] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct Header { /// The Keccak 256-bit hash of the parent /// block’s header, in its entirety; formally Hp. diff --git a/crates/primitives-traits/src/header/sealed.rs b/crates/primitives-traits/src/header/sealed.rs index 20bb30b8a..317ced322 100644 --- a/crates/primitives-traits/src/header/sealed.rs +++ b/crates/primitives-traits/src/header/sealed.rs @@ -8,12 +8,13 @@ use bytes::BufMut; use core::mem; use derive_more::{AsRef, Deref}; use reth_codecs::{add_arbitrary_tests, reth_codec, Compact}; +use serde::{Deserialize, Serialize}; /// A [`Header`] that is sealed at a precalculated hash, use [`SealedHeader::unseal()`] if you want /// to modify header. #[reth_codec(no_arbitrary)] #[add_arbitrary_tests(rlp, compact)] -#[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref, Serialize, Deserialize)] pub struct SealedHeader { /// Locked Header hash. hash: BlockHash, diff --git a/crates/primitives-traits/src/log.rs b/crates/primitives-traits/src/log.rs index a27108810..7812c0102 100644 --- a/crates/primitives-traits/src/log.rs +++ b/crates/primitives-traits/src/log.rs @@ -20,11 +20,14 @@ mod tests { use proptest::proptest; use proptest_arbitrary_interop::arb; use reth_codecs::{reth_codec, Compact}; + use serde::{Deserialize, Serialize}; /// This type is kept for compatibility tests after the codec support was added to /// alloy-primitives Log type natively #[reth_codec(rlp)] - #[derive(Clone, Debug, PartialEq, Eq, RlpDecodable, RlpEncodable, Default)] + #[derive( + Clone, Debug, PartialEq, Eq, RlpDecodable, RlpEncodable, Default, Serialize, Deserialize, + )] struct Log { /// Contract that emitted this log. address: Address, diff --git a/crates/primitives-traits/src/request.rs b/crates/primitives-traits/src/request.rs index eab29736e..d2ae73181 100644 --- a/crates/primitives-traits/src/request.rs +++ b/crates/primitives-traits/src/request.rs @@ -6,13 +6,27 @@ use alloy_rlp::{Decodable, Encodable}; use derive_more::{Deref, DerefMut, From, IntoIterator}; use reth_codecs::{reth_codec, Compact}; use revm_primitives::Bytes; +use serde::{Deserialize, Serialize}; #[cfg(not(feature = "std"))] use alloc::vec::Vec; /// A list of EIP-7685 requests. #[reth_codec] -#[derive(Debug, Clone, PartialEq, Eq, Default, Hash, Deref, DerefMut, From, IntoIterator)] +#[derive( + Debug, + Clone, + PartialEq, + Eq, + Default, + Hash, + Deref, + DerefMut, + From, + IntoIterator, + Serialize, + Deserialize, +)] pub struct Requests(pub Vec); impl Encodable for Requests { diff --git a/crates/primitives-traits/src/withdrawal.rs b/crates/primitives-traits/src/withdrawal.rs index 2064627eb..3f4c6768e 100644 --- a/crates/primitives-traits/src/withdrawal.rs +++ b/crates/primitives-traits/src/withdrawal.rs @@ -10,6 +10,7 @@ use alloc::vec::Vec; /// Re-export from `alloy_eips`. #[doc(inline)] pub use alloy_eips::eip4895::Withdrawal; +use serde::{Deserialize, Serialize}; /// Represents a collection of Withdrawals. #[reth_codec] @@ -27,6 +28,8 @@ pub use alloy_eips::eip4895::Withdrawal; IntoIterator, RlpEncodableWrapper, RlpDecodableWrapper, + Serialize, + Deserialize, )] #[as_ref(forward)] pub struct Withdrawals(Vec); @@ -93,7 +96,18 @@ mod tests { /// This type is kept for compatibility tests after the codec support was added to alloy-eips /// Withdrawal type natively #[reth_codec] - #[derive(Debug, Clone, PartialEq, Eq, Default, Hash, RlpEncodable, RlpDecodable)] + #[derive( + Debug, + Clone, + PartialEq, + Eq, + Default, + Hash, + RlpEncodable, + RlpDecodable, + Serialize, + Deserialize, + )] struct RethWithdrawal { /// Monotonically increasing identifier issued by consensus layer. index: u64, diff --git a/crates/primitives/src/receipt.rs b/crates/primitives/src/receipt.rs index ab71b55b1..91027f66f 100644 --- a/crates/primitives/src/receipt.rs +++ b/crates/primitives/src/receipt.rs @@ -16,7 +16,9 @@ use alloc::{vec, vec::Vec}; /// Receipt containing result of transaction execution. #[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec(no_arbitrary, zstd))] #[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests)] -#[derive(Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)] +#[derive( + Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable, Serialize, Deserialize, +)] #[rlp(trailing)] pub struct Receipt { /// Receipt type. @@ -141,7 +143,7 @@ impl From for ReceiptWithBloom { /// [`Receipt`] with calculated bloom filter. #[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec)] -#[derive(Clone, Debug, PartialEq, Eq, Default)] +#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)] pub struct ReceiptWithBloom { /// Bloom filter build from logs. pub bloom: Bloom, diff --git a/crates/primitives/src/transaction/access_list.rs b/crates/primitives/src/transaction/access_list.rs index 673a7f31a..d961c4f6c 100644 --- a/crates/primitives/src/transaction/access_list.rs +++ b/crates/primitives/src/transaction/access_list.rs @@ -12,12 +12,22 @@ mod tests { use proptest::proptest; use proptest_arbitrary_interop::arb; use reth_codecs::{reth_codec, Compact}; + use serde::{Deserialize, Serialize}; /// This type is kept for compatibility tests after the codec support was added to alloy-eips /// AccessList type natively #[reth_codec(rlp)] #[derive( - Clone, Debug, PartialEq, Eq, Hash, Default, RlpDecodableWrapper, RlpEncodableWrapper, + Clone, + Debug, + PartialEq, + Eq, + Hash, + Default, + RlpDecodableWrapper, + RlpEncodableWrapper, + Serialize, + Deserialize, )] struct RethAccessList(Vec); @@ -29,7 +39,18 @@ mod tests { // This #[reth_codec(rlp)] - #[derive(Clone, Debug, PartialEq, Eq, Hash, Default, RlpDecodable, RlpEncodable)] + #[derive( + Clone, + Debug, + PartialEq, + Eq, + Hash, + Default, + RlpDecodable, + RlpEncodable, + Serialize, + Deserialize, + )] #[serde(rename_all = "camelCase")] struct RethAccessListItem { /// Account address that would be loaded at the start of execution diff --git a/crates/primitives/src/transaction/eip1559.rs b/crates/primitives/src/transaction/eip1559.rs index 1b1fdd248..62c8e4ed4 100644 --- a/crates/primitives/src/transaction/eip1559.rs +++ b/crates/primitives/src/transaction/eip1559.rs @@ -8,10 +8,11 @@ use reth_codecs::Compact; #[cfg(not(feature = "std"))] use alloc::vec::Vec; +use serde::{Deserialize, Serialize}; /// A transaction with a priority fee ([EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)). #[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec)] -#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)] pub struct TxEip1559 { /// Added as EIP-155: Simple replay attack protection pub chain_id: ChainId, diff --git a/crates/primitives/src/transaction/eip2930.rs b/crates/primitives/src/transaction/eip2930.rs index dc9700294..c7cb5d198 100644 --- a/crates/primitives/src/transaction/eip2930.rs +++ b/crates/primitives/src/transaction/eip2930.rs @@ -8,10 +8,11 @@ use reth_codecs::Compact; #[cfg(not(feature = "std"))] use alloc::vec::Vec; +use serde::{Deserialize, Serialize}; /// Transaction with an [`AccessList`] ([EIP-2930](https://eips.ethereum.org/EIPS/eip-2930)). #[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec)] -#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)] pub struct TxEip2930 { /// Added as EIP-155: Simple replay attack protection pub chain_id: ChainId, diff --git a/crates/primitives/src/transaction/eip4844.rs b/crates/primitives/src/transaction/eip4844.rs index a92c8dc92..234c558a1 100644 --- a/crates/primitives/src/transaction/eip4844.rs +++ b/crates/primitives/src/transaction/eip4844.rs @@ -15,12 +15,13 @@ use crate::kzg::KzgSettings; #[cfg(not(feature = "std"))] use alloc::vec::Vec; +use serde::{Deserialize, Serialize}; /// [EIP-4844 Blob Transaction](https://eips.ethereum.org/EIPS/eip-4844#blob-transaction) /// /// A transaction with blob hashes and max blob fee #[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec)] -#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)] pub struct TxEip4844 { /// Added as EIP-155: Simple replay attack protection pub chain_id: ChainId, diff --git a/crates/primitives/src/transaction/eip7702.rs b/crates/primitives/src/transaction/eip7702.rs index feaa37aa2..768d9cf28 100644 --- a/crates/primitives/src/transaction/eip7702.rs +++ b/crates/primitives/src/transaction/eip7702.rs @@ -7,6 +7,7 @@ use core::mem; #[cfg(not(feature = "std"))] use alloc::vec::Vec; +use serde::{Deserialize, Serialize}; #[cfg(any(test, feature = "reth-codec"))] use reth_codecs::Compact; @@ -15,7 +16,7 @@ use reth_codecs::Compact; /// /// Set EOA account code for one transaction #[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec)] -#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)] pub struct TxEip7702 { /// Added as EIP-155: Simple replay attack protection pub chain_id: ChainId, diff --git a/crates/primitives/src/transaction/legacy.rs b/crates/primitives/src/transaction/legacy.rs index 997ba2ccd..790367b47 100644 --- a/crates/primitives/src/transaction/legacy.rs +++ b/crates/primitives/src/transaction/legacy.rs @@ -7,10 +7,11 @@ use reth_codecs::Compact; #[cfg(not(feature = "std"))] use alloc::vec::Vec; +use serde::{Deserialize, Serialize}; /// Legacy transaction. #[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec)] -#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)] pub struct TxLegacy { /// Added as EIP-155: Simple replay attack protection pub chain_id: Option, diff --git a/crates/primitives/src/transaction/optimism.rs b/crates/primitives/src/transaction/optimism.rs index 1d15532a2..0b4635fb3 100644 --- a/crates/primitives/src/transaction/optimism.rs +++ b/crates/primitives/src/transaction/optimism.rs @@ -4,11 +4,12 @@ use alloy_rlp::{ }; use bytes::Buf; use reth_codecs::{reth_codec, Compact}; +use serde::{Deserialize, Serialize}; use std::mem; /// Deposit transactions, also known as deposits are initiated on L1, and executed on L2. #[cfg_attr(any(test, feature = "reth-codec"), reth_codec)] -#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)] pub struct TxDeposit { /// Hash that uniquely identifies the source of the deposit. pub source_hash: B256, diff --git a/crates/prune/types/src/checkpoint.rs b/crates/prune/types/src/checkpoint.rs index 545358579..868fb05da 100644 --- a/crates/prune/types/src/checkpoint.rs +++ b/crates/prune/types/src/checkpoint.rs @@ -1,10 +1,11 @@ use crate::PruneMode; use alloy_primitives::{BlockNumber, TxNumber}; use reth_codecs::{reth_codec, Compact}; +use serde::{Deserialize, Serialize}; /// Saves the pruning progress of a stage. #[reth_codec] -#[derive(Debug, PartialEq, Eq, Clone, Copy)] +#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] #[cfg_attr(test, derive(Default))] pub struct PruneCheckpoint { /// Highest pruned block number. If it's [None], the pruning for block `0` is not finished yet. diff --git a/crates/prune/types/src/mode.rs b/crates/prune/types/src/mode.rs index fc685d999..d35cb6669 100644 --- a/crates/prune/types/src/mode.rs +++ b/crates/prune/types/src/mode.rs @@ -1,10 +1,11 @@ use crate::{segment::PrunePurpose, PruneSegment, PruneSegmentError}; use alloy_primitives::BlockNumber; use reth_codecs::{reth_codec, Compact}; +use serde::{Deserialize, Serialize}; /// Prune mode. #[reth_codec] -#[derive(Debug, PartialEq, Eq, Clone, Copy)] +#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum PruneMode { /// Prune all blocks. diff --git a/crates/prune/types/src/segment.rs b/crates/prune/types/src/segment.rs index 5611ca89c..d9b678292 100644 --- a/crates/prune/types/src/segment.rs +++ b/crates/prune/types/src/segment.rs @@ -1,11 +1,14 @@ use crate::MINIMUM_PRUNING_DISTANCE; use derive_more::Display; use reth_codecs::{reth_codec, Compact}; +use serde::{Deserialize, Serialize}; use thiserror::Error; /// Segment of the data that can be pruned. #[reth_codec] -#[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[derive( + Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize, +)] pub enum PruneSegment { /// Prune segment responsible for the `TransactionSenders` table. SenderRecovery, diff --git a/crates/stages/types/src/checkpoints.rs b/crates/stages/types/src/checkpoints.rs index a9ca74958..fb62feab5 100644 --- a/crates/stages/types/src/checkpoints.rs +++ b/crates/stages/types/src/checkpoints.rs @@ -2,6 +2,7 @@ use alloy_primitives::{Address, BlockNumber, B256}; use bytes::Buf; use reth_codecs::{reth_codec, Compact}; use reth_trie_common::{hash_builder::HashBuilderState, StoredSubNode}; +use serde::{Deserialize, Serialize}; use std::ops::RangeInclusive; use super::StageId; @@ -75,7 +76,7 @@ impl Compact for MerkleCheckpoint { /// Saves the progress of AccountHashing stage. #[reth_codec] -#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct AccountHashingCheckpoint { /// The next account to start hashing from. pub address: Option
, @@ -87,7 +88,7 @@ pub struct AccountHashingCheckpoint { /// Saves the progress of StorageHashing stage. #[reth_codec] -#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct StorageHashingCheckpoint { /// The next account to start hashing from. pub address: Option
, @@ -101,7 +102,7 @@ pub struct StorageHashingCheckpoint { /// Saves the progress of Execution stage. #[reth_codec] -#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct ExecutionCheckpoint { /// Block range which this checkpoint is valid for. pub block_range: CheckpointBlockRange, @@ -111,7 +112,7 @@ pub struct ExecutionCheckpoint { /// Saves the progress of Headers stage. #[reth_codec] -#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct HeadersCheckpoint { /// Block range which this checkpoint is valid for. pub block_range: CheckpointBlockRange, @@ -121,7 +122,7 @@ pub struct HeadersCheckpoint { /// Saves the progress of Index History stages. #[reth_codec] -#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct IndexHistoryCheckpoint { /// Block range which this checkpoint is valid for. pub block_range: CheckpointBlockRange, @@ -131,7 +132,7 @@ pub struct IndexHistoryCheckpoint { /// Saves the progress of abstract stage iterating over or downloading entities. #[reth_codec] -#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)] +#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] pub struct EntitiesCheckpoint { /// Number of entities already processed. pub processed: u64, @@ -159,7 +160,7 @@ impl EntitiesCheckpoint { /// Saves the block range. Usually, it's used to check the validity of some stage checkpoint across /// multiple executions. #[reth_codec] -#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CheckpointBlockRange { /// The first block of the range, inclusive. pub from: BlockNumber, @@ -181,7 +182,7 @@ impl From<&RangeInclusive> for CheckpointBlockRange { /// Saves the progress of a stage. #[reth_codec] -#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)] +#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] pub struct StageCheckpoint { /// The maximum block processed by the stage. pub block_number: BlockNumber, @@ -247,7 +248,7 @@ impl StageCheckpoint { // is not a Copy type. /// Stage-specific checkpoint metrics. #[reth_codec] -#[derive(Debug, PartialEq, Eq, Clone, Copy)] +#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)] pub enum StageUnitCheckpoint { /// Saves the progress of AccountHashing stage. Account(AccountHashingCheckpoint), diff --git a/crates/storage/codecs/derive/src/lib.rs b/crates/storage/codecs/derive/src/lib.rs index bc55b0d71..b4d4e12c8 100644 --- a/crates/storage/codecs/derive/src/lib.rs +++ b/crates/storage/codecs/derive/src/lib.rs @@ -45,13 +45,13 @@ pub fn reth_codec(args: TokenStream, input: TokenStream) -> TokenStream { let compact = if with_zstd { quote! { - #[derive(CompactZstd, serde::Serialize, serde::Deserialize)] + #[derive(CompactZstd)] #ast } .into() } else { quote! { - #[derive(Compact, serde::Serialize, serde::Deserialize)] + #[derive(Compact)] #ast } .into() diff --git a/crates/storage/codecs/src/alloy/authorization_list.rs b/crates/storage/codecs/src/alloy/authorization_list.rs index 520a4cc04..b9ba69dbc 100644 --- a/crates/storage/codecs/src/alloy/authorization_list.rs +++ b/crates/storage/codecs/src/alloy/authorization_list.rs @@ -3,12 +3,13 @@ use alloy_eips::eip7702::{Authorization as AlloyAuthorization, SignedAuthorizati use alloy_primitives::{Address, ChainId, U256}; use bytes::Buf; use reth_codecs_derive::reth_codec; +use serde::{Deserialize, Serialize}; /// Authorization acts as bridge which simplifies Compact implementation for AlloyAuthorization. /// /// Notice: Make sure this struct is 1:1 with `alloy_eips::eip7702::Authorization` #[reth_codec] -#[derive(Debug, Clone, PartialEq, Eq, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] struct Authorization { chain_id: ChainId, address: Address, diff --git a/crates/storage/codecs/src/alloy/genesis_account.rs b/crates/storage/codecs/src/alloy/genesis_account.rs index 8f490d6fd..3f6c83b44 100644 --- a/crates/storage/codecs/src/alloy/genesis_account.rs +++ b/crates/storage/codecs/src/alloy/genesis_account.rs @@ -2,12 +2,13 @@ use crate::Compact; use alloy_genesis::GenesisAccount as AlloyGenesisAccount; use alloy_primitives::{Bytes, B256, U256}; use reth_codecs_derive::reth_codec; +use serde::{Deserialize, Serialize}; /// GenesisAccount acts as bridge which simplifies Compact implementation for AlloyGenesisAccount. /// /// Notice: Make sure this struct is 1:1 with `alloy_genesis::GenesisAccount` #[reth_codec] -#[derive(Debug, Clone, PartialEq, Eq, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] struct GenesisAccount { /// The nonce of the account at genesis. nonce: Option, @@ -22,13 +23,13 @@ struct GenesisAccount { } #[reth_codec] -#[derive(Debug, Clone, PartialEq, Eq, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] struct StorageEntries { entries: Vec, } #[reth_codec] -#[derive(Debug, Clone, PartialEq, Eq, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] struct StorageEntry { key: B256, value: B256, diff --git a/crates/storage/codecs/src/alloy/withdrawal.rs b/crates/storage/codecs/src/alloy/withdrawal.rs index b1ced8fb4..9d2a21d3f 100644 --- a/crates/storage/codecs/src/alloy/withdrawal.rs +++ b/crates/storage/codecs/src/alloy/withdrawal.rs @@ -2,12 +2,13 @@ use crate::Compact; use alloy_eips::eip4895::Withdrawal as AlloyWithdrawal; use alloy_primitives::Address; use reth_codecs_derive::reth_codec; +use serde::{Deserialize, Serialize}; /// Withdrawal acts as bridge which simplifies Compact implementation for AlloyWithdrawal. /// /// Notice: Make sure this struct is 1:1 with `alloy_eips::eip4895::Withdrawal` #[reth_codec] -#[derive(Debug, Clone, PartialEq, Eq, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] struct Withdrawal { /// Monotonically increasing identifier issued by consensus layer. index: u64, diff --git a/crates/storage/codecs/src/lib.rs b/crates/storage/codecs/src/lib.rs index d73cc12f4..afee5f6cc 100644 --- a/crates/storage/codecs/src/lib.rs +++ b/crates/storage/codecs/src/lib.rs @@ -414,6 +414,7 @@ const fn decode_varuint_panic() -> ! { mod tests { use super::*; use alloy_primitives::B256; + use serde::{Deserialize, Serialize}; #[test] fn compact_bytes() { @@ -556,7 +557,7 @@ mod tests { } #[reth_codec] - #[derive(Debug, PartialEq, Clone)] + #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] struct TestStruct { f_u64: u64, f_u256: U256, @@ -608,7 +609,7 @@ mod tests { } #[reth_codec] - #[derive(Debug, PartialEq, Clone, Default)] + #[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)] enum TestEnum { #[default] Var0, diff --git a/crates/storage/db-api/src/models/blocks.rs b/crates/storage/db-api/src/models/blocks.rs index 7d42b6ee4..572c6b019 100644 --- a/crates/storage/db-api/src/models/blocks.rs +++ b/crates/storage/db-api/src/models/blocks.rs @@ -2,6 +2,7 @@ use reth_codecs::{reth_codec, Compact}; use reth_primitives::{Header, TxNumber, Withdrawals, B256}; +use serde::{Deserialize, Serialize}; use std::ops::Range; /// Total number of transactions. @@ -11,7 +12,7 @@ pub type NumTransactions = u64; /// /// It has the pointer to the transaction Number of the first /// transaction in the block and the total number of transactions. -#[derive(Debug, Default, Eq, PartialEq, Clone)] +#[derive(Debug, Default, Eq, PartialEq, Clone, Serialize, Deserialize)] #[reth_codec] pub struct StoredBlockBodyIndices { /// The number of the first transaction in this block @@ -69,7 +70,7 @@ impl StoredBlockBodyIndices { /// /// It is stored as the headers of the block's uncles. #[reth_codec] -#[derive(Debug, Default, Eq, PartialEq, Clone)] +#[derive(Debug, Default, Eq, PartialEq, Clone, Serialize, Deserialize)] pub struct StoredBlockOmmers { /// The block headers of this block's uncles. pub ommers: Vec
, @@ -77,7 +78,7 @@ pub struct StoredBlockOmmers { /// The storage representation of block withdrawals. #[reth_codec] -#[derive(Debug, Default, Eq, PartialEq, Clone)] +#[derive(Debug, Default, Eq, PartialEq, Clone, Serialize, Deserialize)] pub struct StoredBlockWithdrawals { /// The block withdrawals. pub withdrawals: Withdrawals, diff --git a/crates/storage/db-api/src/models/mod.rs b/crates/storage/db-api/src/models/mod.rs index 9f3fabea9..a290af914 100644 --- a/crates/storage/db-api/src/models/mod.rs +++ b/crates/storage/db-api/src/models/mod.rs @@ -9,6 +9,7 @@ use reth_primitives::{Address, B256, *}; use reth_prune_types::{PruneCheckpoint, PruneSegment}; use reth_stages_types::StageCheckpoint; use reth_trie_common::{StoredNibbles, StoredNibblesSubKey, *}; +use serde::{Deserialize, Serialize}; pub mod accounts; pub mod blocks; @@ -264,7 +265,7 @@ macro_rules! add_wrapper_struct { $( /// Wrapper struct so it can use StructFlags from Compact, when used as pure table values. #[reth_codec] - #[derive(Debug, Clone, PartialEq, Eq, Default)] + #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] pub struct $wrapper(pub $name); impl From<$name> for $wrapper { diff --git a/docs/crates/eth-wire.md b/docs/crates/eth-wire.md index 9a8863802..7ab87e914 100644 --- a/docs/crates/eth-wire.md +++ b/docs/crates/eth-wire.md @@ -106,7 +106,7 @@ And the corresponding trait implementations are present in the primitives crate. [File: crates/primitives/src/transaction/mod.rs](https://github.com/paradigmxyz/reth/blob/1563506aea09049a85e5cc72c2894f3f7a371581/crates/primitives/src/transaction/mod.rs) ```rust, ignore #[reth_codec] -#[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref, Default, Serialize, Deserialize)] pub struct TransactionSigned { pub hash: TxHash, pub signature: Signature,