From de1b5f3c734a36f03c231e97e7cf10dcb2d5aa4f Mon Sep 17 00:00:00 2001 From: Enrique Ortiz Date: Fri, 8 Dec 2023 16:24:41 -0400 Subject: [PATCH] fmt --- crates/providers/src/provider.rs | 119 +++++------------- .../src/eth/transaction/access_list.rs | 14 +-- .../src/eth/transaction/signature.rs | 13 +- .../rpc-types/src/eth/transaction/tx_type.rs | 4 +- crates/rpc-types/src/eth/transaction/typed.rs | 79 ++++++------ 5 files changed, 82 insertions(+), 147 deletions(-) diff --git a/crates/providers/src/provider.rs b/crates/providers/src/provider.rs index 680d0de6607..1688778d159 100644 --- a/crates/providers/src/provider.rs +++ b/crates/providers/src/provider.rs @@ -13,7 +13,7 @@ use alloy_transport::{BoxTransport, Transport, TransportErrorKind, TransportResu use alloy_transport_http::Http; use auto_impl::auto_impl; use reqwest::Client; -use serde::{Deserialize, Serialize, de::DeserializeOwned}; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; use thiserror::Error; #[derive(Debug, Error, Serialize, Deserialize)] @@ -239,11 +239,7 @@ pub trait TempProvider: Send + Sync { where Self: Sync; - async fn raw_request( - &self, - method: &'static str, - params: P, - ) -> TransportResult + async fn raw_request(&self, method: &'static str, params: P) -> TransportResult where P: Serialize + Send + Sync + Clone, R: Serialize + DeserializeOwned + Send + Sync + Unpin + 'static, @@ -286,10 +282,7 @@ impl TempProvider for Provider { self.inner .prepare( "eth_getTransactionCount", - ( - address, - tag.unwrap_or(BlockNumberOrTag::Latest.into()), - ), + (address, tag.unwrap_or(BlockNumberOrTag::Latest.into())), ) .await } @@ -305,10 +298,7 @@ impl TempProvider for Provider { self.inner .prepare( "eth_getBalance", - ( - address, - tag.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest)), - ), + (address, tag.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest))), ) .await } @@ -319,9 +309,7 @@ impl TempProvider for Provider { hash: BlockHash, full: bool, ) -> TransportResult> { - self.inner - .prepare("eth_getBlockByHash", (hash, full)) - .await + self.inner.prepare("eth_getBlockByHash", (hash, full)).await } /// Gets a block by [BlockNumberOrTag], with full transactions or only hashes. @@ -330,12 +318,7 @@ impl TempProvider for Provider { number: B, full: bool, ) -> TransportResult> { - self.inner - .prepare( - "eth_getBlockByNumber", - (number.into(), full), - ) - .await + self.inner.prepare("eth_getBlockByNumber", (number.into(), full)).await } /// Gets the chain ID. @@ -353,11 +336,7 @@ impl TempProvider for Provider { self.inner .prepare( "eth_getStorageAt", - ( - address, - key, - tag.unwrap_or(BlockNumberOrTag::Latest.into()), - ), + (address, key, tag.unwrap_or(BlockNumberOrTag::Latest.into())), ) .await } @@ -368,19 +347,12 @@ impl TempProvider for Provider { address: Address, tag: B, ) -> TransportResult { - self.inner - .prepare("eth_getCode", (address, tag.into())) - .await + self.inner.prepare("eth_getCode", (address, tag.into())).await } /// Gets a [Transaction] by its [TxHash]. pub async fn get_transaction_by_hash(&self, hash: TxHash) -> TransportResult { - self.inner - .prepare( - "eth_getTransactionByHash", - (hash,), - ) - .await + self.inner.prepare("eth_getTransactionByHash", (hash,)).await } /// Retrieves a [`Vec`] with the given [Filter]. @@ -416,14 +388,7 @@ impl TempProvider for Provider { reward_percentiles: &[f64], ) -> TransportResult { self.inner - .prepare( - "eth_feeHistory", - ( - block_count, - last_block.into(), - reward_percentiles, - ), - ) + .prepare("eth_feeHistory", (block_count, last_block.into(), reward_percentiles)) .await } @@ -447,20 +412,10 @@ impl TempProvider for Provider { let tag = tag.into(); match tag { BlockId::Hash(hash) => { - self.inner - .prepare( - "eth_getUncleByBlockHashAndIndex", - (hash, idx), - ) - .await + self.inner.prepare("eth_getUncleByBlockHashAndIndex", (hash, idx)).await } BlockId::Number(number) => { - self.inner - .prepare( - "eth_getUncleByBlockNumberAndIndex", - (number, idx), - ) - .await + self.inner.prepare("eth_getUncleByBlockNumberAndIndex", (number, idx)).await } } } @@ -473,13 +428,7 @@ impl TempProvider for Provider { /// Execute a smart contract call with [CallRequest] without publishing a transaction. async fn call(&self, tx: CallRequest, block: Option) -> TransportResult { self.inner - .prepare( - "eth_call", - ( - tx, - block.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest)), - ), - ) + .prepare("eth_call", (tx, block.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest)))) .await } @@ -494,7 +443,7 @@ impl TempProvider for Provider { } } - /// Sends an already-signed transaction. + /// Sends an already-signed transaction. async fn send_raw_transaction(&self, tx: Bytes) -> TransportResult where Self: Sync, @@ -555,11 +504,7 @@ impl TempProvider for Provider { self.inner .prepare( "eth_getProof", - ( - address, - keys, - block.unwrap_or(BlockNumberOrTag::Latest.into()), - ), + (address, keys, block.unwrap_or(BlockNumberOrTag::Latest.into())), ) .await } @@ -575,10 +520,7 @@ impl TempProvider for Provider { self.inner .prepare( "eth_createAccessList", - ( - request, - block.unwrap_or(BlockNumberOrTag::Latest.into()), - ), + (request, block.unwrap_or(BlockNumberOrTag::Latest.into())), ) .await } @@ -602,12 +544,7 @@ impl TempProvider for Provider { where Self: Sync, { - self.inner - .prepare( - "debug_traceTransaction", - (hash, trace_options), - ) - .await + self.inner.prepare("debug_traceTransaction", (hash, trace_options)).await } async fn trace_block( @@ -622,15 +559,11 @@ impl TempProvider for Provider { /// Sends a raw request with the methods and params specified to the internal connection, /// and returns the result. - async fn raw_request( - &self, - method: &'static str, - params: P, - ) -> TransportResult + async fn raw_request(&self, method: &'static str, params: P) -> TransportResult where P: Serialize + Send + Sync + Clone, R: Serialize + DeserializeOwned + Send + Sync + Unpin + 'static, - Self: Sync + Self: Sync, { let res: R = self.inner.prepare(method, ¶ms).await?; Ok(res) @@ -641,9 +574,7 @@ impl TempProvider for Provider { where Self: Sync, { - self.inner - .prepare("anvil_setCode", (address, code)) - .await + self.inner.prepare("anvil_setCode", (address, code)).await } } @@ -681,7 +612,7 @@ mod providers_test { utils, }; use alloy_primitives::{address, b256, U256, U64}; - use alloy_rpc_types::{BlockNumberOrTag, Filter, Block}; + use alloy_rpc_types::{Block, BlockNumberOrTag, Filter}; use ethers_core::utils::Anvil; #[tokio::test] @@ -734,7 +665,13 @@ mod providers_test { let tag: BlockNumberOrTag = num.into(); let block = provider.get_block_by_number(tag, true).await.unwrap().unwrap(); let hash = block.header.hash.unwrap(); - let block: Block = provider.raw_request::<(alloy_primitives::FixedBytes<32>, bool), Block>("eth_getBlockByHash", (hash, true)).await.unwrap(); + let block: Block = provider + .raw_request::<(alloy_primitives::FixedBytes<32>, bool), Block>( + "eth_getBlockByHash", + (hash, true), + ) + .await + .unwrap(); assert_eq!(block.header.hash.unwrap(), hash); } diff --git a/crates/rpc-types/src/eth/transaction/access_list.rs b/crates/rpc-types/src/eth/transaction/access_list.rs index c69517809ac..f0b8025a0cc 100644 --- a/crates/rpc-types/src/eth/transaction/access_list.rs +++ b/crates/rpc-types/src/eth/transaction/access_list.rs @@ -1,7 +1,7 @@ -use std::mem; +use alloy_primitives::{Address, B256, U256}; use alloy_rlp::{RlpDecodable, RlpEncodable}; -use alloy_primitives::{Address, U256, B256}; use serde::{Deserialize, Serialize}; +use std::mem; /// A list of addresses and storage keys that the transaction plans to access. /// Accesses outside the list are possible, but become more expensive. @@ -46,10 +46,7 @@ impl AccessList { self.0.into_iter().map(|item| { ( item.address, - item.storage_keys - .into_iter() - .map(|slot| U256::from_be_bytes(slot.0)) - .collect(), + item.storage_keys.into_iter().map(|slot| U256::from_be_bytes(slot.0)).collect(), ) }) } @@ -59,10 +56,7 @@ impl AccessList { self.0.iter().map(|item| { ( item.address, - item.storage_keys - .iter() - .map(|slot| U256::from_be_bytes(slot.0)) - .collect(), + item.storage_keys.iter().map(|slot| U256::from_be_bytes(slot.0)).collect(), ) }) } diff --git a/crates/rpc-types/src/eth/transaction/signature.rs b/crates/rpc-types/src/eth/transaction/signature.rs index 481de806f34..072f7c3d64c 100644 --- a/crates/rpc-types/src/eth/transaction/signature.rs +++ b/crates/rpc-types/src/eth/transaction/signature.rs @@ -98,13 +98,12 @@ impl Signature { /// Decodes the `y_parity`, `r`, `s` values without a RLP header. pub fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { - let mut sig = - Signature { - y_parity: Some(Decodable::decode(buf)?), - r: Decodable::decode(buf)?, - s: Decodable::decode(buf)?, - v: U256::ZERO, - }; + let mut sig = Signature { + y_parity: Some(Decodable::decode(buf)?), + r: Decodable::decode(buf)?, + s: Decodable::decode(buf)?, + v: U256::ZERO, + }; sig.v = sig.y_parity.unwrap().into(); Ok(sig) } diff --git a/crates/rpc-types/src/eth/transaction/tx_type.rs b/crates/rpc-types/src/eth/transaction/tx_type.rs index 81f60b533e8..f589f639cb0 100644 --- a/crates/rpc-types/src/eth/transaction/tx_type.rs +++ b/crates/rpc-types/src/eth/transaction/tx_type.rs @@ -17,8 +17,8 @@ pub const EIP4844_TX_TYPE_ID: u8 = 3; /// Transaction Type /// /// Currently being used as 2-bit type when encoding it to Compact on -/// crate::TransactionSignedNoHash (see Reth's Compact encoding). Adding more transaction types will break the codec and -/// database format on Reth. +/// crate::TransactionSignedNoHash (see Reth's Compact encoding). Adding more transaction types will +/// break the codec and database format on Reth. /// /// Other required changes when adding a new type can be seen on [PR#3953](https://github.com/paradigmxyz/reth/pull/3953/files). #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize)] diff --git a/crates/rpc-types/src/eth/transaction/typed.rs b/crates/rpc-types/src/eth/transaction/typed.rs index 98c2cd4b99a..054a3137fdf 100644 --- a/crates/rpc-types/src/eth/transaction/typed.rs +++ b/crates/rpc-types/src/eth/transaction/typed.rs @@ -3,11 +3,14 @@ //! transaction deserialized from the json input of an RPC call. Depending on what fields are set, //! it can be converted into the container type [`TypedTransactionRequest`]. -use std::{mem, cmp::Ordering}; +use std::{cmp::Ordering, mem}; use crate::{eth::transaction::AccessList, Signature, TxType}; use alloy_primitives::{keccak256, Address, Bytes, B256, U128, U256, U64}; -use alloy_rlp::{bytes, length_of_length, BufMut, Decodable, Encodable, Error as RlpError, Header, EMPTY_LIST_CODE, Buf}; +use alloy_rlp::{ + bytes, length_of_length, Buf, BufMut, Decodable, Encodable, Error as RlpError, Header, + EMPTY_LIST_CODE, +}; use serde::{Deserialize, Serialize}; /// Container type for various Ethereum transaction requests @@ -37,13 +40,13 @@ impl Encodable for TypedTransactionRequest { let id = 1_u8; id.encode(out); tx.encode(out) - }, + } // For EIP1559, it's 2. TypedTransactionRequest::EIP1559(tx) => { let id = 2_u8; id.encode(out); tx.encode(out) - }, + } } } @@ -75,23 +78,25 @@ impl Decodable for TypedTransactionRequest { // consumed. // Otherwise, header decoding will succeed but nothing is consumed. let _header = Header::decode(buf)?; - let tx_type = *buf.first().ok_or(RlpError::Custom( - "typed tx cannot be decoded from an empty slice", - ))?; + let tx_type = *buf + .first() + .ok_or(RlpError::Custom("typed tx cannot be decoded from an empty slice"))?; if tx_type == 0x01 { buf.advance(1); - EIP2930TransactionRequest::decode(buf) - .map(TypedTransactionRequest::EIP2930) + EIP2930TransactionRequest::decode(buf).map(TypedTransactionRequest::EIP2930) } else if tx_type == 0x02 { buf.advance(1); - EIP1559TransactionRequest::decode(buf) - .map(TypedTransactionRequest::EIP1559) + EIP1559TransactionRequest::decode(buf).map(TypedTransactionRequest::EIP1559) } else { Err(RlpError::Custom("invalid tx type")) } - }, - Ordering::Equal => Err(RlpError::Custom("an empty list is not a valid transaction encoding")), - Ordering::Greater => LegacyTransactionRequest::decode(buf).map(TypedTransactionRequest::Legacy), + } + Ordering::Equal => { + Err(RlpError::Custom("an empty list is not a valid transaction encoding")) + } + Ordering::Greater => { + LegacyTransactionRequest::decode(buf).map(TypedTransactionRequest::Legacy) + } } } } @@ -119,12 +124,12 @@ impl Encodable for LegacyTransactionRequest { } fn length(&self) -> usize { - self.nonce.length() + - self.gas_price.length() + - self.gas_limit.length() + - self.kind.length() + - self.value.length() + - self.input.0.length() + self.nonce.length() + + self.gas_price.length() + + self.gas_limit.length() + + self.kind.length() + + self.value.length() + + self.input.0.length() } } @@ -259,14 +264,14 @@ impl Encodable for EIP2930TransactionRequest { } fn length(&self) -> usize { - self.chain_id.length() + - self.nonce.length() + - self.gas_price.length() + - self.gas_limit.length() + - self.kind.length() + - self.value.length() + - self.input.0.length() + - self.access_list.length() + self.chain_id.length() + + self.nonce.length() + + self.gas_price.length() + + self.gas_limit.length() + + self.kind.length() + + self.value.length() + + self.input.0.length() + + self.access_list.length() } } @@ -443,15 +448,15 @@ impl Encodable for EIP1559TransactionRequest { } fn length(&self) -> usize { - self.chain_id.length() + - self.nonce.length() + - self.max_priority_fee_per_gas.length() + - self.max_fee_per_gas.length() + - self.gas_limit.length() + - self.kind.length() + - self.value.length() + - self.input.0.length() + - self.access_list.length() + self.chain_id.length() + + self.nonce.length() + + self.max_priority_fee_per_gas.length() + + self.max_fee_per_gas.length() + + self.gas_limit.length() + + self.kind.length() + + self.value.length() + + self.input.0.length() + + self.access_list.length() } }