Skip to content

Commit

Permalink
chore: use BlockId functions directly (paradigmxyz#8417)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored and mw2000 committed Jun 5, 2024
1 parent d0e0958 commit f1628b4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion crates/rpc/rpc/src/eth/api/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where
address: Address,
block_id: Option<BlockId>,
) -> EthResult<U256> {
if block_id == Some(BlockId::Number(BlockNumberOrTag::Pending)) {
if block_id == Some(BlockId::pending()) {
let address_txs = self.pool().get_transactions_by_sender(address);
if let Some(highest_nonce) =
address_txs.iter().map(|item| item.transaction.nonce()).max()
Expand Down
11 changes: 3 additions & 8 deletions crates/rpc/rpc/src/eth/api/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,9 +787,7 @@ where
None => return Ok(None),
Some(tx) => {
let res = match tx {
tx @ TransactionSource::Pool(_) => {
(tx, BlockId::Number(BlockNumberOrTag::Pending))
}
tx @ TransactionSource::Pool(_) => (tx, BlockId::pending()),
TransactionSource::Block {
transaction,
index,
Expand Down Expand Up @@ -873,17 +871,14 @@ where

// set nonce if not already set before
if request.nonce.is_none() {
let nonce =
self.get_transaction_count(from, Some(BlockId::Number(BlockNumberOrTag::Pending)))?;
let nonce = self.get_transaction_count(from, Some(BlockId::pending()))?;
// note: `.to()` can't panic because the nonce is constructed from a `u64`
request.nonce = Some(nonce.to::<u64>());
}

let chain_id = self.chain_id();

let estimated_gas = self
.estimate_gas_at(request.clone(), BlockId::Number(BlockNumberOrTag::Pending), None)
.await?;
let estimated_gas = self.estimate_gas_at(request.clone(), BlockId::pending(), None).await?;
let gas_limit = estimated_gas;

let TransactionRequest {
Expand Down
6 changes: 2 additions & 4 deletions crates/rpc/rpc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use crate::eth::{
use async_trait::async_trait;
use jsonrpsee::core::RpcResult as Result;
use reth_consensus_common::calc::{base_block_reward, block_reward};
use reth_primitives::{
revm::env::tx_env_with_recovered, BlockId, BlockNumberOrTag, Bytes, SealedHeader, B256, U256,
};
use reth_primitives::{revm::env::tx_env_with_recovered, BlockId, Bytes, SealedHeader, B256, U256};
use reth_provider::{BlockReader, ChainSpecProvider, EvmEnvProvider, StateProviderFactory};
use reth_revm::database::StateProviderDatabase;
use reth_rpc_api::TraceApiServer;
Expand Down Expand Up @@ -133,7 +131,7 @@ where
calls: Vec<(TransactionRequest, HashSet<TraceType>)>,
block_id: Option<BlockId>,
) -> EthResult<Vec<TraceResults>> {
let at = block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Pending));
let at = block_id.unwrap_or(BlockId::pending());
let (cfg, block_env, at) = self.inner.eth_api.evm_env_at(at).await?;

let gas_limit = self.inner.eth_api.call_gas_limit();
Expand Down

0 comments on commit f1628b4

Please sign in to comment.