use std::sync::Arc;
use reth_chainspec::{ChainInfo, ChainSpec};
use reth_errors::{RethError, RethResult};
use reth_evm::ConfigureEvm;
use reth_network_api::NetworkInfo;
use reth_primitives::{Address, U256, U64};
use reth_provider::{BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, StateProviderFactory};
use reth_rpc_eth_api::helpers::EthApiSpec;
use reth_rpc_types::{SyncInfo, SyncStatus};
use reth_transaction_pool::TransactionPool;
use crate::EthApi;
impl<Provider, Pool, Network, EvmConfig> EthApiSpec for EthApi<Provider, Pool, Network, EvmConfig>
where
Pool: TransactionPool + 'static,
Provider:
BlockReaderIdExt + ChainSpecProvider + StateProviderFactory + EvmEnvProvider + 'static,
Network: NetworkInfo + 'static,
EvmConfig: ConfigureEvm,
{
async fn protocol_version(&self) -> RethResult<U64> {
let status = self.network().network_status().await.map_err(RethError::other)?;
Ok(U64::from(status.protocol_version))
}
fn chain_id(&self) -> U64 {
U64::from(self.network().chain_id())
}
fn chain_info(&self) -> RethResult<ChainInfo> {
Ok(self.provider().chain_info()?)
}
fn accounts(&self) -> Vec<Address> {
self.inner.signers().read().iter().flat_map(|s| s.accounts()).collect()
}
fn is_syncing(&self) -> bool {
self.network().is_syncing()
}
fn sync_status(&self) -> RethResult<SyncStatus> {
let status = if self.is_syncing() {
let current_block = U256::from(
self.provider().chain_info().map(|info| info.best_number).unwrap_or_default(),
);
SyncStatus::Info(SyncInfo {
starting_block: self.inner.starting_block(),
current_block,
highest_block: current_block,
warp_chunks_amount: None,
warp_chunks_processed: None,
})
} else {
SyncStatus::None
};
Ok(status)
}
fn chain_spec(&self) -> Arc<ChainSpec> {
self.inner.provider().chain_spec()
}
}