Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Evalir committed Dec 8, 2023
1 parent 8c30905 commit de1b5f3
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 147 deletions.
119 changes: 28 additions & 91 deletions crates/providers/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -239,11 +239,7 @@ pub trait TempProvider: Send + Sync {
where
Self: Sync;

async fn raw_request<P, R>(
&self,
method: &'static str,
params: P,
) -> TransportResult<R>
async fn raw_request<P, R>(&self, method: &'static str, params: P) -> TransportResult<R>
where
P: Serialize + Send + Sync + Clone,
R: Serialize + DeserializeOwned + Send + Sync + Unpin + 'static,
Expand Down Expand Up @@ -286,10 +282,7 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
self.inner
.prepare(
"eth_getTransactionCount",
(
address,
tag.unwrap_or(BlockNumberOrTag::Latest.into()),
),
(address, tag.unwrap_or(BlockNumberOrTag::Latest.into())),
)
.await
}
Expand All @@ -305,10 +298,7 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
self.inner
.prepare(
"eth_getBalance",
(
address,
tag.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest)),
),
(address, tag.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest))),
)
.await
}
Expand All @@ -319,9 +309,7 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
hash: BlockHash,
full: bool,
) -> TransportResult<Option<Block>> {
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.
Expand All @@ -330,12 +318,7 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
number: B,
full: bool,
) -> TransportResult<Option<Block>> {
self.inner
.prepare(
"eth_getBlockByNumber",
(number.into(), full),
)
.await
self.inner.prepare("eth_getBlockByNumber", (number.into(), full)).await
}

/// Gets the chain ID.
Expand All @@ -353,11 +336,7 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
self.inner
.prepare(
"eth_getStorageAt",
(
address,
key,
tag.unwrap_or(BlockNumberOrTag::Latest.into()),
),
(address, key, tag.unwrap_or(BlockNumberOrTag::Latest.into())),
)
.await
}
Expand All @@ -368,19 +347,12 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
address: Address,
tag: B,
) -> TransportResult<Bytes> {
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<Transaction> {
self.inner
.prepare(
"eth_getTransactionByHash",
(hash,),
)
.await
self.inner.prepare("eth_getTransactionByHash", (hash,)).await
}

/// Retrieves a [`Vec<Log>`] with the given [Filter].
Expand Down Expand Up @@ -416,14 +388,7 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
reward_percentiles: &[f64],
) -> TransportResult<FeeHistory> {
self.inner
.prepare(
"eth_feeHistory",
(
block_count,
last_block.into(),
reward_percentiles,
),
)
.prepare("eth_feeHistory", (block_count, last_block.into(), reward_percentiles))
.await
}

Expand All @@ -447,20 +412,10 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
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
}
}
}
Expand All @@ -473,13 +428,7 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
/// Execute a smart contract call with [CallRequest] without publishing a transaction.
async fn call(&self, tx: CallRequest, block: Option<BlockId>) -> TransportResult<Bytes> {
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
}

Expand All @@ -494,7 +443,7 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
}
}

/// Sends an already-signed transaction.
/// Sends an already-signed transaction.
async fn send_raw_transaction(&self, tx: Bytes) -> TransportResult<TxHash>
where
Self: Sync,
Expand Down Expand Up @@ -555,11 +504,7 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
self.inner
.prepare(
"eth_getProof",
(
address,
keys,
block.unwrap_or(BlockNumberOrTag::Latest.into()),
),
(address, keys, block.unwrap_or(BlockNumberOrTag::Latest.into())),
)
.await
}
Expand All @@ -575,10 +520,7 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
self.inner
.prepare(
"eth_createAccessList",
(
request,
block.unwrap_or(BlockNumberOrTag::Latest.into()),
),
(request, block.unwrap_or(BlockNumberOrTag::Latest.into())),
)
.await
}
Expand All @@ -602,12 +544,7 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
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(
Expand All @@ -622,15 +559,11 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {

/// Sends a raw request with the methods and params specified to the internal connection,
/// and returns the result.
async fn raw_request<P, R>(
&self,
method: &'static str,
params: P,
) -> TransportResult<R>
async fn raw_request<P, R>(&self, method: &'static str, params: P) -> TransportResult<R>
where
P: Serialize + Send + Sync + Clone,
R: Serialize + DeserializeOwned + Send + Sync + Unpin + 'static,
Self: Sync
Self: Sync,
{
let res: R = self.inner.prepare(method, &params).await?;
Ok(res)
Expand All @@ -641,9 +574,7 @@ impl<T: Transport + Clone + Send + Sync> TempProvider for Provider<T> {
where
Self: Sync,
{
self.inner
.prepare("anvil_setCode", (address, code))
.await
self.inner.prepare("anvil_setCode", (address, code)).await
}
}

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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);
}

Expand Down
14 changes: 4 additions & 10 deletions crates/rpc-types/src/eth/transaction/access_list.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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(),
)
})
}
Expand All @@ -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(),
)
})
}
Expand Down
13 changes: 6 additions & 7 deletions crates/rpc-types/src/eth/transaction/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc-types/src/eth/transaction/tx_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Loading

0 comments on commit de1b5f3

Please sign in to comment.