Skip to content

Commit

Permalink
refactor: clean up legacy serde helpers (#624)
Browse files Browse the repository at this point in the history
* refactor: clean up legacy serde helpers

* doc: fixlink
  • Loading branch information
prestwich authored Apr 24, 2024
1 parent e4fb669 commit e1d45b4
Show file tree
Hide file tree
Showing 28 changed files with 169 additions and 319 deletions.
2 changes: 1 addition & 1 deletion crates/consensus/src/receipt/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct AnyReceiptEnvelope<T = Log> {
#[cfg_attr(feature = "serde", serde(flatten))]
pub inner: ReceiptWithBloom<T>,
/// The transaction type.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::num::u8_hex"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::num::u8_via_ruint"))]
pub r#type: u8,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/src/receipt/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Receipt<T = Log> {
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity_bool"))]
pub status: bool,
/// Gas used
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
pub cumulative_gas_used: u128,
/// Log send from contracts.
pub logs: Vec<T>,
Expand Down
10 changes: 5 additions & 5 deletions crates/consensus/src/transaction/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ use alloc::vec::Vec;
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct TxEip1559 {
/// EIP-155: Simple replay attack protection
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
pub chain_id: ChainId,
/// A scalar value equal to the number of transactions sent by the sender; formally Tn.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
pub nonce: u64,
/// A scalar value equal to the maximum
/// amount of gas that should be used in executing
/// this transaction. This is paid up-front, before any
/// computation is done and may not be increased
/// later; formally Tg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
pub gas_limit: u128,
/// A scalar value equal to the maximum
/// amount of gas that should be used in executing
Expand All @@ -36,7 +36,7 @@ pub struct TxEip1559 {
/// 340282366920938463463374607431768211455
///
/// This is also known as `GasFeeCap`
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
pub max_fee_per_gas: u128,
/// Max Priority fee that transaction is paying
///
Expand All @@ -45,7 +45,7 @@ pub struct TxEip1559 {
/// 340282366920938463463374607431768211455
///
/// This is also known as `GasTipCap`
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
pub max_priority_fee_per_gas: u128,
/// The 160-bit address of the message call’s recipient or, for a contract creation
/// transaction, ∅, used here to denote the only member of B0 ; formally Tt.
Expand Down
8 changes: 4 additions & 4 deletions crates/consensus/src/transaction/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use alloc::vec::Vec;
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct TxEip2930 {
/// Added as EIP-pub 155: Simple replay attack protection
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
pub chain_id: ChainId,
/// A scalar value equal to the number of transactions sent by the sender; formally Tn.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
pub nonce: u64,
/// A scalar value equal to the number of
/// Wei to be paid per unit of gas for all computation
Expand All @@ -25,14 +25,14 @@ pub struct TxEip2930 {
/// As ethereum circulation is around 120mil eth as of 2022 that is around
/// 120000000000000000000000000 wei we are safe to use u128 as its max number is:
/// 340282366920938463463374607431768211455
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
pub gas_price: u128,
/// A scalar value equal to the maximum
/// amount of gas that should be used in executing
/// this transaction. This is paid up-front, before any
/// computation is done and may not be increased
/// later; formally Tg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
pub gas_limit: u128,
/// The 160-bit address of the message call’s recipient or, for a contract creation
/// transaction, ∅, used here to denote the only member of B0 ; formally Tt.
Expand Down
12 changes: 6 additions & 6 deletions crates/consensus/src/transaction/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,17 @@ impl SignableTransaction<Signature> for TxEip4844Variant {
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct TxEip4844 {
/// Added as EIP-pub 155: Simple replay attack protection
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
pub chain_id: ChainId,
/// A scalar value equal to the number of transactions sent by the sender; formally Tn.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
pub nonce: u64,
/// A scalar value equal to the maximum
/// amount of gas that should be used in executing
/// this transaction. This is paid up-front, before any
/// computation is done and may not be increased
/// later; formally Tg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
pub gas_limit: u128,
/// A scalar value equal to the maximum
/// amount of gas that should be used in executing
Expand All @@ -358,7 +358,7 @@ pub struct TxEip4844 {
/// 340282366920938463463374607431768211455
///
/// This is also known as `GasFeeCap`
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
pub max_fee_per_gas: u128,
/// Max Priority fee that transaction is paying
///
Expand All @@ -367,7 +367,7 @@ pub struct TxEip4844 {
/// 340282366920938463463374607431768211455
///
/// This is also known as `GasTipCap`
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
pub max_priority_fee_per_gas: u128,
/// The 160-bit address of the message call’s recipient.
pub to: Address,
Expand All @@ -389,7 +389,7 @@ pub struct TxEip4844 {
/// Max fee per data gas
///
/// aka BlobFeeCap or blobGasFeeCap
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
pub max_fee_per_blob_gas: u128,

/// Input has two uses depending if transaction is Create or Call (if `to` field is None or
Expand Down
8 changes: 4 additions & 4 deletions crates/consensus/src/transaction/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ pub struct TxLegacy {
feature = "serde",
serde(
default,
with = "alloy_serde::u64_hex_or_decimal_opt",
with = "alloy_serde::u64_opt_via_ruint",
skip_serializing_if = "Option::is_none",
)
)]
pub chain_id: Option<ChainId>,
/// A scalar value equal to the number of transactions sent by the sender; formally Tn.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
pub nonce: u64,
/// A scalar value equal to the number of
/// Wei to be paid per unit of gas for all computation
Expand All @@ -31,14 +31,14 @@ pub struct TxLegacy {
/// As ethereum circulation is around 120mil eth as of 2022 that is around
/// 120000000000000000000000000 wei we are safe to use u128 as its max number is:
/// 340282366920938463463374607431768211455
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
pub gas_price: u128,
/// A scalar value equal to the maximum
/// amount of gas that should be used in executing
/// this transaction. This is paid up-front, before any
/// computation is done and may not be increased
/// later; formally Tg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
pub gas_limit: u128,
/// The 160-bit address of the message call’s recipient or, for a contract creation
/// transaction, ∅, used here to denote the only member of B0 ; formally Tt.
Expand Down
8 changes: 4 additions & 4 deletions crates/eip7547/src/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use alloy_primitives::{Address, B256};
use alloy_rpc_types_engine::PayloadStatusEnum;
use alloy_serde::u64_hex;
use alloy_serde::u64_via_ruint;
use serde::{ser::SerializeMap, Deserialize, Serialize, Serializer};
use std::fmt;

Expand Down Expand Up @@ -83,7 +83,7 @@ pub struct InclusionListSummaryEntryV1 {
/// The address of the inclusion list entry.
pub address: Address,
/// The nonce of the inclusion list entry.
#[serde(with = "u64_hex")]
#[serde(with = "u64_via_ruint")]
pub nonce: u64,
}

Expand All @@ -108,10 +108,10 @@ impl fmt::Display for InclusionListSummaryEntryV1 {
#[serde(rename_all = "camelCase")]
pub struct InclusionListSummaryV1 {
/// The slot of the inclusion list summary.
#[serde(with = "u64_hex")]
#[serde(with = "u64_via_ruint")]
pub slot: u64,
/// The proposer index of the inclusion list summary.
#[serde(with = "u64_hex")]
#[serde(with = "u64_via_ruint")]
pub proposer_index: u64,
/// The parent hash of the inclusion list summary.
pub parent_hash: B256,
Expand Down
4 changes: 2 additions & 2 deletions crates/eips/src/eip1559/basefee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use crate::{
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BaseFeeParams {
/// The base_fee_max_change_denominator from EIP-1559
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::num::u128_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::num::u128_via_ruint"))]
pub max_change_denominator: u128,
/// The elasticity multiplier from EIP-1559
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::num::u128_hex_or_decimal"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::num::u128_via_ruint"))]
pub elasticity_multiplier: u128,
}

Expand Down
9 changes: 6 additions & 3 deletions crates/eips/src/eip4895.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ pub const GWEI_TO_WEI: u64 = 1_000_000_000;
#[cfg_attr(feature = "ssz", derive(ssz_derive::Encode, ssz_derive::Decode))]
pub struct Withdrawal {
/// Monotonically increasing identifier issued by consensus layer.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
pub index: u64,
/// Index of validator associated with withdrawal.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex", rename = "validatorIndex"))]
#[cfg_attr(
feature = "serde",
serde(with = "alloy_serde::u64_via_ruint", rename = "validatorIndex")
)]
pub validator_index: u64,
/// Target address for withdrawn ether.
pub address: Address,
/// Value of the withdrawal in gwei.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
pub amount: u64,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/eips/src/eip6110.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ pub struct DepositReceipt {
/// Withdrawal credentials
pub withdrawal_credentials: B256,
/// Amount of ether deposited in gwei
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
pub amount: u64,
/// Deposit signature
pub signature: FixedBytes<96>,
/// Deposit index
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
pub index: u64,
}
Loading

0 comments on commit e1d45b4

Please sign in to comment.