feat(eth-wire): derive serde traits for eth-wire types (#348)

* wip: start adding serde to stuff

* add serde traits to NewBlockHashes

* derive serde traits for the rest of the types

* derive serde traits for p2p subprotocol messages

* cargo fmt
This commit is contained in:
Dan Cline
2022-12-06 21:05:22 -05:00
committed by GitHub
parent 292f5f22bc
commit 6c91322251
15 changed files with 81 additions and 35 deletions

View File

@ -1,5 +1,6 @@
use crate::{Header, SealedHeader, TransactionSigned, H256};
use reth_rlp::{Decodable, DecodeError, Encodable, RlpDecodable, RlpEncodable};
use serde::{Deserialize, Serialize};
use std::ops::Deref;
/// Ethereum full block.
@ -46,7 +47,7 @@ impl Deref for BlockLocked {
}
/// Either a block hash _or_ a block number
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum BlockHashOrNumber {
/// A block hash
Hash(H256),

View File

@ -1,10 +1,11 @@
use crate::U256;
use ethers_core::types::{ParseChainError, U64};
use reth_rlp::{Decodable, Encodable};
use serde::{Deserialize, Serialize};
use std::{fmt, str::FromStr};
/// Either a named or chain id or the actual id value
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Chain {
/// Contains a known chain
Named(ethers_core::types::Chain),

View File

@ -6,6 +6,7 @@ use bytes::{BufMut, BytesMut};
use ethers_core::{types::H64, utils::keccak256};
use reth_codecs::{main_codec, Compact};
use reth_rlp::{length_of_length, Decodable, Encodable};
use serde::{Deserialize, Serialize};
use std::ops::Deref;
/// Block header
@ -279,7 +280,7 @@ impl SealedHeader {
/// [`HeadersDirection::Falling`] block numbers for `reverse == false`
///
/// See also <https://github.com/ethereum/devp2p/blob/master/caps/eth.md#getblockheaders-0x03>
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Default)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Default, Serialize, Deserialize)]
pub enum HeadersDirection {
/// Falling block number.
#[default]