mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(rpc): add with_state_at closure (#1763)
This commit is contained in:
@ -3,14 +3,13 @@
|
||||
//! The entire implementation of the namespace is quite large, hence it is divided across several
|
||||
//! files.
|
||||
|
||||
use crate::eth::{cache::EthStateCache, error::EthResult, signer::EthSigner};
|
||||
use crate::eth::{cache::EthStateCache, signer::EthSigner};
|
||||
use async_trait::async_trait;
|
||||
use reth_interfaces::Result;
|
||||
use reth_network_api::NetworkInfo;
|
||||
use reth_primitives::{Address, BlockId, BlockNumberOrTag, ChainInfo, H256, U64};
|
||||
use reth_provider::{
|
||||
providers::ChainState, BlockProvider, EvmEnvProvider, StateProvider as StateProviderTrait,
|
||||
StateProviderFactory,
|
||||
BlockProvider, EvmEnvProvider, StateProvider as StateProviderTrait, StateProviderFactory,
|
||||
};
|
||||
use reth_rpc_types::FeeHistoryCache;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
@ -134,14 +133,6 @@ where
|
||||
self.client().convert_block_number(num)
|
||||
}
|
||||
|
||||
/// Helper function to execute a closure with the database at a specific block.
|
||||
pub(crate) fn with_state_at<F, T>(&self, _at: BlockId, _f: F) -> EthResult<T>
|
||||
where
|
||||
F: FnOnce(ChainState<'_>) -> T,
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// Returns the state at the given [BlockId] enum or the latest.
|
||||
pub(crate) fn state_at_block_id_or_latest(
|
||||
&self,
|
||||
|
||||
@ -8,7 +8,7 @@ use reth_primitives::{
|
||||
BlockId, BlockNumberOrTag, Bytes, FromRecoveredTransaction, IntoRecoveredTransaction,
|
||||
TransactionSigned, TransactionSignedEcRecovered, H256, U256,
|
||||
};
|
||||
use reth_provider::{BlockProvider, EvmEnvProvider, StateProviderFactory};
|
||||
use reth_provider::{providers::ChainState, BlockProvider, EvmEnvProvider, StateProviderFactory};
|
||||
use reth_rlp::Decodable;
|
||||
use reth_rpc_types::{Index, Transaction, TransactionRequest};
|
||||
use reth_transaction_pool::{TransactionOrigin, TransactionPool};
|
||||
@ -17,6 +17,11 @@ use revm::primitives::{BlockEnv, CfgEnv};
|
||||
/// Commonly used transaction related functions for the [EthApi] type in the `eth_` namespace
|
||||
#[async_trait::async_trait]
|
||||
pub trait EthTransactions: Send + Sync {
|
||||
/// Executes the closure with the state that corresponds to the given [BlockId].
|
||||
fn with_state_at<F, T>(&self, _at: BlockId, _f: F) -> EthResult<T>
|
||||
where
|
||||
F: FnOnce(ChainState<'_>) -> EthResult<T>;
|
||||
|
||||
/// Returns the revm evm env for the requested [BlockId]
|
||||
///
|
||||
/// If the [BlockId] this will return the [BlockId::Hash] of the block the env was configured
|
||||
@ -44,6 +49,13 @@ where
|
||||
Client: BlockProvider + StateProviderFactory + EvmEnvProvider + 'static,
|
||||
Network: Send + Sync + 'static,
|
||||
{
|
||||
fn with_state_at<F, T>(&self, _at: BlockId, _f: F) -> EthResult<T>
|
||||
where
|
||||
F: FnOnce(ChainState<'_>) -> EthResult<T>,
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
async fn evm_env_at(&self, at: BlockId) -> EthResult<(CfgEnv, BlockEnv, BlockId)> {
|
||||
// TODO handle Pending state's env
|
||||
match at {
|
||||
|
||||
Reference in New Issue
Block a user