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

[Feature] Manually impl serialisation for reth_rpc_types_eth::Transaction #1409

Open
emhane opened this issue Oct 2, 2024 · 2 comments
Open
Assignees
Labels
debt Tech debt which needs to be addressed

Comments

@emhane
Copy link
Member

emhane commented Oct 2, 2024

Component

rpc

Describe the feature you would like

Manually impl serde Serialization and Deserializationfor reth_rpc_types_eth::Transaction. For the field max_fee_per_gas, this should use the json label gasPrice if the tx type is < 2, i.e. pre-eip1559. This way the field gas_price can be removed from the struct, as it is redundant

/// Transaction object used in RPC
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[doc(alias = "Tx")]
pub struct Transaction {
/// Hash
pub hash: TxHash,
/// Nonce
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub nonce: u64,
/// Block hash
#[cfg_attr(feature = "serde", serde(default))]
pub block_hash: Option<BlockHash>,
/// Block number
#[cfg_attr(feature = "serde", serde(default, with = "alloy_serde::quantity::opt"))]
pub block_number: Option<u64>,
/// Transaction Index
#[cfg_attr(feature = "serde", serde(default, with = "alloy_serde::quantity::opt"))]
pub transaction_index: Option<u64>,
/// Sender
pub from: Address,
/// Recipient
pub to: Option<Address>,
/// Transferred value
pub value: U256,
/// Gas Price
#[cfg_attr(
feature = "serde",
serde(
default,
skip_serializing_if = "Option::is_none",
with = "alloy_serde::quantity::opt"
)
)]
pub gas_price: Option<u128>,
/// Gas amount
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub gas: u64,
/// Max BaseFeePerGas the user is willing to pay.
#[cfg_attr(
feature = "serde",
serde(
default,
skip_serializing_if = "Option::is_none",
with = "alloy_serde::quantity::opt"
)
)]
pub max_fee_per_gas: Option<u128>,
/// The miner's tip.
#[cfg_attr(
feature = "serde",
serde(
default,
skip_serializing_if = "Option::is_none",
with = "alloy_serde::quantity::opt"
)
)]
pub max_priority_fee_per_gas: Option<u128>,
/// Configured max fee per blob gas for eip-4844 transactions
#[cfg_attr(
feature = "serde",
serde(
default,
skip_serializing_if = "Option::is_none",
with = "alloy_serde::quantity::opt"
)
)]
pub max_fee_per_blob_gas: Option<u128>,
/// Data
pub input: Bytes,
/// All _flattened_ fields of the transaction signature.
///
/// Note: this is an option so special transaction types without a signature (e.g. <https://github.com/ethereum-optimism/optimism/blob/0bf643c4147b43cd6f25a759d331ef3a2a61a2a3/specs/deposits.md#the-deposited-transaction-type>) can be supported.
#[cfg_attr(feature = "serde", serde(flatten, skip_serializing_if = "Option::is_none"))]
pub signature: Option<Signature>,
/// The chain id of the transaction, if any.
#[cfg_attr(
feature = "serde",
serde(
default,
skip_serializing_if = "Option::is_none",
with = "alloy_serde::quantity::opt"
)
)]
pub chain_id: Option<ChainId>,
/// Contains the blob hashes for eip-4844 transactions.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub blob_versioned_hashes: Option<Vec<B256>>,
/// EIP2930
///
/// Pre-pay to warm storage access.
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub access_list: Option<AccessList>,
/// EIP2718
///
/// Transaction type,
/// Some(4) for EIP-7702 transaction, Some(3) for EIP-4844 transaction, Some(2) for EIP-1559
/// transaction, Some(1) for AccessList transaction, None or Some(0) for Legacy
#[cfg_attr(
feature = "serde",
serde(
default,
rename = "type",
skip_serializing_if = "Option::is_none",
with = "alloy_serde::quantity::opt"
)
)]
#[doc(alias = "tx_type")]
pub transaction_type: Option<u8>,
/// The signed authorization list is a list of tuples that store the address to code which the
/// signer desires to execute in the context of their EOA and their signature.
#[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "Option::is_none"))]
pub authorization_list: Option<Vec<SignedAuthorization>>,
}

Additional context

No response

@emhane emhane added the debt Tech debt which needs to be addressed label Oct 2, 2024
@nadtech-hub
Copy link
Contributor

I can make it up. Could you assign it to me?

@nadtech-hub
Copy link
Contributor

I'm finalizing this one and want to make sure that serializer/deserializer is supposed to process only fields a certain type of transaction has, isn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debt Tech debt which needs to be addressed
Projects
None yet
Development

No branches or pull requests

2 participants