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

feat(serde): deprecate individual num::* for a generic quantity module #855

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion crates/consensus/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use alloc::{vec, vec::Vec};
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct Account {
/// The account's nonce.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub nonce: u64,
/// The account's balance.
pub balance: U256,
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/src/receipt/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
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(alias = "root"))]
pub status: Eip658Value,
/// Gas used
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub cumulative_gas_used: u128,
/// Log send from contracts.
pub logs: Vec<T>,
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/src/receipt/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Default for Eip658Value {
impl serde::Serialize for Eip658Value {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
Self::Eip658(status) => alloy_serde::quantity_bool::serialize(status, serializer),
Self::Eip658(status) => alloy_serde::quantity::serialize(status, serializer),
Self::PostState(state) => state.serialize(serializer),
}
}
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 @@ -14,17 +14,17 @@ use alloc::vec::Vec;
#[doc(alias = "Eip1559Transaction", alias = "TransactionEip1559", alias = "Eip1559Tx")]
pub struct TxEip1559 {
/// EIP-155: Simple replay attack protection
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
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_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
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_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub gas_limit: u128,
/// A scalar value equal to the maximum
/// amount of gas that should be used in executing
Expand All @@ -37,7 +37,7 @@ pub struct TxEip1559 {
/// 340282366920938463463374607431768211455
///
/// This is also known as `GasFeeCap`
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub max_fee_per_gas: u128,
/// Max Priority fee that transaction is paying
///
Expand All @@ -46,7 +46,7 @@ pub struct TxEip1559 {
/// 340282366920938463463374607431768211455
///
/// This is also known as `GasTipCap`
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
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 @@ -14,10 +14,10 @@ use alloc::vec::Vec;
#[doc(alias = "Eip2930Transaction", alias = "TransactionEip2930", alias = "Eip2930Tx")]
pub struct TxEip2930 {
/// Added as EIP-pub 155: Simple replay attack protection
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
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_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub nonce: u64,
/// A scalar value equal to the number of
/// Wei to be paid per unit of gas for all computation
Expand All @@ -26,14 +26,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_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
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_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
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 @@ -290,17 +290,17 @@ impl SignableTransaction<Signature> for TxEip4844Variant {
#[doc(alias = "Eip4844Transaction", alias = "TransactionEip4844", alias = "Eip4844Tx")]
pub struct TxEip4844 {
/// Added as EIP-pub 155: Simple replay attack protection
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
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_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
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_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub gas_limit: u128,
/// A scalar value equal to the maximum
/// amount of gas that should be used in executing
Expand All @@ -313,7 +313,7 @@ pub struct TxEip4844 {
/// 340282366920938463463374607431768211455
///
/// This is also known as `GasFeeCap`
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub max_fee_per_gas: u128,
/// Max Priority fee that transaction is paying
///
Expand All @@ -322,7 +322,7 @@ pub struct TxEip4844 {
/// 340282366920938463463374607431768211455
///
/// This is also known as `GasTipCap`
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub max_priority_fee_per_gas: u128,
/// The 160-bit address of the message call’s recipient.
pub to: Address,
Expand All @@ -344,7 +344,7 @@ pub struct TxEip4844 {
/// Max fee per data gas
///
/// aka BlobFeeCap or blobGasFeeCap
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
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 @@ -17,13 +17,13 @@ pub struct TxLegacy {
feature = "serde",
serde(
default,
with = "alloy_serde::u64_opt_via_ruint",
with = "alloy_serde::quantity::opt",
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_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub nonce: u64,
/// A scalar value equal to the number of
/// Wei to be paid per unit of gas for all computation
Expand All @@ -32,14 +32,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_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
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_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
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
7 changes: 3 additions & 4 deletions crates/eip7547/src/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use alloy_primitives::{Address, B256};
use alloy_rpc_types_engine::PayloadStatusEnum;
use alloy_serde::u64_via_ruint;
use serde::{ser::SerializeMap, Deserialize, Serialize, Serializer};
use std::fmt;

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

Expand All @@ -108,10 +107,10 @@ impl fmt::Display for InclusionListSummaryEntryV1 {
#[serde(rename_all = "camelCase")]
pub struct InclusionListSummaryV1 {
/// The slot of the inclusion list summary.
#[serde(with = "u64_via_ruint")]
#[serde(with = "alloy_serde::quantity")]
pub slot: u64,
/// The proposer index of the inclusion list summary.
#[serde(with = "u64_via_ruint")]
#[serde(with = "alloy_serde::quantity")]
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_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub max_change_denominator: u128,
/// The elasticity multiplier from EIP-1559
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::num::u128_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub elasticity_multiplier: u128,
}

Expand Down
6 changes: 3 additions & 3 deletions crates/eips/src/eip4895.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +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_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub index: u64,
/// Index of validator associated with withdrawal.
#[cfg_attr(
feature = "serde",
serde(with = "alloy_serde::u64_via_ruint", rename = "validatorIndex")
serde(with = "alloy_serde::quantity", 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_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
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 @@ -28,11 +28,11 @@ pub struct DepositRequest {
/// Withdrawal credentials
pub withdrawal_credentials: B256,
/// Amount of ether deposited in gwei
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub amount: u64,
/// Deposit signature
pub signature: FixedBytes<96>,
/// Deposit index
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub index: u64,
}
2 changes: 1 addition & 1 deletion crates/eips/src/eip7002.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ pub struct WithdrawalRequest {
/// Validator public key.
pub validator_public_key: FixedBytes<48>,
/// Amount of withdrawn ether in gwei.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_via_ruint"))]
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub amount: u64,
}
Loading
Loading