From 7d1d8d9d1b2ab5966e64ab01e1df0fbf011d4492 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 10 Jun 2024 12:50:02 +0200 Subject: [PATCH 01/17] improve type aliasing on untyped types --- crates/eips/src/eip1898.rs | 8 +++--- crates/provider/src/ext/anvil.rs | 4 +-- crates/provider/src/heart.rs | 26 +++++++++---------- crates/rpc-types-beacon/src/relay.rs | 18 ++++++------- crates/rpc-types-eth/src/log.rs | 10 +++---- .../rpc-types-eth/src/transaction/common.rs | 8 +++--- crates/rpc-types-trace/src/parity.rs | 12 ++++----- 7 files changed, 43 insertions(+), 43 deletions(-) diff --git a/crates/eips/src/eip1898.rs b/crates/eips/src/eip1898.rs index 31d07b7b2eb..007090b0457 100644 --- a/crates/eips/src/eip1898.rs +++ b/crates/eips/src/eip1898.rs @@ -29,7 +29,7 @@ use serde::{ #[cfg_attr(feature = "serde", serde(rename = "camelCase"))] pub struct RpcBlockHash { /// A block hash - pub block_hash: B256, + pub block_hash: BlockHash, /// Whether the block must be a canonical block pub require_canonical: Option, } @@ -42,19 +42,19 @@ impl RpcBlockHash { } } -impl From for RpcBlockHash { +impl From for RpcBlockHash { fn from(value: B256) -> Self { Self::from_hash(value, None) } } -impl From for B256 { +impl From for BlockHash { fn from(value: RpcBlockHash) -> Self { value.block_hash } } -impl AsRef for RpcBlockHash { +impl AsRef for RpcBlockHash { fn as_ref(&self) -> &B256 { &self.block_hash } diff --git a/crates/provider/src/ext/anvil.rs b/crates/provider/src/ext/anvil.rs index 016ff780aa4..94ad65d9f8a 100644 --- a/crates/provider/src/ext/anvil.rs +++ b/crates/provider/src/ext/anvil.rs @@ -41,7 +41,7 @@ pub trait AnvilApi: Send + Sync { async fn anvil_set_interval_mining(&self, secs: u64) -> TransportResult<()>; /// Removes transactions from the pool. - async fn anvil_drop_transaction(&self, tx_hash: B256) -> TransportResult>; + async fn anvil_drop_transaction(&self, tx_hash: TxHash) -> TransportResult>; /// Removes all transactions from the pool. async fn anvil_drop_all_transactions(&self) -> TransportResult<()>; @@ -184,7 +184,7 @@ where self.client().request("anvil_setIntervalMining", (secs,)).await } - async fn anvil_drop_transaction(&self, tx_hash: B256) -> TransportResult> { + async fn anvil_drop_transaction(&self, tx_hash: TxHash) -> TransportResult> { self.client().request("anvil_dropTransaction", (tx_hash,)).await } diff --git a/crates/provider/src/heart.rs b/crates/provider/src/heart.rs index 346ce00486c..d250aef048a 100644 --- a/crates/provider/src/heart.rs +++ b/crates/provider/src/heart.rs @@ -3,7 +3,7 @@ use crate::{Provider, RootProvider}; use alloy_json_rpc::RpcError; use alloy_network::Network; -use alloy_primitives::B256; +use alloy_primitives::{TxHash, B256}; use alloy_rpc_types_eth::Block; use alloy_transport::{utils::Spawnable, Transport, TransportErrorKind, TransportResult}; use futures::{stream::StreamExt, FutureExt, Stream}; @@ -61,7 +61,7 @@ pub struct PendingTransactionBuilder<'a, T, N> { impl<'a, T: Transport + Clone, N: Network> PendingTransactionBuilder<'a, T, N> { /// Creates a new pending transaction builder. - pub const fn new(provider: &'a RootProvider, tx_hash: B256) -> Self { + pub const fn new(provider: &'a RootProvider, tx_hash: TxHash) -> Self { Self::from_config(provider, PendingTransactionConfig::new(tx_hash)) } @@ -95,19 +95,19 @@ impl<'a, T: Transport + Clone, N: Network> PendingTransactionBuilder<'a, T, N> { /// Returns the transaction hash. #[doc(alias = "transaction_hash")] - pub const fn tx_hash(&self) -> &B256 { + pub const fn tx_hash(&self) -> &TxHash { self.config.tx_hash() } /// Sets the transaction hash. #[doc(alias = "set_transaction_hash")] - pub fn set_tx_hash(&mut self, tx_hash: B256) { + pub fn set_tx_hash(&mut self, tx_hash: TxHash) { self.config.set_tx_hash(tx_hash); } /// Sets the transaction hash. #[doc(alias = "with_transaction_hash")] - pub const fn with_tx_hash(mut self, tx_hash: B256) -> Self { + pub const fn with_tx_hash(mut self, tx_hash: TxHash) -> Self { self.config.tx_hash = tx_hash; self } @@ -168,7 +168,7 @@ impl<'a, T: Transport + Clone, N: Network> PendingTransactionBuilder<'a, T, N> { /// confirmed. /// - [`get_receipt`](Self::get_receipt) for fetching the receipt after the transaction has been /// confirmed. - pub async fn watch(self) -> TransportResult { + pub async fn watch(self) -> TransportResult { self.register().await?.await } @@ -225,7 +225,7 @@ impl<'a, T: Transport + Clone, N: Network> PendingTransactionBuilder<'a, T, N> { pub struct PendingTransactionConfig { /// The transaction hash to watch for. #[doc(alias = "transaction_hash")] - tx_hash: B256, + tx_hash: TxHash, /// Require a number of confirmations. required_confirmations: u64, @@ -236,25 +236,25 @@ pub struct PendingTransactionConfig { impl PendingTransactionConfig { /// Create a new watch for a transaction. - pub const fn new(tx_hash: B256) -> Self { + pub const fn new(tx_hash: TxHash) -> Self { Self { tx_hash, required_confirmations: 1, timeout: None } } /// Returns the transaction hash. #[doc(alias = "transaction_hash")] - pub const fn tx_hash(&self) -> &B256 { + pub const fn tx_hash(&self) -> &TxHash { &self.tx_hash } /// Sets the transaction hash. #[doc(alias = "set_transaction_hash")] - pub fn set_tx_hash(&mut self, tx_hash: B256) { + pub fn set_tx_hash(&mut self, tx_hash: TxHash) { self.tx_hash = tx_hash; } /// Sets the transaction hash. #[doc(alias = "with_transaction_hash")] - pub const fn with_tx_hash(mut self, tx_hash: B256) -> Self { + pub const fn with_tx_hash(mut self, tx_hash: TxHash) -> Self { self.tx_hash = tx_hash; self } @@ -326,7 +326,7 @@ impl TxWatcher { pub struct PendingTransaction { /// The transaction hash. #[doc(alias = "transaction_hash")] - pub(crate) tx_hash: B256, + pub(crate) tx_hash: TxHash, /// The receiver for the notification. // TODO: send a receipt? pub(crate) rx: oneshot::Receiver<()>, @@ -341,7 +341,7 @@ impl fmt::Debug for PendingTransaction { impl PendingTransaction { /// Returns this transaction's hash. #[doc(alias = "transaction_hash")] - pub const fn tx_hash(&self) -> &B256 { + pub const fn tx_hash(&self) -> &TxHash { &self.tx_hash } } diff --git a/crates/rpc-types-beacon/src/relay.rs b/crates/rpc-types-beacon/src/relay.rs index 209eeca337a..893c5a5e851 100644 --- a/crates/rpc-types-beacon/src/relay.rs +++ b/crates/rpc-types-beacon/src/relay.rs @@ -3,7 +3,7 @@ //! See also use crate::{BlsPublicKey, BlsSignature}; -use alloy_primitives::{Address, B256, U256}; +use alloy_primitives::{Address, BlockHash, B256, U256}; use alloy_rpc_types_engine::{ BlobsBundleV1, ExecutionPayload, ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3, }; @@ -189,7 +189,7 @@ pub struct ProposerPayloadsDeliveredQuery { pub limit: Option, /// Search for a specific blockhash #[serde(skip_serializing_if = "Option::is_none")] - pub block_hash: Option, + pub block_hash: Option, /// Search for a specific EL block number #[serde(skip_serializing_if = "Option::is_none")] pub block_number: Option, @@ -218,7 +218,7 @@ impl ProposerPayloadsDeliveredQuery { } /// Sets the specific blockhash - pub const fn block_hash(mut self, block_hash: B256) -> Self { + pub const fn block_hash(mut self, block_hash: BlockHash) -> Self { self.block_hash = Some(block_hash); self } @@ -288,7 +288,7 @@ pub struct BuilderBlocksReceivedQuery { pub limit: Option, /// Search for a specific blockhash #[serde(skip_serializing_if = "Option::is_none")] - pub block_hash: Option, + pub block_hash: Option, /// Search for a specific EL block number #[serde(skip_serializing_if = "Option::is_none")] pub block_number: Option, @@ -311,7 +311,7 @@ impl BuilderBlocksReceivedQuery { } /// Sets the specific blockhash - pub const fn block_hash(mut self, block_hash: B256) -> Self { + pub const fn block_hash(mut self, block_hash: BlockHash) -> Self { self.block_hash = Some(block_hash); self } @@ -341,17 +341,17 @@ pub mod error { #[error("incorrect ParentHash {actual}, expected {expected}")] IncorrectParentHash { /// The expected parent hash - expected: B256, + expected: BlockHash, /// The actual parent hash - actual: B256, + actual: BlockHash, }, /// Thrown if block hash mismatches #[error("incorrect BlockHash {actual}, expected {expected}")] IncorrectBlockHash { /// The expected block hash - expected: B256, + expected: BlockHash, /// The actual block hash - actual: B256, + actual: BlockHash, }, /// Thrown if block hash mismatches #[error("incorrect GasLimit {actual}, expected {expected}")] diff --git a/crates/rpc-types-eth/src/log.rs b/crates/rpc-types-eth/src/log.rs index ccfcffeabc4..f4f716f5315 100644 --- a/crates/rpc-types-eth/src/log.rs +++ b/crates/rpc-types-eth/src/log.rs @@ -1,6 +1,6 @@ #![allow(unknown_lints, non_local_definitions)] // TODO: remove when proptest-derive updates -use alloy_primitives::{LogData, B256}; +use alloy_primitives::{BlockHash, BlockNumber, LogData, TxHash, TxIndex, B256}; use serde::{Deserialize, Serialize}; /// Ethereum Log emitted by a transaction @@ -15,10 +15,10 @@ pub struct Log { /// Consensus log object pub inner: alloy_primitives::Log, /// Hash of the block the transaction that emitted this log was mined in - pub block_hash: Option, + pub block_hash: Option, /// Number of the block the transaction that emitted this log was mined in #[serde(with = "alloy_serde::quantity::opt")] - pub block_number: Option, + pub block_number: Option, /// The timestamp of the block as proposed in: /// /// @@ -26,11 +26,11 @@ pub struct Log { pub block_timestamp: Option, /// Transaction Hash #[doc(alias = "tx_hash")] - pub transaction_hash: Option, + pub transaction_hash: Option, /// Index of the Transaction in the block #[serde(with = "alloy_serde::quantity::opt")] #[doc(alias = "tx_index")] - pub transaction_index: Option, + pub transaction_index: Option, /// Log Index in Block #[serde(with = "alloy_serde::quantity::opt")] pub log_index: Option, diff --git a/crates/rpc-types-eth/src/transaction/common.rs b/crates/rpc-types-eth/src/transaction/common.rs index 94567b2372f..af94387f709 100644 --- a/crates/rpc-types-eth/src/transaction/common.rs +++ b/crates/rpc-types-eth/src/transaction/common.rs @@ -2,7 +2,7 @@ //! when working with RPC types, such as [Transaction] use crate::Transaction; -use alloy_primitives::{TxHash, B256}; +use alloy_primitives::{BlockHash, BlockNumber, TxHash, TxIndex, B256}; /// Additional fields in the context of a block that contains this transaction. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] @@ -11,11 +11,11 @@ pub struct TransactionInfo { /// Hash of the transaction. pub hash: Option, /// Index of the transaction in the block - pub index: Option, + pub index: Option, /// Hash of the block. - pub block_hash: Option, + pub block_hash: Option, /// Number of the block. - pub block_number: Option, + pub block_number: Option, /// Base fee of the block. pub base_fee: Option, } diff --git a/crates/rpc-types-trace/src/parity.rs b/crates/rpc-types-trace/src/parity.rs index 8a07ce1d6ea..d913de9394f 100644 --- a/crates/rpc-types-trace/src/parity.rs +++ b/crates/rpc-types-trace/src/parity.rs @@ -2,7 +2,7 @@ //! //! See -use alloy_primitives::{Address, Bytes, B256, U256, U64}; +use alloy_primitives::{Address, BlockHash, BlockNumber, Bytes, TxHash, TxIndex, B256, U256, U64}; use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer}; use std::{ collections::BTreeMap, @@ -397,17 +397,17 @@ pub struct LocalizedTransactionTrace { /// Hash of the block, if not pending. /// /// Note: this deviates from which always returns a block number - pub block_hash: Option, + pub block_hash: Option, /// Block number the transaction is included in, None if pending. /// /// Note: this deviates from which always returns a block number - pub block_number: Option, + pub block_number: Option, /// Hash of the transaction #[doc(alias = "tx_hash")] - pub transaction_hash: Option, + pub transaction_hash: Option, /// Transaction index within the block, None if pending. - #[doc(alias = "tx_position")] - pub transaction_position: Option, + #[doc(alias = "tx_position", alias = "transaction_index", alias = "tx_index")] + pub transaction_position: Option, } // Implement Serialize manually to ensure consistent ordering of fields to match other client's From 1d448030e4f5671a3f5f26005910577bd9dc6fc1 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 10 Jun 2024 13:18:56 +0200 Subject: [PATCH 02/17] prefer type alias --- crates/eips/src/eip1898.rs | 18 +++++++------- crates/genesis/src/lib.rs | 6 ++--- crates/network/src/lib.rs | 4 ++-- crates/node-bindings/src/anvil.rs | 12 +++++----- crates/provider/src/builder.rs | 3 ++- crates/provider/src/fillers/chain_id.rs | 7 +++--- crates/provider/src/heart.rs | 2 +- crates/rpc-types-anvil/src/lib.rs | 24 +++++++++---------- crates/rpc-types-eth/src/block.rs | 8 +++---- crates/rpc-types-eth/src/filter.rs | 4 ++-- crates/rpc-types-eth/src/pubsub.rs | 8 +++---- .../rpc-types-eth/src/transaction/common.rs | 2 +- crates/rpc-types-eth/src/transaction/mod.rs | 14 ++++++----- .../rpc-types-eth/src/transaction/receipt.rs | 10 ++++---- .../rpc-types-eth/src/transaction/request.rs | 2 +- crates/rpc-types-trace/src/opcode.rs | 8 +++---- crates/signer-gcp/src/signer.rs | 10 ++++---- crates/signer/src/error.rs | 10 ++++---- 18 files changed, 79 insertions(+), 73 deletions(-) diff --git a/crates/eips/src/eip1898.rs b/crates/eips/src/eip1898.rs index 007090b0457..afdd8add4a9 100644 --- a/crates/eips/src/eip1898.rs +++ b/crates/eips/src/eip1898.rs @@ -273,7 +273,7 @@ pub enum BlockId { impl BlockId { /// Returns the block hash if it is [BlockId::Hash] - pub const fn as_block_hash(&self) -> Option { + pub const fn as_block_hash(&self) -> Option { match self { Self::Hash(hash) => Some(hash.block_hash), Self::Number(_) => None, @@ -345,12 +345,12 @@ impl BlockId { } /// Create a new block hash instance. - pub const fn hash(block_hash: B256) -> Self { + pub const fn hash(block_hash: BlockHash) -> Self { Self::Hash(RpcBlockHash { block_hash, require_canonical: None }) } /// Create a new block hash instance that requires the block to be canonical. - pub const fn hash_canonical(block_hash: B256) -> Self { + pub const fn hash_canonical(block_hash: BlockHash) -> Self { Self::Hash(RpcBlockHash { block_hash, require_canonical: Some(true) }) } } @@ -379,14 +379,14 @@ impl From for BlockId { } } -impl From for BlockId { - fn from(block_hash: B256) -> Self { +impl From for BlockId { + fn from(block_hash: BlockHash) -> Self { Self::Hash(RpcBlockHash { block_hash, require_canonical: None }) } } -impl From<(B256, Option)> for BlockId { - fn from(hash_can: (B256, Option)) -> Self { +impl From<(BlockHash, Option)> for BlockId { + fn from(hash_can: (BlockHash, Option)) -> Self { Self::Hash(RpcBlockHash { block_hash: hash_can.0, require_canonical: hash_can.1 }) } } @@ -614,9 +614,9 @@ impl From<(BlockHash, BlockNumber)> for BlockNumHash { )] pub enum BlockHashOrNumber { /// A block hash - Hash(B256), + Hash(BlockHash), /// A block number - Number(u64), + Number(BlockNumber), } // === impl BlockHashOrNumber === diff --git a/crates/genesis/src/lib.rs b/crates/genesis/src/lib.rs index 6ed8e91f482..ef9eee0b9b6 100644 --- a/crates/genesis/src/lib.rs +++ b/crates/genesis/src/lib.rs @@ -12,7 +12,7 @@ extern crate alloc; use alloc::{collections::BTreeMap, string::String}; -use alloy_primitives::{Address, Bytes, B256, U256}; +use alloy_primitives::{Address, Bytes, ChainId, B256, U256}; use alloy_serde::{storage::deserialize_storage_map, ttd::deserialize_json_ttd_opt}; use serde::{Deserialize, Serialize}; @@ -68,7 +68,7 @@ impl Genesis { /// and funds the given address with max coins. /// /// Enables all hard forks up to London at genesis. - pub fn clique_genesis(chain_id: u64, signer_addr: Address) -> Self { + pub fn clique_genesis(chain_id: ChainId, signer_addr: Address) -> Self { // set up a clique config with an instant sealing period and short (8 block) epoch let clique_config = CliqueConfig { period: Some(0), epoch: Some(8) }; @@ -262,7 +262,7 @@ impl GenesisAccount { pub struct ChainConfig { /// The network's chain ID. #[serde(default = "mainnet_id")] - pub chain_id: u64, + pub chain_id: ChainId, /// The homestead switch block (None = no fork, 0 = already homestead). #[serde( diff --git a/crates/network/src/lib.rs b/crates/network/src/lib.rs index dd0a5931a7d..3037067d4b9 100644 --- a/crates/network/src/lib.rs +++ b/crates/network/src/lib.rs @@ -9,7 +9,7 @@ use alloy_consensus::TxReceipt; use alloy_eips::eip2718::{Eip2718Envelope, Eip2718Error}; use alloy_json_rpc::RpcObject; -use alloy_primitives::{Address, B256, U256}; +use alloy_primitives::{Address, TxHash, U256}; use core::fmt::{Debug, Display}; mod transaction; @@ -44,7 +44,7 @@ pub trait ReceiptResponse { pub trait TransactionResponse { /// Hash of the transaction #[doc(alias = "transaction_hash")] - fn tx_hash(&self) -> B256; + fn tx_hash(&self) -> TxHash; /// Sender of the transaction fn from(&self) -> Address; diff --git a/crates/node-bindings/src/anvil.rs b/crates/node-bindings/src/anvil.rs index 86360c0f504..68c0bcf9fe8 100644 --- a/crates/node-bindings/src/anvil.rs +++ b/crates/node-bindings/src/anvil.rs @@ -1,6 +1,6 @@ //! Utilities for launching an Anvil instance. -use alloy_primitives::{hex, Address}; +use alloy_primitives::{hex, Address, BlockNumber, ChainId}; use k256::{ecdsa::SigningKey, SecretKey as K256SecretKey}; use std::{ io::{BufRead, BufReader}, @@ -25,7 +25,7 @@ pub struct AnvilInstance { private_keys: Vec, addresses: Vec
, port: u16, - chain_id: Option, + chain_id: Option, } impl AnvilInstance { @@ -55,8 +55,8 @@ impl AnvilInstance { } /// Returns the chain of the anvil instance - pub fn chain_id(&self) -> u64 { - const ANVIL_HARDHAT_CHAIN_ID: u64 = 31_337; + pub fn chain_id(&self) -> ChainId { + const ANVIL_HARDHAT_CHAIN_ID: ChainId = 31_337; self.chain_id.unwrap_or(ANVIL_HARDHAT_CHAIN_ID) } @@ -150,10 +150,10 @@ pub struct Anvil { // If the block_time is an integer, f64::to_string() will output without a decimal point // which allows this to be backwards compatible. block_time: Option, - chain_id: Option, + chain_id: Option, mnemonic: Option, fork: Option, - fork_block_number: Option, + fork_block_number: Option, args: Vec, timeout: Option, } diff --git a/crates/provider/src/builder.rs b/crates/provider/src/builder.rs index 1ab8b29945b..215999a4df8 100644 --- a/crates/provider/src/builder.rs +++ b/crates/provider/src/builder.rs @@ -8,6 +8,7 @@ use crate::{ }; use alloy_chains::NamedChain; use alloy_network::{Ethereum, Network}; +use alloy_primitives::ChainId; use alloy_rpc_client::{BuiltInConnectionString, ClientBuilder, RpcClient}; use alloy_transport::{BoxTransport, Transport, TransportError, TransportResult}; use std::marker::PhantomData; @@ -160,7 +161,7 @@ impl ProviderBuilder { /// that the provider reports via [`Provider::get_chain_id`]. pub fn with_chain_id( self, - chain_id: u64, + chain_id: ChainId, ) -> ProviderBuilder, N> { self.filler(ChainIdFiller::new(Some(chain_id))) } diff --git a/crates/provider/src/fillers/chain_id.rs b/crates/provider/src/fillers/chain_id.rs index 5184aedc40b..b9fbc8d4143 100644 --- a/crates/provider/src/fillers/chain_id.rs +++ b/crates/provider/src/fillers/chain_id.rs @@ -1,6 +1,7 @@ use std::sync::{Arc, OnceLock}; use alloy_network::{Network, TransactionBuilder}; +use alloy_primitives::ChainId; use alloy_transport::TransportResult; use crate::{ @@ -35,7 +36,7 @@ use crate::{ /// # } /// ``` #[derive(Clone, Debug, Default, PartialEq, Eq)] -pub struct ChainIdFiller(Arc>); +pub struct ChainIdFiller(Arc>); impl ChainIdFiller { /// Create a new [`ChainIdFiller`] with an optional chain ID. @@ -43,7 +44,7 @@ impl ChainIdFiller { /// If a chain ID is provided, it will be used for filling. If a chain ID /// is not provided, the filler will attempt to fetch the chain ID from the /// provider the first time a transaction is prepared. - pub fn new(chain_id: Option) -> Self { + pub fn new(chain_id: Option) -> Self { let lock = OnceLock::new(); if let Some(chain_id) = chain_id { lock.set(chain_id).expect("brand new"); @@ -53,7 +54,7 @@ impl ChainIdFiller { } impl TxFiller for ChainIdFiller { - type Fillable = u64; + type Fillable = ChainId; fn status(&self, tx: &N::TransactionRequest) -> FillerControlFlow { if tx.chain_id().is_some() { diff --git a/crates/provider/src/heart.rs b/crates/provider/src/heart.rs index d250aef048a..05bf5cfe0f5 100644 --- a/crates/provider/src/heart.rs +++ b/crates/provider/src/heart.rs @@ -347,7 +347,7 @@ impl PendingTransaction { } impl Future for PendingTransaction { - type Output = TransportResult; + type Output = TransportResult; fn poll( mut self: std::pin::Pin<&mut Self>, diff --git a/crates/rpc-types-anvil/src/lib.rs b/crates/rpc-types-anvil/src/lib.rs index 47bed565434..093a2d648aa 100644 --- a/crates/rpc-types-anvil/src/lib.rs +++ b/crates/rpc-types-anvil/src/lib.rs @@ -6,7 +6,7 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -use alloy_primitives::{TxHash, B256, U256}; +use alloy_primitives::{BlockHash, BlockNumber, ChainId, TxHash, B256, U256}; use serde::{Deserialize, Deserializer, Serialize}; use std::collections::BTreeMap; @@ -19,7 +19,7 @@ pub struct Forking { /// The URL of the JSON-RPC endpoint to fork from. pub json_rpc_url: Option, /// The block number to fork from. - pub block_number: Option, + pub block_number: Option, } impl<'de> serde::Deserialize<'de> for Forking { @@ -32,7 +32,7 @@ impl<'de> serde::Deserialize<'de> for Forking { struct ForkOpts { json_rpc_url: Option, #[serde(default, with = "alloy_serde::quantity::opt")] - block_number: Option, + block_number: Option, } #[derive(serde::Deserialize)] @@ -63,11 +63,11 @@ impl<'de> serde::Deserialize<'de> for Forking { pub struct NodeInfo { /// The current block number #[serde(with = "alloy_serde::quantity")] - pub current_block_number: u64, + pub current_block_number: BlockNumber, /// The current block timestamp pub current_block_timestamp: u64, /// The current block hash - pub current_block_hash: B256, + pub current_block_hash: BlockHash, /// The enabled hardfork pub hard_fork: String, /// How transactions are ordered for mining @@ -86,7 +86,7 @@ pub struct NodeEnvironment { /// Base fee of the current block pub base_fee: U256, /// Chain id of the node. - pub chain_id: u64, + pub chain_id: ChainId, /// Configured block gas limit pub gas_limit: U256, /// Configured gas price @@ -100,7 +100,7 @@ pub struct NodeForkConfig { /// URL of the forked network pub fork_url: Option, /// Block number of the forked network - pub fork_block_number: Option, + pub fork_block_number: Option, /// Retry backoff for requests pub fork_retry_backoff: Option, } @@ -114,13 +114,13 @@ pub struct Metadata { /// client version pub client_version: String, /// Chain id of the node. - pub chain_id: u64, + pub chain_id: ChainId, /// Unique instance id pub instance_id: B256, /// Latest block number - pub latest_block_number: u64, + pub latest_block_number: BlockNumber, /// Latest block hash - pub latest_block_hash: B256, + pub latest_block_hash: BlockHash, /// Forked network info pub forked_network: Option, /// Snapshots of the chain @@ -133,9 +133,9 @@ pub struct Metadata { #[serde(rename_all = "camelCase")] pub struct ForkedNetwork { /// Chain id of the node. - pub chain_id: u64, + pub chain_id: ChainId, /// Block number of the forked chain - pub fork_block_number: u64, + pub fork_block_number: BlockNumber, /// Block hash of the forked chain pub fork_block_hash: TxHash, } diff --git a/crates/rpc-types-eth/src/block.rs b/crates/rpc-types-eth/src/block.rs index 1ce2a062008..a73ac274200 100644 --- a/crates/rpc-types-eth/src/block.rs +++ b/crates/rpc-types-eth/src/block.rs @@ -5,7 +5,7 @@ pub use alloy_eips::{ calc_blob_gasprice, calc_excess_blob_gas, BlockHashOrNumber, BlockId, BlockNumHash, BlockNumberOrTag, ForkBlock, RpcBlockHash, }; -use alloy_primitives::{Address, Bloom, Bytes, B256, B64, U256, U64}; +use alloy_primitives::{Address, BlockHash, BlockNumber, Bloom, Bytes, B256, B64, U256, U64}; use serde::{ser::Error, Deserialize, Serialize, Serializer}; use std::{collections::BTreeMap, ops::Deref}; @@ -50,7 +50,7 @@ impl Block { #[serde(rename_all = "camelCase")] pub struct Header { /// Hash of the block - pub hash: Option, + pub hash: Option, /// Hash of the parent pub parent_hash: B256, /// Hash of the uncles @@ -70,7 +70,7 @@ pub struct Header { pub difficulty: U256, /// Block number #[serde(default, with = "alloy_serde::quantity::opt")] - pub number: Option, + pub number: Option, /// Gas Limit #[serde(default, with = "alloy_serde::quantity")] pub gas_limit: u128, @@ -557,7 +557,7 @@ pub struct BlockOverrides { /// A dictionary that maps blockNumber to a user-defined hash. It could be queried from the /// solidity opcode BLOCKHASH. #[serde(default, skip_serializing_if = "Option::is_none")] - pub block_hash: Option>, + pub block_hash: Option>, } #[cfg(test)] diff --git a/crates/rpc-types-eth/src/filter.rs b/crates/rpc-types-eth/src/filter.rs index ac3042c90aa..49a5ffed621 100644 --- a/crates/rpc-types-eth/src/filter.rs +++ b/crates/rpc-types-eth/src/filter.rs @@ -1,5 +1,5 @@ use crate::{BlockNumberOrTag, Log as RpcLog, Transaction}; -use alloy_primitives::{keccak256, Address, Bloom, BloomInput, B256, U256, U64}; +use alloy_primitives::{keccak256, Address, BlockHash, Bloom, BloomInput, B256, U256, U64}; use itertools::{EitherOrBoth::*, Itertools}; use serde::{ de::{DeserializeOwned, MapAccess, Visitor}, @@ -166,7 +166,7 @@ pub enum FilterBlockOption { to_block: Option, }, /// The hash of the block if the filter only targets a single block - AtBlockHash(B256), + AtBlockHash(BlockHash), } impl FilterBlockOption { diff --git a/crates/rpc-types-eth/src/pubsub.rs b/crates/rpc-types-eth/src/pubsub.rs index da8f41563c5..4e00d515477 100644 --- a/crates/rpc-types-eth/src/pubsub.rs +++ b/crates/rpc-types-eth/src/pubsub.rs @@ -1,7 +1,7 @@ //! Ethereum types for pub-sub use crate::{Filter, Log, RichHeader, Transaction}; -use alloy_primitives::B256; +use alloy_primitives::{BlockNumber, B256}; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; /// Subscription result. @@ -37,12 +37,12 @@ pub struct SyncStatusMetadata { /// Whether the node is currently syncing. pub syncing: bool, /// The starting block. - pub starting_block: u64, + pub starting_block: BlockNumber, /// The current block. - pub current_block: u64, + pub current_block: BlockNumber, /// The highest block. #[serde(default, skip_serializing_if = "Option::is_none")] - pub highest_block: Option, + pub highest_block: Option, } impl Serialize for SubscriptionResult { diff --git a/crates/rpc-types-eth/src/transaction/common.rs b/crates/rpc-types-eth/src/transaction/common.rs index af94387f709..a50d5c3dd83 100644 --- a/crates/rpc-types-eth/src/transaction/common.rs +++ b/crates/rpc-types-eth/src/transaction/common.rs @@ -2,7 +2,7 @@ //! when working with RPC types, such as [Transaction] use crate::Transaction; -use alloy_primitives::{BlockHash, BlockNumber, TxHash, TxIndex, B256}; +use alloy_primitives::{BlockHash, BlockNumber, TxHash, TxIndex}; /// Additional fields in the context of a block that contains this transaction. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index d5446d99918..27cca08ec8d 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -5,7 +5,9 @@ use alloy_consensus::{ SignableTransaction, Signed, TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, TxEnvelope, TxLegacy, TxType, }; -use alloy_primitives::{Address, Bytes, TxKind, B256, U256}; +use alloy_primitives::{ + Address, BlockHash, BlockNumber, Bytes, ChainId, TxHash, TxIndex, TxKind, B256, U256, +}; use serde::{Deserialize, Serialize}; pub use alloy_consensus::BlobTransactionSidecar; @@ -38,19 +40,19 @@ pub use alloy_consensus::{AnyReceiptEnvelope, Receipt, ReceiptEnvelope, ReceiptW #[doc(alias = "Tx")] pub struct Transaction { /// Hash - pub hash: B256, + pub hash: TxHash, /// Nonce #[serde(with = "alloy_serde::quantity")] pub nonce: u64, /// Block hash #[serde(default)] - pub block_hash: Option, + pub block_hash: Option, /// Block number #[serde(default, with = "alloy_serde::quantity::opt")] - pub block_number: Option, + pub block_number: Option, /// Transaction Index #[serde(default, with = "alloy_serde::quantity::opt")] - pub transaction_index: Option, + pub transaction_index: Option, /// Sender pub from: Address, /// Recipient @@ -81,7 +83,7 @@ pub struct Transaction { pub signature: Option, /// The chain id of the transaction, if any. #[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")] - pub chain_id: Option, + pub chain_id: Option, /// Contains the blob hashes for eip-4844 transactions. #[serde(skip_serializing_if = "Option::is_none")] pub blob_versioned_hashes: Option>, diff --git a/crates/rpc-types-eth/src/transaction/receipt.rs b/crates/rpc-types-eth/src/transaction/receipt.rs index ab06808ce15..2a20d50c0ef 100644 --- a/crates/rpc-types-eth/src/transaction/receipt.rs +++ b/crates/rpc-types-eth/src/transaction/receipt.rs @@ -2,7 +2,7 @@ use crate::{Log, WithOtherFields}; use alloy_consensus::{AnyReceiptEnvelope, ReceiptEnvelope, TxType}; -use alloy_primitives::{Address, B256}; +use alloy_primitives::{Address, BlockHash, BlockNumber, TxHash, TxIndex, B256}; use serde::{Deserialize, Serialize}; /// Transaction receipt @@ -22,17 +22,17 @@ pub struct TransactionReceipt> { pub inner: T, /// Transaction Hash. #[doc(alias = "tx_hash")] - pub transaction_hash: B256, + pub transaction_hash: TxHash, /// Index within the block. #[serde(default, with = "alloy_serde::quantity::opt")] #[doc(alias = "tx_index")] - pub transaction_index: Option, + pub transaction_index: Option, /// Hash of the block this transaction was included within. #[serde(default)] - pub block_hash: Option, + pub block_hash: Option, /// Number of the block this transaction was included within. #[serde(default, with = "alloy_serde::quantity::opt")] - pub block_number: Option, + pub block_number: Option, /// Gas used by this transaction alone. #[serde(with = "alloy_serde::quantity")] pub gas_used: u128, diff --git a/crates/rpc-types-eth/src/transaction/request.rs b/crates/rpc-types-eth/src/transaction/request.rs index ce4d74cc917..987678fda6a 100644 --- a/crates/rpc-types-eth/src/transaction/request.rs +++ b/crates/rpc-types-eth/src/transaction/request.rs @@ -820,7 +820,7 @@ mod tests { #[test] fn serde_tx_chain_id_field() { - let chain_id: u64 = 12345678; + let chain_id: ChainId = 12345678; let chain_id_as_num = format!(r#"{{"chainId": {} }}"#, chain_id); let req1 = serde_json::from_str::(&chain_id_as_num).unwrap(); diff --git a/crates/rpc-types-trace/src/opcode.rs b/crates/rpc-types-trace/src/opcode.rs index 979ee9d9bda..cafd5ffdd79 100644 --- a/crates/rpc-types-trace/src/opcode.rs +++ b/crates/rpc-types-trace/src/opcode.rs @@ -1,6 +1,6 @@ //! Types for opcode tracing. -use alloy_primitives::B256; +use alloy_primitives::{BlockHash, BlockNumber, TxHash}; use serde::{Deserialize, Serialize}; /// Opcode gas usage for a transaction. @@ -8,9 +8,9 @@ use serde::{Deserialize, Serialize}; #[serde(rename_all = "camelCase")] pub struct BlockOpcodeGas { /// The block hash - pub block_hash: B256, + pub block_hash: BlockHash, /// The block number - pub block_number: u64, + pub block_number: BlockNumber, /// All executed transactions in the block in the order they were executed, with their opcode /// gas usage. pub transactions: Vec, @@ -23,7 +23,7 @@ pub struct BlockOpcodeGas { pub struct TransactionOpcodeGas { /// The transaction hash #[doc(alias = "tx_hash")] - pub transaction_hash: B256, + pub transaction_hash: TxHash, /// The gas used by each opcode in the transaction pub opcode_gas: Vec, } diff --git a/crates/signer-gcp/src/signer.rs b/crates/signer-gcp/src/signer.rs index dc5e24f4dc4..be982797a08 100644 --- a/crates/signer-gcp/src/signer.rs +++ b/crates/signer-gcp/src/signer.rs @@ -1,5 +1,5 @@ use alloy_consensus::SignableTransaction; -use alloy_primitives::{hex, Address, B256}; +use alloy_primitives::{hex, Address, ChainId, B256}; use alloy_signer::{sign_transaction_with_chain_id, Result, Signature, Signer}; use async_trait::async_trait; use gcloud_sdk::{ @@ -109,7 +109,7 @@ impl KeySpecifier { pub struct GcpSigner { client: Client, key_name: String, - chain_id: Option, + chain_id: Option, pubkey: VerifyingKey, address: Address, } @@ -177,12 +177,12 @@ impl Signer for GcpSigner { } #[inline] - fn chain_id(&self) -> Option { + fn chain_id(&self) -> Option { self.chain_id } #[inline] - fn set_chain_id(&mut self, chain_id: Option) { + fn set_chain_id(&mut self, chain_id: Option) { self.chain_id = chain_id; } } @@ -195,7 +195,7 @@ impl GcpSigner { pub async fn new( client: Client, key_specifier: KeySpecifier, - chain_id: Option, + chain_id: Option, ) -> Result { let key_name = key_specifier.0; let resp = request_get_pubkey(&client, &key_name).await?; diff --git a/crates/signer/src/error.rs b/crates/signer/src/error.rs index b7fc30612e1..93a59677806 100644 --- a/crates/signer/src/error.rs +++ b/crates/signer/src/error.rs @@ -1,4 +1,4 @@ -use alloy_primitives::hex; +use alloy_primitives::{hex, ChainId}; use k256::ecdsa; use std::fmt; use thiserror::Error; @@ -13,12 +13,14 @@ pub enum Error { #[error("operation `{0}` is not supported by the signer")] UnsupportedOperation(UnsupportedSignerOperation), /// Mismatch between provided transaction chain ID and signer chain ID. - #[error("transaction-provided chain ID ({tx}) does not match the signer's ({signer})")] + #[error( + "transaction-provided chain ID ({tx}) does not match the signer's chain ID ({signer})" + )] TransactionChainIdMismatch { /// The signer's chain ID. - signer: u64, + signer: ChainId, /// The chain ID provided by the transaction. - tx: u64, + tx: ChainId, }, /// [`alloy_dyn_abi`] error. #[error(transparent)] From 862d10c2a9716817cffe26c4755f0c456eb3998a Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 10 Jun 2024 13:30:45 +0200 Subject: [PATCH 03/17] clean up --- crates/eips/src/eip1898.rs | 14 +++++++------- crates/rpc-types-beacon/src/relay.rs | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/eips/src/eip1898.rs b/crates/eips/src/eip1898.rs index afdd8add4a9..68fc1b71191 100644 --- a/crates/eips/src/eip1898.rs +++ b/crates/eips/src/eip1898.rs @@ -42,19 +42,19 @@ impl RpcBlockHash { } } -impl From for RpcBlockHash { +impl From for RpcBlockHash { fn from(value: B256) -> Self { Self::from_hash(value, None) } } -impl From for BlockHash { +impl From for B256 { fn from(value: RpcBlockHash) -> Self { value.block_hash } } -impl AsRef for RpcBlockHash { +impl AsRef for RpcBlockHash { fn as_ref(&self) -> &B256 { &self.block_hash } @@ -361,8 +361,8 @@ impl Default for BlockId { } } -impl From for BlockId { - fn from(num: u64) -> Self { +impl From for BlockId { + fn from(num: BlockNumber) -> Self { BlockNumberOrTag::Number(num).into() } } @@ -614,9 +614,9 @@ impl From<(BlockHash, BlockNumber)> for BlockNumHash { )] pub enum BlockHashOrNumber { /// A block hash - Hash(BlockHash), + Hash(B256), /// A block number - Number(BlockNumber), + Number(u64), } // === impl BlockHashOrNumber === diff --git a/crates/rpc-types-beacon/src/relay.rs b/crates/rpc-types-beacon/src/relay.rs index 893c5a5e851..c09aa153088 100644 --- a/crates/rpc-types-beacon/src/relay.rs +++ b/crates/rpc-types-beacon/src/relay.rs @@ -3,7 +3,7 @@ //! See also use crate::{BlsPublicKey, BlsSignature}; -use alloy_primitives::{Address, BlockHash, B256, U256}; +use alloy_primitives::{Address, BlockHash, BlockNumber, B256, U256}; use alloy_rpc_types_engine::{ BlobsBundleV1, ExecutionPayload, ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3, }; @@ -66,7 +66,7 @@ pub struct BidTrace { /// The parent hash of the block. pub parent_hash: B256, /// The hash of the block. - pub block_hash: B256, + pub block_hash: BlockHash, /// The public key of the builder. pub builder_pubkey: BlsPublicKey, /// The public key of the proposer. @@ -192,7 +192,7 @@ pub struct ProposerPayloadsDeliveredQuery { pub block_hash: Option, /// Search for a specific EL block number #[serde(skip_serializing_if = "Option::is_none")] - pub block_number: Option, + pub block_number: Option, /// Filter results by a proposer public key #[serde(skip_serializing_if = "Option::is_none")] pub proposer_pubkey: Option, @@ -341,9 +341,9 @@ pub mod error { #[error("incorrect ParentHash {actual}, expected {expected}")] IncorrectParentHash { /// The expected parent hash - expected: BlockHash, + expected: B256, /// The actual parent hash - actual: BlockHash, + actual: B256, }, /// Thrown if block hash mismatches #[error("incorrect BlockHash {actual}, expected {expected}")] From 6f2df6a8fec196fe319e739d97b2c8d45ff5597a Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 10 Jun 2024 15:36:57 +0200 Subject: [PATCH 04/17] fix typo --- crates/provider/src/provider/trait.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/provider/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index 7d18ee02ca8..db9c9f528eb 100644 --- a/crates/provider/src/provider/trait.rs +++ b/crates/provider/src/provider/trait.rs @@ -490,7 +490,7 @@ pub trait Provider: self.send_transaction_internal(SendableTx::Envelope(tx)).await } - /// This method allows [`ProviderLayer`] and [`TxFiller`] to bulid the + /// This method allows [`ProviderLayer`] and [`TxFiller`] to build the /// transaction and send it to the network without changing user-facing /// APIs. Generally implementors should NOT override this method. /// From 518489d6c0b91f8caab6dee7c847d28ec4cd929e Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 10 Jun 2024 15:37:17 +0200 Subject: [PATCH 05/17] fix typo --- crates/rpc-client/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/rpc-client/README.md b/crates/rpc-client/README.md index 1a1ccc84813..3c1ed3c5386 100644 --- a/crates/rpc-client/README.md +++ b/crates/rpc-client/README.md @@ -13,7 +13,7 @@ For example, to make a simple request: ```rust,ignore // Instantiate a new client over a transport. -let client: ReqwestClient = ClientBulider::default().http(url); +let client: ReqwestClient = ClientBuilder::default().http(url); // Prepare a request to the server. let request = client.request("eth_blockNumber", ()); @@ -26,7 +26,7 @@ Batch requests are also supported: ```rust,ignore // Instantiate a new client over a transport. -let client: ReqwestClient = ClientBulider::default().http(url); +let client: ReqwestClient = ClientBuilder::default().http(url); // Prepare a batch request to the server. let batch = client.new_batch(); From ba2c9455627b094a1181160705e53cf5f4ed3108 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 10 Jun 2024 18:32:35 +0200 Subject: [PATCH 06/17] add TxNonce and BlockTimestamp --- crates/consensus/src/transaction/eip1559.rs | 32 ++++++++++----------- crates/consensus/src/transaction/eip2930.rs | 32 ++++++++++----------- crates/consensus/src/transaction/eip4844.rs | 20 +++++++------ crates/consensus/src/transaction/legacy.rs | 28 +++++++++--------- crates/consensus/src/transaction/mod.rs | 22 +++++++------- crates/consensus/src/transaction/typed.rs | 4 +-- crates/eips/src/eip1898.rs | 8 +++--- crates/genesis/src/lib.rs | 6 ++-- crates/network/src/any/builder.rs | 6 ++-- crates/network/src/ethereum/builder.rs | 6 ++-- crates/network/src/transaction/builder.rs | 14 ++++----- crates/provider/src/ext/anvil.rs | 9 ++++-- crates/rpc-types-anvil/src/lib.rs | 10 ++++--- crates/rpc-types-engine/src/payload.rs | 8 ++++-- crates/rpc-types-eth/src/account.rs | 4 +-- crates/rpc-types-eth/src/block.rs | 6 ++-- crates/rpc-types-eth/src/filter.rs | 8 +++--- crates/rpc-types-eth/src/log.rs | 6 ++-- crates/rpc-types-eth/src/transaction/mod.rs | 5 ++-- 19 files changed, 124 insertions(+), 110 deletions(-) diff --git a/crates/consensus/src/transaction/eip1559.rs b/crates/consensus/src/transaction/eip1559.rs index 3869938fd05..f1d54fc7603 100644 --- a/crates/consensus/src/transaction/eip1559.rs +++ b/crates/consensus/src/transaction/eip1559.rs @@ -1,6 +1,6 @@ use crate::{SignableTransaction, Signed, Transaction, TxType}; use alloy_eips::eip2930::AccessList; -use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, U256}; +use alloy_primitives::{aliases::TxNonce, keccak256, Bytes, ChainId, Signature, TxKind, U256}; use alloy_rlp::{BufMut, Decodable, Encodable, Header}; use core::mem; @@ -18,7 +18,7 @@ pub struct TxEip1559 { 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::quantity"))] - pub nonce: u64, + pub nonce: TxNonce, /// 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 @@ -249,7 +249,7 @@ impl TxEip1559 { #[inline] pub fn size(&self) -> usize { mem::size_of::() + // chain_id - mem::size_of::() + // nonce + mem::size_of::() + // nonce mem::size_of::() + // gas_limit mem::size_of::() + // max_fee_per_gas mem::size_of::() + // max_priority_fee_per_gas @@ -261,23 +261,11 @@ impl TxEip1559 { } impl Transaction for TxEip1559 { - fn input(&self) -> &[u8] { - &self.input - } - - fn to(&self) -> TxKind { - self.to - } - - fn value(&self) -> U256 { - self.value - } - fn chain_id(&self) -> Option { Some(self.chain_id) } - fn nonce(&self) -> u64 { + fn nonce(&self) -> TxNonce { self.nonce } @@ -288,6 +276,18 @@ impl Transaction for TxEip1559 { fn gas_price(&self) -> Option { None } + + fn to(&self) -> TxKind { + self.to + } + + fn value(&self) -> U256 { + self.value + } + + fn input(&self) -> &[u8] { + &self.input + } } impl SignableTransaction for TxEip1559 { diff --git a/crates/consensus/src/transaction/eip2930.rs b/crates/consensus/src/transaction/eip2930.rs index 690b9e34704..666dbcbb207 100644 --- a/crates/consensus/src/transaction/eip2930.rs +++ b/crates/consensus/src/transaction/eip2930.rs @@ -1,6 +1,6 @@ use crate::{SignableTransaction, Signed, Transaction, TxType}; use alloy_eips::eip2930::AccessList; -use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, U256}; +use alloy_primitives::{aliases::TxNonce, keccak256, Bytes, ChainId, Signature, TxKind, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header}; use core::mem; @@ -18,7 +18,7 @@ pub struct TxEip2930 { 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::quantity"))] - pub nonce: u64, + pub nonce: TxNonce, /// A scalar value equal to the number of /// Wei to be paid per unit of gas for all computation /// costs incurred as a result of the execution of this transaction; formally Tp. @@ -63,7 +63,7 @@ impl TxEip2930 { #[inline] pub fn size(&self) -> usize { mem::size_of::() + // chain_id - mem::size_of::() + // nonce + mem::size_of::() + // nonce mem::size_of::() + // gas_price mem::size_of::() + // gas_limit self.to.size() + // to @@ -225,23 +225,11 @@ impl TxEip2930 { } impl Transaction for TxEip2930 { - fn input(&self) -> &[u8] { - &self.input - } - - fn to(&self) -> TxKind { - self.to - } - - fn value(&self) -> U256 { - self.value - } - fn chain_id(&self) -> Option { Some(self.chain_id) } - fn nonce(&self) -> u64 { + fn nonce(&self) -> TxNonce { self.nonce } @@ -252,6 +240,18 @@ impl Transaction for TxEip2930 { fn gas_price(&self) -> Option { Some(self.gas_price) } + + fn to(&self) -> TxKind { + self.to + } + + fn value(&self) -> U256 { + self.value + } + + fn input(&self) -> &[u8] { + &self.input + } } impl SignableTransaction for TxEip2930 { diff --git a/crates/consensus/src/transaction/eip4844.rs b/crates/consensus/src/transaction/eip4844.rs index d7dfd911202..2f8cfa330ae 100644 --- a/crates/consensus/src/transaction/eip4844.rs +++ b/crates/consensus/src/transaction/eip4844.rs @@ -1,7 +1,9 @@ use crate::{SignableTransaction, Signed, Transaction, TxType}; use alloy_eips::{eip2930::AccessList, eip4844::DATA_GAS_PER_BLOB}; -use alloy_primitives::{keccak256, Address, Bytes, ChainId, Signature, TxKind, B256, U256}; +use alloy_primitives::{ + aliases::TxNonce, keccak256, Address, Bytes, ChainId, Signature, TxKind, B256, U256, +}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header}; use core::mem; @@ -217,7 +219,7 @@ impl Transaction for TxEip4844Variant { } } - fn nonce(&self) -> u64 { + fn nonce(&self) -> TxNonce { match self { Self::TxEip4844(tx) => tx.nonce, Self::TxEip4844WithSidecar(tx) => tx.tx().nonce, @@ -294,7 +296,7 @@ pub struct TxEip4844 { 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::quantity"))] - pub nonce: u64, + pub nonce: TxNonce, /// 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 @@ -472,7 +474,7 @@ impl TxEip4844 { #[inline] pub fn size(&self) -> usize { mem::size_of::() + // chain_id - mem::size_of::() + // nonce + mem::size_of::() + // nonce mem::size_of::() + // gas_limit mem::size_of::() + // max_fee_per_gas mem::size_of::() + // max_priority_fee_per_gas @@ -645,7 +647,7 @@ impl Transaction for TxEip4844 { Some(self.chain_id) } - fn nonce(&self) -> u64 { + fn nonce(&self) -> TxNonce { self.nonce } @@ -868,6 +870,10 @@ impl Transaction for TxEip4844WithSidecar { self.tx.chain_id() } + fn nonce(&self) -> TxNonce { + self.tx.nonce() + } + fn gas_limit(&self) -> u128 { self.tx.gas_limit() } @@ -876,10 +882,6 @@ impl Transaction for TxEip4844WithSidecar { self.tx.gas_price() } - fn nonce(&self) -> u64 { - self.tx.nonce() - } - fn to(&self) -> TxKind { self.tx.to() } diff --git a/crates/consensus/src/transaction/legacy.rs b/crates/consensus/src/transaction/legacy.rs index 26d15e903b8..8921ba58bc0 100644 --- a/crates/consensus/src/transaction/legacy.rs +++ b/crates/consensus/src/transaction/legacy.rs @@ -1,5 +1,5 @@ use crate::{SignableTransaction, Signed, Transaction}; -use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, U256}; +use alloy_primitives::{aliases::TxNonce, keccak256, Bytes, ChainId, Signature, TxKind, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header, Result}; use core::mem; @@ -198,23 +198,11 @@ impl TxLegacy { } impl Transaction for TxLegacy { - fn input(&self) -> &[u8] { - &self.input - } - - fn to(&self) -> TxKind { - self.to - } - - fn value(&self) -> U256 { - self.value - } - fn chain_id(&self) -> Option { self.chain_id } - fn nonce(&self) -> u64 { + fn nonce(&self) -> TxNonce { self.nonce } @@ -225,6 +213,18 @@ impl Transaction for TxLegacy { fn gas_price(&self) -> Option { Some(self.gas_price) } + + fn to(&self) -> TxKind { + self.to + } + + fn value(&self) -> U256 { + self.value + } + + fn input(&self) -> &[u8] { + &self.input + } } impl SignableTransaction for TxLegacy { diff --git a/crates/consensus/src/transaction/mod.rs b/crates/consensus/src/transaction/mod.rs index df3c0f2c891..c1165aa991d 100644 --- a/crates/consensus/src/transaction/mod.rs +++ b/crates/consensus/src/transaction/mod.rs @@ -1,7 +1,7 @@ //! Transaction types. use crate::Signed; -use alloy_primitives::{keccak256, ChainId, TxKind, B256, U256}; +use alloy_primitives::{aliases::TxNonce, keccak256, ChainId, TxKind, B256, U256}; use core::any; #[cfg(not(feature = "std"))] @@ -36,26 +36,26 @@ pub use typed::TypedTransaction; /// Represents a minimal EVM transaction. #[doc(alias = "Tx")] pub trait Transaction: any::Any + Send + Sync + 'static { - /// Get `data`. - fn input(&self) -> &[u8]; - - /// Get `to`. - fn to(&self) -> TxKind; - - /// Get `value`. - fn value(&self) -> U256; - /// Get `chain_id`. fn chain_id(&self) -> Option; /// Get `nonce`. - fn nonce(&self) -> u64; + fn nonce(&self) -> TxNonce; /// Get `gas_limit`. fn gas_limit(&self) -> u128; /// Get `gas_price`. fn gas_price(&self) -> Option; + + /// Get `to`. + fn to(&self) -> TxKind; + + /// Get `value`. + fn value(&self) -> U256; + + /// Get `data`. + fn input(&self) -> &[u8]; } /// A signable transaction. diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index 02a05246b9b..1e1408e052b 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -2,7 +2,7 @@ use crate::{ transaction::eip4844::{TxEip4844, TxEip4844Variant, TxEip4844WithSidecar}, Transaction, TxEip1559, TxEip2930, TxEnvelope, TxLegacy, TxType, }; -use alloy_primitives::TxKind; +use alloy_primitives::{aliases::TxNonce, TxKind}; /// The TypedTransaction enum represents all Ethereum transaction request types. /// @@ -151,7 +151,7 @@ impl Transaction for TypedTransaction { } } - fn nonce(&self) -> u64 { + fn nonce(&self) -> TxNonce { match self { Self::Legacy(tx) => tx.nonce(), Self::Eip2930(tx) => tx.nonce(), diff --git a/crates/eips/src/eip1898.rs b/crates/eips/src/eip1898.rs index 68fc1b71191..02f53912aa2 100644 --- a/crates/eips/src/eip1898.rs +++ b/crates/eips/src/eip1898.rs @@ -119,14 +119,14 @@ impl BlockNumberOrTag { } impl From for BlockNumberOrTag { - fn from(num: u64) -> Self { - Self::Number(num) + fn from(block_number: u64) -> Self { + Self::Number(block_number) } } impl From for BlockNumberOrTag { - fn from(num: U64) -> Self { - num.to::().into() + fn from(block_number: U64) -> Self { + block_number.to::().into() } } diff --git a/crates/genesis/src/lib.rs b/crates/genesis/src/lib.rs index ef9eee0b9b6..f9abaf27e85 100644 --- a/crates/genesis/src/lib.rs +++ b/crates/genesis/src/lib.rs @@ -12,7 +12,7 @@ extern crate alloc; use alloc::{collections::BTreeMap, string::String}; -use alloy_primitives::{Address, Bytes, ChainId, B256, U256}; +use alloy_primitives::{aliases::BlockTimestamp, Address, BlockNumber, Bytes, ChainId, B256, U256}; use alloy_serde::{storage::deserialize_storage_map, ttd::deserialize_json_ttd_opt}; use serde::{Deserialize, Serialize}; @@ -28,7 +28,7 @@ pub struct Genesis { pub nonce: u64, /// The genesis header timestamp. #[serde(with = "alloy_serde::quantity")] - pub timestamp: u64, + pub timestamp: BlockTimestamp, /// The genesis header extra data. pub extra_data: Bytes, /// The genesis header gas limit. @@ -60,7 +60,7 @@ pub struct Genesis { pub blob_gas_used: Option, /// The genesis block number #[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")] - pub number: Option, + pub number: Option, } impl Genesis { diff --git a/crates/network/src/any/builder.rs b/crates/network/src/any/builder.rs index 05867896e25..53542bcc2f1 100644 --- a/crates/network/src/any/builder.rs +++ b/crates/network/src/any/builder.rs @@ -1,7 +1,7 @@ use std::ops::{Deref, DerefMut}; use alloy_consensus::BlobTransactionSidecar; -use alloy_primitives::Bytes; +use alloy_primitives::{aliases::TxNonce, Bytes}; use alloy_rpc_types_eth::{AccessList, TransactionRequest, WithOtherFields}; use crate::{any::AnyNetwork, BuildResult, Network, TransactionBuilder, TransactionBuilderError}; @@ -15,11 +15,11 @@ impl TransactionBuilder for WithOtherFields { self.deref_mut().set_chain_id(chain_id) } - fn nonce(&self) -> Option { + fn nonce(&self) -> Option { self.deref().nonce() } - fn set_nonce(&mut self, nonce: u64) { + fn set_nonce(&mut self, nonce: TxNonce) { self.deref_mut().set_nonce(nonce) } diff --git a/crates/network/src/ethereum/builder.rs b/crates/network/src/ethereum/builder.rs index 74913e957e7..c5bc3d98949 100644 --- a/crates/network/src/ethereum/builder.rs +++ b/crates/network/src/ethereum/builder.rs @@ -2,7 +2,7 @@ use crate::{ BuildResult, Ethereum, Network, NetworkSigner, TransactionBuilder, TransactionBuilderError, }; use alloy_consensus::{BlobTransactionSidecar, TxType, TypedTransaction}; -use alloy_primitives::{Address, Bytes, ChainId, TxKind, U256}; +use alloy_primitives::{aliases::TxNonce, Address, Bytes, ChainId, TxKind, U256}; use alloy_rpc_types_eth::{request::TransactionRequest, AccessList}; impl TransactionBuilder for TransactionRequest { @@ -14,11 +14,11 @@ impl TransactionBuilder for TransactionRequest { self.chain_id = Some(chain_id); } - fn nonce(&self) -> Option { + fn nonce(&self) -> Option { self.nonce } - fn set_nonce(&mut self, nonce: u64) { + fn set_nonce(&mut self, nonce: TxNonce) { self.nonce = Some(nonce); } diff --git a/crates/network/src/transaction/builder.rs b/crates/network/src/transaction/builder.rs index d2bbdbb2334..7ddf71c28b5 100644 --- a/crates/network/src/transaction/builder.rs +++ b/crates/network/src/transaction/builder.rs @@ -1,7 +1,7 @@ use super::signer::NetworkSigner; use crate::Network; use alloy_consensus::BlobTransactionSidecar; -use alloy_primitives::{Address, Bytes, ChainId, TxKind, U256}; +use alloy_primitives::{aliases::TxNonce, Address, Bytes, ChainId, TxKind, U256}; use alloy_rpc_types_eth::AccessList; use alloy_sol_types::SolCall; use futures_utils_wasm::impl_future; @@ -65,13 +65,13 @@ pub trait TransactionBuilder: Default + Sized + Send + Sync + 'stati } /// Get the nonce for the transaction. - fn nonce(&self) -> Option; + fn nonce(&self) -> Option; /// Set the nonce for the transaction. - fn set_nonce(&mut self, nonce: u64); + fn set_nonce(&mut self, nonce: TxNonce); /// Builder-pattern method for setting the nonce. - fn with_nonce(mut self, nonce: u64) -> Self { + fn with_nonce(mut self, nonce: TxNonce) -> Self { self.set_nonce(nonce); self } @@ -101,16 +101,16 @@ pub trait TransactionBuilder: Default + Sized + Send + Sync + 'stati } /// Get the kind of transaction. - fn kind(&self) -> Option; + fn kind(&self) -> Option; /// Clear the kind of transaction. fn clear_kind(&mut self); /// Set the kind of transaction. - fn set_kind(&mut self, kind: alloy_primitives::TxKind); + fn set_kind(&mut self, kind: TxKind); /// Builder-pattern method for setting the kind of transaction. - fn with_kind(mut self, kind: alloy_primitives::TxKind) -> Self { + fn with_kind(mut self, kind: TxKind) -> Self { self.set_kind(kind); self } diff --git a/crates/provider/src/ext/anvil.rs b/crates/provider/src/ext/anvil.rs index 94ad65d9f8a..f47ab28777e 100644 --- a/crates/provider/src/ext/anvil.rs +++ b/crates/provider/src/ext/anvil.rs @@ -1,7 +1,7 @@ //! This module extends the Ethereum JSON-RPC provider with the Anvil namespace's RPC methods. use crate::Provider; use alloy_network::Network; -use alloy_primitives::{Address, Bytes, TxHash, B256, U256}; +use alloy_primitives::{aliases::BlockTimestamp, Address, Bytes, TxHash, B256, U256}; use alloy_rpc_types_anvil::{Forking, Metadata, MineOptions, NodeInfo}; use alloy_rpc_types_eth::{Block, TransactionRequest, WithOtherFields}; use alloy_transport::{Transport, TransportResult}; @@ -111,11 +111,14 @@ pub trait AnvilApi: Send + Sync { async fn anvil_increase_time(&self, seconds: U256) -> TransportResult; /// Similar to `evm_increaseTime` but takes the exact timestamp that you want in the next block. - async fn anvil_set_next_block_timestamp(&self, seconds: u64) -> TransportResult<()>; + async fn anvil_set_next_block_timestamp( + &self, + timestamp: BlockTimestamp, + ) -> TransportResult<()>; /// Sets the specific timestamp and returns the number of seconds between the given timestamp /// and the current time. - async fn anvil_set_time(&self, timestamp: u64) -> TransportResult; + async fn anvil_set_time(&self, timestamp: BlockTimestamp) -> TransportResult; /// Set the next block gas limit. async fn anvil_set_block_gas_limit(&self, gas_limit: U256) -> TransportResult; diff --git a/crates/rpc-types-anvil/src/lib.rs b/crates/rpc-types-anvil/src/lib.rs index 093a2d648aa..e01b67ffa58 100644 --- a/crates/rpc-types-anvil/src/lib.rs +++ b/crates/rpc-types-anvil/src/lib.rs @@ -6,7 +6,9 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -use alloy_primitives::{BlockHash, BlockNumber, ChainId, TxHash, B256, U256}; +use alloy_primitives::{ + aliases::BlockTimestamp, BlockHash, BlockNumber, ChainId, TxHash, B256, U256, +}; use serde::{Deserialize, Deserializer, Serialize}; use std::collections::BTreeMap; @@ -65,7 +67,7 @@ pub struct NodeInfo { #[serde(with = "alloy_serde::quantity")] pub current_block_number: BlockNumber, /// The current block timestamp - pub current_block_timestamp: u64, + pub current_block_timestamp: BlockTimestamp, /// The current block hash pub current_block_hash: BlockHash, /// The enabled hardfork @@ -148,14 +150,14 @@ pub enum MineOptions { Options { /// The timestamp the block should be mined with #[serde(with = "alloy_serde::quantity::opt")] - timestamp: Option, + timestamp: Option, /// If `blocks` is given, it will mine exactly blocks number of blocks, regardless of any /// other blocks mined or reverted during it's operation blocks: Option, }, /// The timestamp the block should be mined with #[serde(with = "alloy_serde::quantity::opt")] - Timestamp(Option), + Timestamp(Option), } impl Default for MineOptions { diff --git a/crates/rpc-types-engine/src/payload.rs b/crates/rpc-types-engine/src/payload.rs index b9f3248f4e5..276177a4410 100644 --- a/crates/rpc-types-engine/src/payload.rs +++ b/crates/rpc-types-engine/src/payload.rs @@ -1,7 +1,9 @@ //! Payload types. use alloy_consensus::{Blob, Bytes48}; use alloy_eips::{eip6110::DepositRequest, eip7002::WithdrawalRequest}; -use alloy_primitives::{Address, Bloom, Bytes, B256, B64, U256}; +use alloy_primitives::{ + aliases::BlockTimestamp, Address, BlockNumber, Bloom, Bytes, B256, B64, U256, +}; use alloy_rpc_types_eth::{transaction::BlobTransactionSidecar, Withdrawal}; use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer}; use std::fmt; @@ -156,7 +158,7 @@ pub struct ExecutionPayloadV1 { pub prev_randao: B256, /// The block number. #[serde(with = "alloy_serde::quantity")] - pub block_number: u64, + pub block_number: BlockNumber, /// The gas limit of the block. #[serde(with = "alloy_serde::quantity")] pub gas_limit: u64, @@ -165,7 +167,7 @@ pub struct ExecutionPayloadV1 { pub gas_used: u64, /// The timestamp of the block. #[serde(with = "alloy_serde::quantity")] - pub timestamp: u64, + pub timestamp: BlockTimestamp, /// The extra data of the block. pub extra_data: Bytes, /// The base fee per gas of the block. diff --git a/crates/rpc-types-eth/src/account.rs b/crates/rpc-types-eth/src/account.rs index 26f6c9497ea..75d41ab5392 100644 --- a/crates/rpc-types-eth/src/account.rs +++ b/crates/rpc-types-eth/src/account.rs @@ -1,4 +1,4 @@ -use alloy_primitives::{Address, Bytes, B256, B512, U256, U64}; +use alloy_primitives::{aliases::TxNonce, Address, Bytes, B256, B512, U256, U64}; use alloy_serde::storage::JsonStorageKey; use serde::{Deserialize, Serialize}; @@ -32,7 +32,7 @@ pub struct EIP1186AccountProofResponse { /// The hash of the code of the account. pub code_hash: B256, /// The account nonce. - pub nonce: U64, + pub nonce: TxNonce, /// The hash of the storage of the account. pub storage_hash: B256, /// The account proof. diff --git a/crates/rpc-types-eth/src/block.rs b/crates/rpc-types-eth/src/block.rs index a73ac274200..802ecf3cf6e 100644 --- a/crates/rpc-types-eth/src/block.rs +++ b/crates/rpc-types-eth/src/block.rs @@ -5,7 +5,9 @@ pub use alloy_eips::{ calc_blob_gasprice, calc_excess_blob_gas, BlockHashOrNumber, BlockId, BlockNumHash, BlockNumberOrTag, ForkBlock, RpcBlockHash, }; -use alloy_primitives::{Address, BlockHash, BlockNumber, Bloom, Bytes, B256, B64, U256, U64}; +use alloy_primitives::{ + aliases::BlockTimestamp, Address, BlockHash, BlockNumber, Bloom, Bytes, B256, B64, U256, U64, +}; use serde::{ser::Error, Deserialize, Serialize, Serializer}; use std::{collections::BTreeMap, ops::Deref}; @@ -79,7 +81,7 @@ pub struct Header { pub gas_used: u128, /// Timestamp #[serde(default, with = "alloy_serde::quantity")] - pub timestamp: u64, + pub timestamp: BlockTimestamp, /// Total difficulty #[serde(default, skip_serializing_if = "Option::is_none")] pub total_difficulty: Option, diff --git a/crates/rpc-types-eth/src/filter.rs b/crates/rpc-types-eth/src/filter.rs index 23fa26a79cb..078144f55ce 100644 --- a/crates/rpc-types-eth/src/filter.rs +++ b/crates/rpc-types-eth/src/filter.rs @@ -203,14 +203,14 @@ impl From for FilterBlockOption { } impl From for FilterBlockOption { - fn from(block: U64) -> Self { - BlockNumberOrTag::from(block).into() + fn from(block_number: U64) -> Self { + BlockNumberOrTag::from(block_number).into() } } impl From for FilterBlockOption { - fn from(block: u64) -> Self { - BlockNumberOrTag::from(block).into() + fn from(block_number: u64) -> Self { + BlockNumberOrTag::from(block_number).into() } } diff --git a/crates/rpc-types-eth/src/log.rs b/crates/rpc-types-eth/src/log.rs index f4f716f5315..a24dcd4b494 100644 --- a/crates/rpc-types-eth/src/log.rs +++ b/crates/rpc-types-eth/src/log.rs @@ -1,6 +1,8 @@ #![allow(unknown_lints, non_local_definitions)] // TODO: remove when proptest-derive updates -use alloy_primitives::{BlockHash, BlockNumber, LogData, TxHash, TxIndex, B256}; +use alloy_primitives::{ + aliases::BlockTimestamp, BlockHash, BlockNumber, LogData, TxHash, TxIndex, B256, +}; use serde::{Deserialize, Serialize}; /// Ethereum Log emitted by a transaction @@ -23,7 +25,7 @@ pub struct Log { /// /// #[serde(skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt", default)] - pub block_timestamp: Option, + pub block_timestamp: Option, /// Transaction Hash #[doc(alias = "tx_hash")] pub transaction_hash: Option, diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 27cca08ec8d..8400261e0a3 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -6,7 +6,8 @@ use alloy_consensus::{ TxLegacy, TxType, }; use alloy_primitives::{ - Address, BlockHash, BlockNumber, Bytes, ChainId, TxHash, TxIndex, TxKind, B256, U256, + aliases::TxNonce, Address, BlockHash, BlockNumber, Bytes, ChainId, TxHash, TxIndex, TxKind, + B256, U256, }; use serde::{Deserialize, Serialize}; @@ -43,7 +44,7 @@ pub struct Transaction { pub hash: TxHash, /// Nonce #[serde(with = "alloy_serde::quantity")] - pub nonce: u64, + pub nonce: TxNonce, /// Block hash #[serde(default)] pub block_hash: Option, From f75d98bed0e5648ce3d35fd8db1c6e2ba5d8b72b Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 10 Jun 2024 18:39:25 +0200 Subject: [PATCH 07/17] fix clippy, keep impl From as is --- crates/eips/src/eip1898.rs | 18 +++++++++--------- crates/rpc-types-eth/src/account.rs | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/eips/src/eip1898.rs b/crates/eips/src/eip1898.rs index 02f53912aa2..bdfcba859f2 100644 --- a/crates/eips/src/eip1898.rs +++ b/crates/eips/src/eip1898.rs @@ -361,9 +361,9 @@ impl Default for BlockId { } } -impl From for BlockId { - fn from(num: BlockNumber) -> Self { - BlockNumberOrTag::Number(num).into() +impl From for BlockId { + fn from(block_number: u64) -> Self { + BlockNumberOrTag::Number(block_number).into() } } @@ -374,19 +374,19 @@ impl From for BlockId { } impl From for BlockId { - fn from(num: BlockNumberOrTag) -> Self { - Self::Number(num) + fn from(block_number: BlockNumberOrTag) -> Self { + Self::Number(block_number) } } -impl From for BlockId { - fn from(block_hash: BlockHash) -> Self { +impl From for BlockId { + fn from(block_hash: B256) -> Self { Self::Hash(RpcBlockHash { block_hash, require_canonical: None }) } } -impl From<(BlockHash, Option)> for BlockId { - fn from(hash_can: (BlockHash, Option)) -> Self { +impl From<(B256, Option)> for BlockId { + fn from(hash_can: (B256, Option)) -> Self { Self::Hash(RpcBlockHash { block_hash: hash_can.0, require_canonical: hash_can.1 }) } } diff --git a/crates/rpc-types-eth/src/account.rs b/crates/rpc-types-eth/src/account.rs index 75d41ab5392..a46ec8a9d9c 100644 --- a/crates/rpc-types-eth/src/account.rs +++ b/crates/rpc-types-eth/src/account.rs @@ -1,4 +1,4 @@ -use alloy_primitives::{aliases::TxNonce, Address, Bytes, B256, B512, U256, U64}; +use alloy_primitives::{aliases::TxNonce, Address, Bytes, B256, B512, U256}; use alloy_serde::storage::JsonStorageKey; use serde::{Deserialize, Serialize}; From 3637445524c0adbcdd0155df2a2cca7da0714660 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Mon, 10 Jun 2024 19:08:28 +0200 Subject: [PATCH 08/17] do not use TxNonce for EIP1186AccountProofResponse as type is expected to be U64, not u64 --- crates/rpc-types-eth/src/account.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/rpc-types-eth/src/account.rs b/crates/rpc-types-eth/src/account.rs index a46ec8a9d9c..26f6c9497ea 100644 --- a/crates/rpc-types-eth/src/account.rs +++ b/crates/rpc-types-eth/src/account.rs @@ -1,4 +1,4 @@ -use alloy_primitives::{aliases::TxNonce, Address, Bytes, B256, B512, U256}; +use alloy_primitives::{Address, Bytes, B256, B512, U256, U64}; use alloy_serde::storage::JsonStorageKey; use serde::{Deserialize, Serialize}; @@ -32,7 +32,7 @@ pub struct EIP1186AccountProofResponse { /// The hash of the code of the account. pub code_hash: B256, /// The account nonce. - pub nonce: TxNonce, + pub nonce: U64, /// The hash of the storage of the account. pub storage_hash: B256, /// The account proof. From b5dbbabb90f11e6d59687c2292533eddf71e93a7 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Tue, 11 Jun 2024 13:55:23 +0200 Subject: [PATCH 09/17] avoid aliasing for genesis as it is often read from file and rarely interacted with dynamically --- crates/genesis/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/genesis/src/lib.rs b/crates/genesis/src/lib.rs index f9abaf27e85..b308e40097d 100644 --- a/crates/genesis/src/lib.rs +++ b/crates/genesis/src/lib.rs @@ -12,7 +12,7 @@ extern crate alloc; use alloc::{collections::BTreeMap, string::String}; -use alloy_primitives::{aliases::BlockTimestamp, Address, BlockNumber, Bytes, ChainId, B256, U256}; +use alloy_primitives::{Address, Bytes, ChainId, B256, U256}; use alloy_serde::{storage::deserialize_storage_map, ttd::deserialize_json_ttd_opt}; use serde::{Deserialize, Serialize}; @@ -28,7 +28,7 @@ pub struct Genesis { pub nonce: u64, /// The genesis header timestamp. #[serde(with = "alloy_serde::quantity")] - pub timestamp: BlockTimestamp, + pub timestamp: u64, /// The genesis header extra data. pub extra_data: Bytes, /// The genesis header gas limit. @@ -60,7 +60,7 @@ pub struct Genesis { pub blob_gas_used: Option, /// The genesis block number #[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")] - pub number: Option, + pub number: Option, } impl Genesis { @@ -68,7 +68,7 @@ impl Genesis { /// and funds the given address with max coins. /// /// Enables all hard forks up to London at genesis. - pub fn clique_genesis(chain_id: ChainId, signer_addr: Address) -> Self { + pub fn clique_genesis(chain_id: u64, signer_addr: Address) -> Self { // set up a clique config with an instant sealing period and short (8 block) epoch let clique_config = CliqueConfig { period: Some(0), epoch: Some(8) }; @@ -262,7 +262,7 @@ impl GenesisAccount { pub struct ChainConfig { /// The network's chain ID. #[serde(default = "mainnet_id")] - pub chain_id: ChainId, + pub chain_id: u64, /// The homestead switch block (None = no fork, 0 = already homestead). #[serde( From 3b6c6ce2483a6d8aac60922deb766e7a29759609 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Tue, 11 Jun 2024 13:56:59 +0200 Subject: [PATCH 10/17] fix clippy --- crates/genesis/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/genesis/src/lib.rs b/crates/genesis/src/lib.rs index b308e40097d..6ed8e91f482 100644 --- a/crates/genesis/src/lib.rs +++ b/crates/genesis/src/lib.rs @@ -12,7 +12,7 @@ extern crate alloc; use alloc::{collections::BTreeMap, string::String}; -use alloy_primitives::{Address, Bytes, ChainId, B256, U256}; +use alloy_primitives::{Address, Bytes, B256, U256}; use alloy_serde::{storage::deserialize_storage_map, ttd::deserialize_json_ttd_opt}; use serde::{Deserialize, Serialize}; From 06c3960dbd5a902fef0e05050888fea8dd6947f7 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Tue, 11 Jun 2024 16:08:20 +0200 Subject: [PATCH 11/17] revert consensus, engine related type changes --- crates/rpc-types-beacon/src/relay.rs | 18 +++++++++--------- crates/rpc-types-engine/src/payload.rs | 8 +++----- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/crates/rpc-types-beacon/src/relay.rs b/crates/rpc-types-beacon/src/relay.rs index c09aa153088..209eeca337a 100644 --- a/crates/rpc-types-beacon/src/relay.rs +++ b/crates/rpc-types-beacon/src/relay.rs @@ -3,7 +3,7 @@ //! See also use crate::{BlsPublicKey, BlsSignature}; -use alloy_primitives::{Address, BlockHash, BlockNumber, B256, U256}; +use alloy_primitives::{Address, B256, U256}; use alloy_rpc_types_engine::{ BlobsBundleV1, ExecutionPayload, ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3, }; @@ -66,7 +66,7 @@ pub struct BidTrace { /// The parent hash of the block. pub parent_hash: B256, /// The hash of the block. - pub block_hash: BlockHash, + pub block_hash: B256, /// The public key of the builder. pub builder_pubkey: BlsPublicKey, /// The public key of the proposer. @@ -189,10 +189,10 @@ pub struct ProposerPayloadsDeliveredQuery { pub limit: Option, /// Search for a specific blockhash #[serde(skip_serializing_if = "Option::is_none")] - pub block_hash: Option, + pub block_hash: Option, /// Search for a specific EL block number #[serde(skip_serializing_if = "Option::is_none")] - pub block_number: Option, + pub block_number: Option, /// Filter results by a proposer public key #[serde(skip_serializing_if = "Option::is_none")] pub proposer_pubkey: Option, @@ -218,7 +218,7 @@ impl ProposerPayloadsDeliveredQuery { } /// Sets the specific blockhash - pub const fn block_hash(mut self, block_hash: BlockHash) -> Self { + pub const fn block_hash(mut self, block_hash: B256) -> Self { self.block_hash = Some(block_hash); self } @@ -288,7 +288,7 @@ pub struct BuilderBlocksReceivedQuery { pub limit: Option, /// Search for a specific blockhash #[serde(skip_serializing_if = "Option::is_none")] - pub block_hash: Option, + pub block_hash: Option, /// Search for a specific EL block number #[serde(skip_serializing_if = "Option::is_none")] pub block_number: Option, @@ -311,7 +311,7 @@ impl BuilderBlocksReceivedQuery { } /// Sets the specific blockhash - pub const fn block_hash(mut self, block_hash: BlockHash) -> Self { + pub const fn block_hash(mut self, block_hash: B256) -> Self { self.block_hash = Some(block_hash); self } @@ -349,9 +349,9 @@ pub mod error { #[error("incorrect BlockHash {actual}, expected {expected}")] IncorrectBlockHash { /// The expected block hash - expected: BlockHash, + expected: B256, /// The actual block hash - actual: BlockHash, + actual: B256, }, /// Thrown if block hash mismatches #[error("incorrect GasLimit {actual}, expected {expected}")] diff --git a/crates/rpc-types-engine/src/payload.rs b/crates/rpc-types-engine/src/payload.rs index 276177a4410..b9f3248f4e5 100644 --- a/crates/rpc-types-engine/src/payload.rs +++ b/crates/rpc-types-engine/src/payload.rs @@ -1,9 +1,7 @@ //! Payload types. use alloy_consensus::{Blob, Bytes48}; use alloy_eips::{eip6110::DepositRequest, eip7002::WithdrawalRequest}; -use alloy_primitives::{ - aliases::BlockTimestamp, Address, BlockNumber, Bloom, Bytes, B256, B64, U256, -}; +use alloy_primitives::{Address, Bloom, Bytes, B256, B64, U256}; use alloy_rpc_types_eth::{transaction::BlobTransactionSidecar, Withdrawal}; use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer}; use std::fmt; @@ -158,7 +156,7 @@ pub struct ExecutionPayloadV1 { pub prev_randao: B256, /// The block number. #[serde(with = "alloy_serde::quantity")] - pub block_number: BlockNumber, + pub block_number: u64, /// The gas limit of the block. #[serde(with = "alloy_serde::quantity")] pub gas_limit: u64, @@ -167,7 +165,7 @@ pub struct ExecutionPayloadV1 { pub gas_used: u64, /// The timestamp of the block. #[serde(with = "alloy_serde::quantity")] - pub timestamp: BlockTimestamp, + pub timestamp: u64, /// The extra data of the block. pub extra_data: Bytes, /// The base fee per gas of the block. From 8bbf462468f4e654f5e21579ddb998cc4c2756dd Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Tue, 11 Jun 2024 16:18:37 +0200 Subject: [PATCH 12/17] prefer import types as long as they do not clash --- crates/consensus/src/receipt/receipts.rs | 7 ++----- crates/consensus/src/transaction/typed.rs | 4 ++-- crates/network/src/any/builder.rs | 20 ++++++++++---------- crates/network/src/transaction/builder.rs | 2 +- crates/rpc-types-eth/src/log.rs | 4 ++-- crates/serde/src/lib.rs | 4 ++-- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/crates/consensus/src/receipt/receipts.rs b/crates/consensus/src/receipt/receipts.rs index f57e648c3e4..64963ae4578 100644 --- a/crates/consensus/src/receipt/receipts.rs +++ b/crates/consensus/src/receipt/receipts.rs @@ -1,5 +1,5 @@ use crate::receipt::{Eip658Value, TxReceipt}; -use alloy_primitives::{Bloom, Log}; +use alloy_primitives::{Bloom, Log, U128}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable}; use core::borrow::Borrow; @@ -43,10 +43,7 @@ where let key = if self.status.is_eip658() { "status" } else { "root" }; s.serialize_field(key, &self.status)?; - s.serialize_field( - "cumulativeGasUsed", - &alloy_primitives::U128::from(self.cumulative_gas_used), - )?; + s.serialize_field("cumulativeGasUsed", &U128::from(self.cumulative_gas_used))?; s.serialize_field("logs", &self.logs)?; s.end() diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index 1e1408e052b..d7f12d50f85 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -2,7 +2,7 @@ use crate::{ transaction::eip4844::{TxEip4844, TxEip4844Variant, TxEip4844WithSidecar}, Transaction, TxEip1559, TxEip2930, TxEnvelope, TxLegacy, TxType, }; -use alloy_primitives::{aliases::TxNonce, TxKind}; +use alloy_primitives::{aliases::TxNonce, ChainId, TxKind}; /// The TypedTransaction enum represents all Ethereum transaction request types. /// @@ -115,7 +115,7 @@ impl TypedTransaction { } impl Transaction for TypedTransaction { - fn chain_id(&self) -> Option { + fn chain_id(&self) -> Option { match self { Self::Legacy(tx) => tx.chain_id(), Self::Eip2930(tx) => tx.chain_id(), diff --git a/crates/network/src/any/builder.rs b/crates/network/src/any/builder.rs index 53542bcc2f1..bc3640a53dc 100644 --- a/crates/network/src/any/builder.rs +++ b/crates/network/src/any/builder.rs @@ -1,17 +1,17 @@ use std::ops::{Deref, DerefMut}; use alloy_consensus::BlobTransactionSidecar; -use alloy_primitives::{aliases::TxNonce, Bytes}; +use alloy_primitives::{aliases::TxNonce, Address, Bytes, ChainId, TxKind, U256}; use alloy_rpc_types_eth::{AccessList, TransactionRequest, WithOtherFields}; use crate::{any::AnyNetwork, BuildResult, Network, TransactionBuilder, TransactionBuilderError}; impl TransactionBuilder for WithOtherFields { - fn chain_id(&self) -> Option { + fn chain_id(&self) -> Option { self.deref().chain_id() } - fn set_chain_id(&mut self, chain_id: alloy_primitives::ChainId) { + fn set_chain_id(&mut self, chain_id: ChainId) { self.deref_mut().set_chain_id(chain_id) } @@ -23,7 +23,7 @@ impl TransactionBuilder for WithOtherFields { self.deref_mut().set_nonce(nonce) } - fn input(&self) -> Option<&alloy_primitives::Bytes> { + fn input(&self) -> Option<&Bytes> { self.deref().input() } @@ -31,15 +31,15 @@ impl TransactionBuilder for WithOtherFields { self.deref_mut().set_input(input); } - fn from(&self) -> Option { + fn from(&self) -> Option
{ self.deref().from() } - fn set_from(&mut self, from: alloy_primitives::Address) { + fn set_from(&mut self, from: Address) { self.deref_mut().set_from(from); } - fn kind(&self) -> Option { + fn kind(&self) -> Option { self.deref().kind() } @@ -47,15 +47,15 @@ impl TransactionBuilder for WithOtherFields { self.deref_mut().clear_kind() } - fn set_kind(&mut self, kind: alloy_primitives::TxKind) { + fn set_kind(&mut self, kind: TxKind) { self.deref_mut().set_kind(kind) } - fn value(&self) -> Option { + fn value(&self) -> Option { self.deref().value() } - fn set_value(&mut self, value: alloy_primitives::U256) { + fn set_value(&mut self, value: U256) { self.deref_mut().set_value(value) } diff --git a/crates/network/src/transaction/builder.rs b/crates/network/src/transaction/builder.rs index 7ddf71c28b5..9700080f34b 100644 --- a/crates/network/src/transaction/builder.rs +++ b/crates/network/src/transaction/builder.rs @@ -59,7 +59,7 @@ pub trait TransactionBuilder: Default + Sized + Send + Sync + 'stati fn set_chain_id(&mut self, chain_id: ChainId); /// Builder-pattern method for setting the chain ID. - fn with_chain_id(mut self, chain_id: alloy_primitives::ChainId) -> Self { + fn with_chain_id(mut self, chain_id: ChainId) -> Self { self.set_chain_id(chain_id); self } diff --git a/crates/rpc-types-eth/src/log.rs b/crates/rpc-types-eth/src/log.rs index a24dcd4b494..4ce6b5f93cf 100644 --- a/crates/rpc-types-eth/src/log.rs +++ b/crates/rpc-types-eth/src/log.rs @@ -1,7 +1,7 @@ #![allow(unknown_lints, non_local_definitions)] // TODO: remove when proptest-derive updates use alloy_primitives::{ - aliases::BlockTimestamp, BlockHash, BlockNumber, LogData, TxHash, TxIndex, B256, + aliases::BlockTimestamp, Address, BlockHash, BlockNumber, LogData, TxHash, TxIndex, B256, }; use serde::{Deserialize, Serialize}; @@ -43,7 +43,7 @@ pub struct Log { impl Log { /// Getter for the address field. Shortcut for `log.inner.address`. - pub const fn address(&self) -> alloy_primitives::Address { + pub const fn address(&self) -> Address { self.inner.address } diff --git a/crates/serde/src/lib.rs b/crates/serde/src/lib.rs index 0ab720f4df0..9a7f17ec900 100644 --- a/crates/serde/src/lib.rs +++ b/crates/serde/src/lib.rs @@ -33,7 +33,7 @@ pub use ttd::*; use alloc::format; use serde::Serializer; -use alloy_primitives::B256; +use alloy_primitives::{hex, B256}; /// Serialize a byte vec as a hex string _without_ the "0x" prefix. /// @@ -43,7 +43,7 @@ where S: Serializer, T: AsRef<[u8]>, { - s.serialize_str(&alloy_primitives::hex::encode(x.as_ref())) + s.serialize_str(&hex::encode(x.as_ref())) } /// Serialize a [B256] as a hex string _without_ the "0x" prefix. From 2e50473551e603e2c29a0bb13fddd61bcdbbe6b2 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Tue, 11 Jun 2024 16:52:37 +0200 Subject: [PATCH 13/17] fix docs link --- crates/serde/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/serde/src/lib.rs b/crates/serde/src/lib.rs index 9a7f17ec900..11e98f54706 100644 --- a/crates/serde/src/lib.rs +++ b/crates/serde/src/lib.rs @@ -37,7 +37,7 @@ use alloy_primitives::{hex, B256}; /// Serialize a byte vec as a hex string _without_ the "0x" prefix. /// -/// This behaves the same as [`hex::encode`](alloy_primitives::hex::encode). +/// This behaves the same as [`hex::encode`]. pub fn serialize_hex_string_no_prefix(x: T, s: S) -> Result where S: Serializer, From 71c14ebf915e0c5c156182376c757203bcacc9ee Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Tue, 11 Jun 2024 19:31:05 +0200 Subject: [PATCH 14/17] do not use TxNonce and BlockTimestamp aliases --- crates/consensus/src/transaction/eip1559.rs | 8 ++++---- crates/consensus/src/transaction/eip2930.rs | 8 ++++---- crates/consensus/src/transaction/eip4844.rs | 14 ++++++-------- crates/consensus/src/transaction/legacy.rs | 4 ++-- crates/consensus/src/transaction/mod.rs | 4 ++-- crates/consensus/src/transaction/typed.rs | 4 ++-- crates/network/src/any/builder.rs | 6 +++--- crates/network/src/ethereum/builder.rs | 6 +++--- crates/network/src/transaction/builder.rs | 8 ++++---- crates/provider/src/ext/anvil.rs | 9 +++------ crates/rpc-types-anvil/src/lib.rs | 10 ++++------ crates/rpc-types-eth/src/block.rs | 6 ++---- crates/rpc-types-eth/src/log.rs | 6 ++---- crates/rpc-types-eth/src/transaction/mod.rs | 5 ++--- 14 files changed, 43 insertions(+), 55 deletions(-) diff --git a/crates/consensus/src/transaction/eip1559.rs b/crates/consensus/src/transaction/eip1559.rs index f1d54fc7603..585f14bfa2b 100644 --- a/crates/consensus/src/transaction/eip1559.rs +++ b/crates/consensus/src/transaction/eip1559.rs @@ -1,6 +1,6 @@ use crate::{SignableTransaction, Signed, Transaction, TxType}; use alloy_eips::eip2930::AccessList; -use alloy_primitives::{aliases::TxNonce, keccak256, Bytes, ChainId, Signature, TxKind, U256}; +use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, U256}; use alloy_rlp::{BufMut, Decodable, Encodable, Header}; use core::mem; @@ -18,7 +18,7 @@ pub struct TxEip1559 { 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::quantity"))] - pub nonce: TxNonce, + 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 @@ -249,7 +249,7 @@ impl TxEip1559 { #[inline] pub fn size(&self) -> usize { mem::size_of::() + // chain_id - mem::size_of::() + // nonce + mem::size_of::() + // nonce mem::size_of::() + // gas_limit mem::size_of::() + // max_fee_per_gas mem::size_of::() + // max_priority_fee_per_gas @@ -265,7 +265,7 @@ impl Transaction for TxEip1559 { Some(self.chain_id) } - fn nonce(&self) -> TxNonce { + fn nonce(&self) -> u64 { self.nonce } diff --git a/crates/consensus/src/transaction/eip2930.rs b/crates/consensus/src/transaction/eip2930.rs index 666dbcbb207..8ae2a111098 100644 --- a/crates/consensus/src/transaction/eip2930.rs +++ b/crates/consensus/src/transaction/eip2930.rs @@ -1,6 +1,6 @@ use crate::{SignableTransaction, Signed, Transaction, TxType}; use alloy_eips::eip2930::AccessList; -use alloy_primitives::{aliases::TxNonce, keccak256, Bytes, ChainId, Signature, TxKind, U256}; +use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header}; use core::mem; @@ -18,7 +18,7 @@ pub struct TxEip2930 { 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::quantity"))] - pub nonce: TxNonce, + pub nonce: u64, /// A scalar value equal to the number of /// Wei to be paid per unit of gas for all computation /// costs incurred as a result of the execution of this transaction; formally Tp. @@ -63,7 +63,7 @@ impl TxEip2930 { #[inline] pub fn size(&self) -> usize { mem::size_of::() + // chain_id - mem::size_of::() + // nonce + mem::size_of::() + // nonce mem::size_of::() + // gas_price mem::size_of::() + // gas_limit self.to.size() + // to @@ -229,7 +229,7 @@ impl Transaction for TxEip2930 { Some(self.chain_id) } - fn nonce(&self) -> TxNonce { + fn nonce(&self) -> u64 { self.nonce } diff --git a/crates/consensus/src/transaction/eip4844.rs b/crates/consensus/src/transaction/eip4844.rs index 2f8cfa330ae..f93273314cb 100644 --- a/crates/consensus/src/transaction/eip4844.rs +++ b/crates/consensus/src/transaction/eip4844.rs @@ -1,9 +1,7 @@ use crate::{SignableTransaction, Signed, Transaction, TxType}; use alloy_eips::{eip2930::AccessList, eip4844::DATA_GAS_PER_BLOB}; -use alloy_primitives::{ - aliases::TxNonce, keccak256, Address, Bytes, ChainId, Signature, TxKind, B256, U256, -}; +use alloy_primitives::{keccak256, Address, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header}; use core::mem; @@ -219,7 +217,7 @@ impl Transaction for TxEip4844Variant { } } - fn nonce(&self) -> TxNonce { + fn nonce(&self) -> u64 { match self { Self::TxEip4844(tx) => tx.nonce, Self::TxEip4844WithSidecar(tx) => tx.tx().nonce, @@ -296,7 +294,7 @@ pub struct TxEip4844 { 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::quantity"))] - pub nonce: TxNonce, + 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 @@ -474,7 +472,7 @@ impl TxEip4844 { #[inline] pub fn size(&self) -> usize { mem::size_of::() + // chain_id - mem::size_of::() + // nonce + mem::size_of::() + // nonce mem::size_of::() + // gas_limit mem::size_of::() + // max_fee_per_gas mem::size_of::() + // max_priority_fee_per_gas @@ -647,7 +645,7 @@ impl Transaction for TxEip4844 { Some(self.chain_id) } - fn nonce(&self) -> TxNonce { + fn nonce(&self) -> u64 { self.nonce } @@ -870,7 +868,7 @@ impl Transaction for TxEip4844WithSidecar { self.tx.chain_id() } - fn nonce(&self) -> TxNonce { + fn nonce(&self) -> u64 { self.tx.nonce() } diff --git a/crates/consensus/src/transaction/legacy.rs b/crates/consensus/src/transaction/legacy.rs index 8921ba58bc0..c39abfbf186 100644 --- a/crates/consensus/src/transaction/legacy.rs +++ b/crates/consensus/src/transaction/legacy.rs @@ -1,5 +1,5 @@ use crate::{SignableTransaction, Signed, Transaction}; -use alloy_primitives::{aliases::TxNonce, keccak256, Bytes, ChainId, Signature, TxKind, U256}; +use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, U256}; use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header, Result}; use core::mem; @@ -202,7 +202,7 @@ impl Transaction for TxLegacy { self.chain_id } - fn nonce(&self) -> TxNonce { + fn nonce(&self) -> u64 { self.nonce } diff --git a/crates/consensus/src/transaction/mod.rs b/crates/consensus/src/transaction/mod.rs index c1165aa991d..ab8237346a7 100644 --- a/crates/consensus/src/transaction/mod.rs +++ b/crates/consensus/src/transaction/mod.rs @@ -1,7 +1,7 @@ //! Transaction types. use crate::Signed; -use alloy_primitives::{aliases::TxNonce, keccak256, ChainId, TxKind, B256, U256}; +use alloy_primitives::{keccak256, ChainId, TxKind, B256, U256}; use core::any; #[cfg(not(feature = "std"))] @@ -40,7 +40,7 @@ pub trait Transaction: any::Any + Send + Sync + 'static { fn chain_id(&self) -> Option; /// Get `nonce`. - fn nonce(&self) -> TxNonce; + fn nonce(&self) -> u64; /// Get `gas_limit`. fn gas_limit(&self) -> u128; diff --git a/crates/consensus/src/transaction/typed.rs b/crates/consensus/src/transaction/typed.rs index d7f12d50f85..462575378b5 100644 --- a/crates/consensus/src/transaction/typed.rs +++ b/crates/consensus/src/transaction/typed.rs @@ -2,7 +2,7 @@ use crate::{ transaction::eip4844::{TxEip4844, TxEip4844Variant, TxEip4844WithSidecar}, Transaction, TxEip1559, TxEip2930, TxEnvelope, TxLegacy, TxType, }; -use alloy_primitives::{aliases::TxNonce, ChainId, TxKind}; +use alloy_primitives::{ChainId, TxKind}; /// The TypedTransaction enum represents all Ethereum transaction request types. /// @@ -151,7 +151,7 @@ impl Transaction for TypedTransaction { } } - fn nonce(&self) -> TxNonce { + fn nonce(&self) -> u64 { match self { Self::Legacy(tx) => tx.nonce(), Self::Eip2930(tx) => tx.nonce(), diff --git a/crates/network/src/any/builder.rs b/crates/network/src/any/builder.rs index bc3640a53dc..a40eb94cf51 100644 --- a/crates/network/src/any/builder.rs +++ b/crates/network/src/any/builder.rs @@ -1,7 +1,7 @@ use std::ops::{Deref, DerefMut}; use alloy_consensus::BlobTransactionSidecar; -use alloy_primitives::{aliases::TxNonce, Address, Bytes, ChainId, TxKind, U256}; +use alloy_primitives::{Address, Bytes, ChainId, TxKind, U256}; use alloy_rpc_types_eth::{AccessList, TransactionRequest, WithOtherFields}; use crate::{any::AnyNetwork, BuildResult, Network, TransactionBuilder, TransactionBuilderError}; @@ -15,11 +15,11 @@ impl TransactionBuilder for WithOtherFields { self.deref_mut().set_chain_id(chain_id) } - fn nonce(&self) -> Option { + fn nonce(&self) -> Option { self.deref().nonce() } - fn set_nonce(&mut self, nonce: TxNonce) { + fn set_nonce(&mut self, nonce: u64) { self.deref_mut().set_nonce(nonce) } diff --git a/crates/network/src/ethereum/builder.rs b/crates/network/src/ethereum/builder.rs index c5bc3d98949..74913e957e7 100644 --- a/crates/network/src/ethereum/builder.rs +++ b/crates/network/src/ethereum/builder.rs @@ -2,7 +2,7 @@ use crate::{ BuildResult, Ethereum, Network, NetworkSigner, TransactionBuilder, TransactionBuilderError, }; use alloy_consensus::{BlobTransactionSidecar, TxType, TypedTransaction}; -use alloy_primitives::{aliases::TxNonce, Address, Bytes, ChainId, TxKind, U256}; +use alloy_primitives::{Address, Bytes, ChainId, TxKind, U256}; use alloy_rpc_types_eth::{request::TransactionRequest, AccessList}; impl TransactionBuilder for TransactionRequest { @@ -14,11 +14,11 @@ impl TransactionBuilder for TransactionRequest { self.chain_id = Some(chain_id); } - fn nonce(&self) -> Option { + fn nonce(&self) -> Option { self.nonce } - fn set_nonce(&mut self, nonce: TxNonce) { + fn set_nonce(&mut self, nonce: u64) { self.nonce = Some(nonce); } diff --git a/crates/network/src/transaction/builder.rs b/crates/network/src/transaction/builder.rs index 9700080f34b..a18ccc4bda9 100644 --- a/crates/network/src/transaction/builder.rs +++ b/crates/network/src/transaction/builder.rs @@ -1,7 +1,7 @@ use super::signer::NetworkSigner; use crate::Network; use alloy_consensus::BlobTransactionSidecar; -use alloy_primitives::{aliases::TxNonce, Address, Bytes, ChainId, TxKind, U256}; +use alloy_primitives::{Address, Bytes, ChainId, TxKind, U256}; use alloy_rpc_types_eth::AccessList; use alloy_sol_types::SolCall; use futures_utils_wasm::impl_future; @@ -65,13 +65,13 @@ pub trait TransactionBuilder: Default + Sized + Send + Sync + 'stati } /// Get the nonce for the transaction. - fn nonce(&self) -> Option; + fn nonce(&self) -> Option; /// Set the nonce for the transaction. - fn set_nonce(&mut self, nonce: TxNonce); + fn set_nonce(&mut self, nonce: u64); /// Builder-pattern method for setting the nonce. - fn with_nonce(mut self, nonce: TxNonce) -> Self { + fn with_nonce(mut self, nonce: u64) -> Self { self.set_nonce(nonce); self } diff --git a/crates/provider/src/ext/anvil.rs b/crates/provider/src/ext/anvil.rs index f47ab28777e..4dabf00bf22 100644 --- a/crates/provider/src/ext/anvil.rs +++ b/crates/provider/src/ext/anvil.rs @@ -1,7 +1,7 @@ //! This module extends the Ethereum JSON-RPC provider with the Anvil namespace's RPC methods. use crate::Provider; use alloy_network::Network; -use alloy_primitives::{aliases::BlockTimestamp, Address, Bytes, TxHash, B256, U256}; +use alloy_primitives::{Address, Bytes, TxHash, B256, U256}; use alloy_rpc_types_anvil::{Forking, Metadata, MineOptions, NodeInfo}; use alloy_rpc_types_eth::{Block, TransactionRequest, WithOtherFields}; use alloy_transport::{Transport, TransportResult}; @@ -111,14 +111,11 @@ pub trait AnvilApi: Send + Sync { async fn anvil_increase_time(&self, seconds: U256) -> TransportResult; /// Similar to `evm_increaseTime` but takes the exact timestamp that you want in the next block. - async fn anvil_set_next_block_timestamp( - &self, - timestamp: BlockTimestamp, - ) -> TransportResult<()>; + async fn anvil_set_next_block_timestamp(&self, timestamp: u64) -> TransportResult<()>; /// Sets the specific timestamp and returns the number of seconds between the given timestamp /// and the current time. - async fn anvil_set_time(&self, timestamp: BlockTimestamp) -> TransportResult; + async fn anvil_set_time(&self, timestamp: u64) -> TransportResult; /// Set the next block gas limit. async fn anvil_set_block_gas_limit(&self, gas_limit: U256) -> TransportResult; diff --git a/crates/rpc-types-anvil/src/lib.rs b/crates/rpc-types-anvil/src/lib.rs index e01b67ffa58..093a2d648aa 100644 --- a/crates/rpc-types-anvil/src/lib.rs +++ b/crates/rpc-types-anvil/src/lib.rs @@ -6,9 +6,7 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -use alloy_primitives::{ - aliases::BlockTimestamp, BlockHash, BlockNumber, ChainId, TxHash, B256, U256, -}; +use alloy_primitives::{BlockHash, BlockNumber, ChainId, TxHash, B256, U256}; use serde::{Deserialize, Deserializer, Serialize}; use std::collections::BTreeMap; @@ -67,7 +65,7 @@ pub struct NodeInfo { #[serde(with = "alloy_serde::quantity")] pub current_block_number: BlockNumber, /// The current block timestamp - pub current_block_timestamp: BlockTimestamp, + pub current_block_timestamp: u64, /// The current block hash pub current_block_hash: BlockHash, /// The enabled hardfork @@ -150,14 +148,14 @@ pub enum MineOptions { Options { /// The timestamp the block should be mined with #[serde(with = "alloy_serde::quantity::opt")] - timestamp: Option, + timestamp: Option, /// If `blocks` is given, it will mine exactly blocks number of blocks, regardless of any /// other blocks mined or reverted during it's operation blocks: Option, }, /// The timestamp the block should be mined with #[serde(with = "alloy_serde::quantity::opt")] - Timestamp(Option), + Timestamp(Option), } impl Default for MineOptions { diff --git a/crates/rpc-types-eth/src/block.rs b/crates/rpc-types-eth/src/block.rs index 802ecf3cf6e..a73ac274200 100644 --- a/crates/rpc-types-eth/src/block.rs +++ b/crates/rpc-types-eth/src/block.rs @@ -5,9 +5,7 @@ pub use alloy_eips::{ calc_blob_gasprice, calc_excess_blob_gas, BlockHashOrNumber, BlockId, BlockNumHash, BlockNumberOrTag, ForkBlock, RpcBlockHash, }; -use alloy_primitives::{ - aliases::BlockTimestamp, Address, BlockHash, BlockNumber, Bloom, Bytes, B256, B64, U256, U64, -}; +use alloy_primitives::{Address, BlockHash, BlockNumber, Bloom, Bytes, B256, B64, U256, U64}; use serde::{ser::Error, Deserialize, Serialize, Serializer}; use std::{collections::BTreeMap, ops::Deref}; @@ -81,7 +79,7 @@ pub struct Header { pub gas_used: u128, /// Timestamp #[serde(default, with = "alloy_serde::quantity")] - pub timestamp: BlockTimestamp, + pub timestamp: u64, /// Total difficulty #[serde(default, skip_serializing_if = "Option::is_none")] pub total_difficulty: Option, diff --git a/crates/rpc-types-eth/src/log.rs b/crates/rpc-types-eth/src/log.rs index 4ce6b5f93cf..b1a7212a62c 100644 --- a/crates/rpc-types-eth/src/log.rs +++ b/crates/rpc-types-eth/src/log.rs @@ -1,8 +1,6 @@ #![allow(unknown_lints, non_local_definitions)] // TODO: remove when proptest-derive updates -use alloy_primitives::{ - aliases::BlockTimestamp, Address, BlockHash, BlockNumber, LogData, TxHash, TxIndex, B256, -}; +use alloy_primitives::{Address, BlockHash, BlockNumber, LogData, TxHash, TxIndex, B256}; use serde::{Deserialize, Serialize}; /// Ethereum Log emitted by a transaction @@ -25,7 +23,7 @@ pub struct Log { /// /// #[serde(skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt", default)] - pub block_timestamp: Option, + pub block_timestamp: Option, /// Transaction Hash #[doc(alias = "tx_hash")] pub transaction_hash: Option, diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 8400261e0a3..27cca08ec8d 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -6,8 +6,7 @@ use alloy_consensus::{ TxLegacy, TxType, }; use alloy_primitives::{ - aliases::TxNonce, Address, BlockHash, BlockNumber, Bytes, ChainId, TxHash, TxIndex, TxKind, - B256, U256, + Address, BlockHash, BlockNumber, Bytes, ChainId, TxHash, TxIndex, TxKind, B256, U256, }; use serde::{Deserialize, Serialize}; @@ -44,7 +43,7 @@ pub struct Transaction { pub hash: TxHash, /// Nonce #[serde(with = "alloy_serde::quantity")] - pub nonce: TxNonce, + pub nonce: u64, /// Block hash #[serde(default)] pub block_hash: Option, From 24b40a8f51b66e2785ee195179cb95c86d87ce8f Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Tue, 11 Jun 2024 19:36:43 +0200 Subject: [PATCH 15/17] rule: alias for hash types, not number types --- crates/node-bindings/src/anvil.rs | 4 ++-- crates/rpc-types-anvil/src/lib.rs | 14 +++++++------- crates/rpc-types-eth/src/log.rs | 4 ++-- crates/rpc-types-eth/src/transaction/common.rs | 4 ++-- crates/rpc-types-eth/src/transaction/mod.rs | 6 ++---- crates/rpc-types-eth/src/transaction/receipt.rs | 4 ++-- crates/rpc-types-trace/src/parity.rs | 4 ++-- 7 files changed, 19 insertions(+), 21 deletions(-) diff --git a/crates/node-bindings/src/anvil.rs b/crates/node-bindings/src/anvil.rs index 68c0bcf9fe8..0928957203c 100644 --- a/crates/node-bindings/src/anvil.rs +++ b/crates/node-bindings/src/anvil.rs @@ -1,6 +1,6 @@ //! Utilities for launching an Anvil instance. -use alloy_primitives::{hex, Address, BlockNumber, ChainId}; +use alloy_primitives::{hex, Address, ChainId}; use k256::{ecdsa::SigningKey, SecretKey as K256SecretKey}; use std::{ io::{BufRead, BufReader}, @@ -153,7 +153,7 @@ pub struct Anvil { chain_id: Option, mnemonic: Option, fork: Option, - fork_block_number: Option, + fork_block_number: Option, args: Vec, timeout: Option, } diff --git a/crates/rpc-types-anvil/src/lib.rs b/crates/rpc-types-anvil/src/lib.rs index 093a2d648aa..02469f2d363 100644 --- a/crates/rpc-types-anvil/src/lib.rs +++ b/crates/rpc-types-anvil/src/lib.rs @@ -6,7 +6,7 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -use alloy_primitives::{BlockHash, BlockNumber, ChainId, TxHash, B256, U256}; +use alloy_primitives::{BlockHash, ChainId, TxHash, B256, U256}; use serde::{Deserialize, Deserializer, Serialize}; use std::collections::BTreeMap; @@ -19,7 +19,7 @@ pub struct Forking { /// The URL of the JSON-RPC endpoint to fork from. pub json_rpc_url: Option, /// The block number to fork from. - pub block_number: Option, + pub block_number: Option, } impl<'de> serde::Deserialize<'de> for Forking { @@ -32,7 +32,7 @@ impl<'de> serde::Deserialize<'de> for Forking { struct ForkOpts { json_rpc_url: Option, #[serde(default, with = "alloy_serde::quantity::opt")] - block_number: Option, + block_number: Option, } #[derive(serde::Deserialize)] @@ -63,7 +63,7 @@ impl<'de> serde::Deserialize<'de> for Forking { pub struct NodeInfo { /// The current block number #[serde(with = "alloy_serde::quantity")] - pub current_block_number: BlockNumber, + pub current_block_number: u64, /// The current block timestamp pub current_block_timestamp: u64, /// The current block hash @@ -100,7 +100,7 @@ pub struct NodeForkConfig { /// URL of the forked network pub fork_url: Option, /// Block number of the forked network - pub fork_block_number: Option, + pub fork_block_number: Option, /// Retry backoff for requests pub fork_retry_backoff: Option, } @@ -118,7 +118,7 @@ pub struct Metadata { /// Unique instance id pub instance_id: B256, /// Latest block number - pub latest_block_number: BlockNumber, + pub latest_block_number: u64, /// Latest block hash pub latest_block_hash: BlockHash, /// Forked network info @@ -135,7 +135,7 @@ pub struct ForkedNetwork { /// Chain id of the node. pub chain_id: ChainId, /// Block number of the forked chain - pub fork_block_number: BlockNumber, + pub fork_block_number: u64, /// Block hash of the forked chain pub fork_block_hash: TxHash, } diff --git a/crates/rpc-types-eth/src/log.rs b/crates/rpc-types-eth/src/log.rs index b1a7212a62c..b1ede6e77a4 100644 --- a/crates/rpc-types-eth/src/log.rs +++ b/crates/rpc-types-eth/src/log.rs @@ -1,6 +1,6 @@ #![allow(unknown_lints, non_local_definitions)] // TODO: remove when proptest-derive updates -use alloy_primitives::{Address, BlockHash, BlockNumber, LogData, TxHash, TxIndex, B256}; +use alloy_primitives::{Address, BlockHash, LogData, TxHash, TxIndex, B256}; use serde::{Deserialize, Serialize}; /// Ethereum Log emitted by a transaction @@ -18,7 +18,7 @@ pub struct Log { pub block_hash: Option, /// Number of the block the transaction that emitted this log was mined in #[serde(with = "alloy_serde::quantity::opt")] - pub block_number: Option, + pub block_number: Option, /// The timestamp of the block as proposed in: /// /// diff --git a/crates/rpc-types-eth/src/transaction/common.rs b/crates/rpc-types-eth/src/transaction/common.rs index a50d5c3dd83..a9b02d2849d 100644 --- a/crates/rpc-types-eth/src/transaction/common.rs +++ b/crates/rpc-types-eth/src/transaction/common.rs @@ -2,7 +2,7 @@ //! when working with RPC types, such as [Transaction] use crate::Transaction; -use alloy_primitives::{BlockHash, BlockNumber, TxHash, TxIndex}; +use alloy_primitives::{BlockHash, TxHash, TxIndex}; /// Additional fields in the context of a block that contains this transaction. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] @@ -15,7 +15,7 @@ pub struct TransactionInfo { /// Hash of the block. pub block_hash: Option, /// Number of the block. - pub block_number: Option, + pub block_number: Option, /// Base fee of the block. pub base_fee: Option, } diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 27cca08ec8d..64190e02975 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -5,9 +5,7 @@ use alloy_consensus::{ SignableTransaction, Signed, TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, TxEnvelope, TxLegacy, TxType, }; -use alloy_primitives::{ - Address, BlockHash, BlockNumber, Bytes, ChainId, TxHash, TxIndex, TxKind, B256, U256, -}; +use alloy_primitives::{Address, BlockHash, Bytes, ChainId, TxHash, TxIndex, TxKind, B256, U256}; use serde::{Deserialize, Serialize}; pub use alloy_consensus::BlobTransactionSidecar; @@ -49,7 +47,7 @@ pub struct Transaction { pub block_hash: Option, /// Block number #[serde(default, with = "alloy_serde::quantity::opt")] - pub block_number: Option, + pub block_number: Option, /// Transaction Index #[serde(default, with = "alloy_serde::quantity::opt")] pub transaction_index: Option, diff --git a/crates/rpc-types-eth/src/transaction/receipt.rs b/crates/rpc-types-eth/src/transaction/receipt.rs index 2a20d50c0ef..2d645502ac0 100644 --- a/crates/rpc-types-eth/src/transaction/receipt.rs +++ b/crates/rpc-types-eth/src/transaction/receipt.rs @@ -2,7 +2,7 @@ use crate::{Log, WithOtherFields}; use alloy_consensus::{AnyReceiptEnvelope, ReceiptEnvelope, TxType}; -use alloy_primitives::{Address, BlockHash, BlockNumber, TxHash, TxIndex, B256}; +use alloy_primitives::{Address, BlockHash, TxHash, TxIndex, B256}; use serde::{Deserialize, Serialize}; /// Transaction receipt @@ -32,7 +32,7 @@ pub struct TransactionReceipt> { pub block_hash: Option, /// Number of the block this transaction was included within. #[serde(default, with = "alloy_serde::quantity::opt")] - pub block_number: Option, + pub block_number: Option, /// Gas used by this transaction alone. #[serde(with = "alloy_serde::quantity")] pub gas_used: u128, diff --git a/crates/rpc-types-trace/src/parity.rs b/crates/rpc-types-trace/src/parity.rs index d913de9394f..71b20801955 100644 --- a/crates/rpc-types-trace/src/parity.rs +++ b/crates/rpc-types-trace/src/parity.rs @@ -2,7 +2,7 @@ //! //! See -use alloy_primitives::{Address, BlockHash, BlockNumber, Bytes, TxHash, TxIndex, B256, U256, U64}; +use alloy_primitives::{Address, BlockHash, Bytes, TxHash, TxIndex, B256, U256, U64}; use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer}; use std::{ collections::BTreeMap, @@ -401,7 +401,7 @@ pub struct LocalizedTransactionTrace { /// Block number the transaction is included in, None if pending. /// /// Note: this deviates from which always returns a block number - pub block_number: Option, + pub block_number: Option, /// Hash of the transaction #[doc(alias = "tx_hash")] pub transaction_hash: Option, From b9855679d30c9437d93af3a74ec428294ac50e3c Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Tue, 11 Jun 2024 19:43:30 +0200 Subject: [PATCH 16/17] remove newly added BlockNumber references, leave the old ones as is --- crates/eips/src/eip1898.rs | 16 ++++++++-------- crates/rpc-types-eth/src/block.rs | 6 +++--- crates/rpc-types-eth/src/filter.rs | 8 ++++---- crates/rpc-types-eth/src/pubsub.rs | 8 ++++---- crates/rpc-types-trace/src/opcode.rs | 4 ++-- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/crates/eips/src/eip1898.rs b/crates/eips/src/eip1898.rs index c679f10e3e9..1d3d3d75ab4 100644 --- a/crates/eips/src/eip1898.rs +++ b/crates/eips/src/eip1898.rs @@ -119,14 +119,14 @@ impl BlockNumberOrTag { } impl From for BlockNumberOrTag { - fn from(block_number: u64) -> Self { - Self::Number(block_number) + fn from(num: u64) -> Self { + Self::Number(num) } } impl From for BlockNumberOrTag { - fn from(block_number: U64) -> Self { - block_number.to::().into() + fn from(num: U64) -> Self { + num.to::().into() } } @@ -362,8 +362,8 @@ impl Default for BlockId { } impl From for BlockId { - fn from(block_number: u64) -> Self { - BlockNumberOrTag::Number(block_number).into() + fn from(num: u64) -> Self { + BlockNumberOrTag::Number(num).into() } } @@ -374,8 +374,8 @@ impl From for BlockId { } impl From for BlockId { - fn from(block_number: BlockNumberOrTag) -> Self { - Self::Number(block_number) + fn from(num: BlockNumberOrTag) -> Self { + Self::Number(num) } } diff --git a/crates/rpc-types-eth/src/block.rs b/crates/rpc-types-eth/src/block.rs index a73ac274200..55913a64f0b 100644 --- a/crates/rpc-types-eth/src/block.rs +++ b/crates/rpc-types-eth/src/block.rs @@ -5,7 +5,7 @@ pub use alloy_eips::{ calc_blob_gasprice, calc_excess_blob_gas, BlockHashOrNumber, BlockId, BlockNumHash, BlockNumberOrTag, ForkBlock, RpcBlockHash, }; -use alloy_primitives::{Address, BlockHash, BlockNumber, Bloom, Bytes, B256, B64, U256, U64}; +use alloy_primitives::{Address, BlockHash, Bloom, Bytes, B256, B64, U256, U64}; use serde::{ser::Error, Deserialize, Serialize, Serializer}; use std::{collections::BTreeMap, ops::Deref}; @@ -70,7 +70,7 @@ pub struct Header { pub difficulty: U256, /// Block number #[serde(default, with = "alloy_serde::quantity::opt")] - pub number: Option, + pub number: Option, /// Gas Limit #[serde(default, with = "alloy_serde::quantity")] pub gas_limit: u128, @@ -557,7 +557,7 @@ pub struct BlockOverrides { /// A dictionary that maps blockNumber to a user-defined hash. It could be queried from the /// solidity opcode BLOCKHASH. #[serde(default, skip_serializing_if = "Option::is_none")] - pub block_hash: Option>, + pub block_hash: Option>, } #[cfg(test)] diff --git a/crates/rpc-types-eth/src/filter.rs b/crates/rpc-types-eth/src/filter.rs index 078144f55ce..00f00a89c28 100644 --- a/crates/rpc-types-eth/src/filter.rs +++ b/crates/rpc-types-eth/src/filter.rs @@ -203,14 +203,14 @@ impl From for FilterBlockOption { } impl From for FilterBlockOption { - fn from(block_number: U64) -> Self { - BlockNumberOrTag::from(block_number).into() + fn from(num: U64) -> Self { + BlockNumberOrTag::from(num).into() } } impl From for FilterBlockOption { - fn from(block_number: u64) -> Self { - BlockNumberOrTag::from(block_number).into() + fn from(num: u64) -> Self { + BlockNumberOrTag::from(num).into() } } diff --git a/crates/rpc-types-eth/src/pubsub.rs b/crates/rpc-types-eth/src/pubsub.rs index 4e00d515477..da8f41563c5 100644 --- a/crates/rpc-types-eth/src/pubsub.rs +++ b/crates/rpc-types-eth/src/pubsub.rs @@ -1,7 +1,7 @@ //! Ethereum types for pub-sub use crate::{Filter, Log, RichHeader, Transaction}; -use alloy_primitives::{BlockNumber, B256}; +use alloy_primitives::B256; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; /// Subscription result. @@ -37,12 +37,12 @@ pub struct SyncStatusMetadata { /// Whether the node is currently syncing. pub syncing: bool, /// The starting block. - pub starting_block: BlockNumber, + pub starting_block: u64, /// The current block. - pub current_block: BlockNumber, + pub current_block: u64, /// The highest block. #[serde(default, skip_serializing_if = "Option::is_none")] - pub highest_block: Option, + pub highest_block: Option, } impl Serialize for SubscriptionResult { diff --git a/crates/rpc-types-trace/src/opcode.rs b/crates/rpc-types-trace/src/opcode.rs index cafd5ffdd79..a307308364b 100644 --- a/crates/rpc-types-trace/src/opcode.rs +++ b/crates/rpc-types-trace/src/opcode.rs @@ -1,6 +1,6 @@ //! Types for opcode tracing. -use alloy_primitives::{BlockHash, BlockNumber, TxHash}; +use alloy_primitives::{BlockHash, TxHash}; use serde::{Deserialize, Serialize}; /// Opcode gas usage for a transaction. @@ -10,7 +10,7 @@ pub struct BlockOpcodeGas { /// The block hash pub block_hash: BlockHash, /// The block number - pub block_number: BlockNumber, + pub block_number: u64, /// All executed transactions in the block in the order they were executed, with their opcode /// gas usage. pub transactions: Vec, From f391d70fb33e836db071b4e03f2d5ad1b8b72403 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Tue, 11 Jun 2024 19:47:49 +0200 Subject: [PATCH 17/17] remove TxIndex alias use --- crates/rpc-types-eth/src/filter.rs | 8 ++++---- crates/rpc-types-eth/src/log.rs | 4 ++-- crates/rpc-types-eth/src/transaction/common.rs | 4 ++-- crates/rpc-types-eth/src/transaction/mod.rs | 4 ++-- crates/rpc-types-eth/src/transaction/receipt.rs | 4 ++-- crates/rpc-types-trace/src/parity.rs | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/rpc-types-eth/src/filter.rs b/crates/rpc-types-eth/src/filter.rs index 00f00a89c28..23fa26a79cb 100644 --- a/crates/rpc-types-eth/src/filter.rs +++ b/crates/rpc-types-eth/src/filter.rs @@ -203,14 +203,14 @@ impl From for FilterBlockOption { } impl From for FilterBlockOption { - fn from(num: U64) -> Self { - BlockNumberOrTag::from(num).into() + fn from(block: U64) -> Self { + BlockNumberOrTag::from(block).into() } } impl From for FilterBlockOption { - fn from(num: u64) -> Self { - BlockNumberOrTag::from(num).into() + fn from(block: u64) -> Self { + BlockNumberOrTag::from(block).into() } } diff --git a/crates/rpc-types-eth/src/log.rs b/crates/rpc-types-eth/src/log.rs index b1ede6e77a4..c22aadad4e9 100644 --- a/crates/rpc-types-eth/src/log.rs +++ b/crates/rpc-types-eth/src/log.rs @@ -1,6 +1,6 @@ #![allow(unknown_lints, non_local_definitions)] // TODO: remove when proptest-derive updates -use alloy_primitives::{Address, BlockHash, LogData, TxHash, TxIndex, B256}; +use alloy_primitives::{Address, BlockHash, LogData, TxHash, B256}; use serde::{Deserialize, Serialize}; /// Ethereum Log emitted by a transaction @@ -30,7 +30,7 @@ pub struct Log { /// Index of the Transaction in the block #[serde(with = "alloy_serde::quantity::opt")] #[doc(alias = "tx_index")] - pub transaction_index: Option, + pub transaction_index: Option, /// Log Index in Block #[serde(with = "alloy_serde::quantity::opt")] pub log_index: Option, diff --git a/crates/rpc-types-eth/src/transaction/common.rs b/crates/rpc-types-eth/src/transaction/common.rs index a9b02d2849d..f729c0f74f1 100644 --- a/crates/rpc-types-eth/src/transaction/common.rs +++ b/crates/rpc-types-eth/src/transaction/common.rs @@ -2,7 +2,7 @@ //! when working with RPC types, such as [Transaction] use crate::Transaction; -use alloy_primitives::{BlockHash, TxHash, TxIndex}; +use alloy_primitives::{BlockHash, TxHash}; /// Additional fields in the context of a block that contains this transaction. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] @@ -11,7 +11,7 @@ pub struct TransactionInfo { /// Hash of the transaction. pub hash: Option, /// Index of the transaction in the block - pub index: Option, + pub index: Option, /// Hash of the block. pub block_hash: Option, /// Number of the block. diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 64190e02975..88c35a45300 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -5,7 +5,7 @@ use alloy_consensus::{ SignableTransaction, Signed, TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, TxEnvelope, TxLegacy, TxType, }; -use alloy_primitives::{Address, BlockHash, Bytes, ChainId, TxHash, TxIndex, TxKind, B256, U256}; +use alloy_primitives::{Address, BlockHash, Bytes, ChainId, TxHash, TxKind, B256, U256}; use serde::{Deserialize, Serialize}; pub use alloy_consensus::BlobTransactionSidecar; @@ -50,7 +50,7 @@ pub struct Transaction { pub block_number: Option, /// Transaction Index #[serde(default, with = "alloy_serde::quantity::opt")] - pub transaction_index: Option, + pub transaction_index: Option, /// Sender pub from: Address, /// Recipient diff --git a/crates/rpc-types-eth/src/transaction/receipt.rs b/crates/rpc-types-eth/src/transaction/receipt.rs index 2d645502ac0..7fc7b108e85 100644 --- a/crates/rpc-types-eth/src/transaction/receipt.rs +++ b/crates/rpc-types-eth/src/transaction/receipt.rs @@ -2,7 +2,7 @@ use crate::{Log, WithOtherFields}; use alloy_consensus::{AnyReceiptEnvelope, ReceiptEnvelope, TxType}; -use alloy_primitives::{Address, BlockHash, TxHash, TxIndex, B256}; +use alloy_primitives::{Address, BlockHash, TxHash, B256}; use serde::{Deserialize, Serialize}; /// Transaction receipt @@ -26,7 +26,7 @@ pub struct TransactionReceipt> { /// Index within the block. #[serde(default, with = "alloy_serde::quantity::opt")] #[doc(alias = "tx_index")] - pub transaction_index: Option, + pub transaction_index: Option, /// Hash of the block this transaction was included within. #[serde(default)] pub block_hash: Option, diff --git a/crates/rpc-types-trace/src/parity.rs b/crates/rpc-types-trace/src/parity.rs index 71b20801955..55feda41208 100644 --- a/crates/rpc-types-trace/src/parity.rs +++ b/crates/rpc-types-trace/src/parity.rs @@ -2,7 +2,7 @@ //! //! See -use alloy_primitives::{Address, BlockHash, Bytes, TxHash, TxIndex, B256, U256, U64}; +use alloy_primitives::{Address, BlockHash, Bytes, TxHash, B256, U256, U64}; use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer}; use std::{ collections::BTreeMap, @@ -407,7 +407,7 @@ pub struct LocalizedTransactionTrace { pub transaction_hash: Option, /// Transaction index within the block, None if pending. #[doc(alias = "tx_position", alias = "transaction_index", alias = "tx_index")] - pub transaction_position: Option, + pub transaction_position: Option, } // Implement Serialize manually to ensure consistent ordering of fields to match other client's