diff --git a/crates/derive/src/online/alloy_providers.rs b/crates/derive/src/online/alloy_providers.rs index 52ae8597a..8f9903ca4 100644 --- a/crates/derive/src/online/alloy_providers.rs +++ b/crates/derive/src/online/alloy_providers.rs @@ -8,7 +8,7 @@ use alloy_provider::{Provider, ReqwestProvider}; use alloy_rlp::{Buf, Decodable}; use alloy_transport::{RpcError, TransportErrorKind, TransportResult}; use async_trait::async_trait; -use core::{num::NonZeroUsize, str::FromStr}; +use core::num::NonZeroUsize; use kona_primitives::{Block, L2ExecutionPayloadEnvelope, OpBlock}; use lru::LruCache; use op_alloy_genesis::{RollupConfig, SystemConfig}; @@ -59,29 +59,13 @@ impl AlloyChainProvider { } /// Returns the latest L2 block number. - pub async fn latest_block_number(&mut self) -> Result { - let b: TransportResult = - self.inner.raw_request("eth_blockNumber".into(), ()).await; - match b { - Ok(s) => { - let s = alloc::string::String::from(s.trim_start_matches("0x")); - u64::from_str_radix(&s, 16).map_err(|e| anyhow!(e)) - } - Err(e) => Err(anyhow!(e)), - } + pub async fn latest_block_number(&mut self) -> Result> { + self.inner.get_block_number().await } /// Returns the chain ID. pub async fn chain_id(&mut self) -> Result> { - let chain_id: TransportResult = - self.inner.raw_request("eth_chainId".into(), ()).await; - let chain_id = match chain_id { - Ok(s) => { - U64::from_str(s.as_str()).map_err(|e| RpcError::LocalUsageError(Box::new(e)))? - } - Err(e) => return Err(e), - }; - Ok(chain_id.to::()) + self.inner.get_chain_id().await } } @@ -305,26 +289,12 @@ impl AlloyL2ChainProvider { /// Returns the chain ID. pub async fn chain_id(&mut self) -> Result> { - let chain_id: TransportResult = - self.inner.raw_request("eth_chainId".into(), ()).await; - let chain_id = match chain_id { - Ok(s) => { - U64::from_str(s.as_str()).map_err(|e| RpcError::LocalUsageError(Box::new(e)))? - } - Err(e) => return Err(e), - }; - Ok(chain_id.to::()) + self.inner.get_chain_id().await } /// Returns the latest L2 block number. pub async fn latest_block_number(&mut self) -> Result> { - let s = self - .inner - .raw_request::<(), alloc::string::String>("eth_blockNumber".into(), ()) - .await?; - U64::from_str(s.as_str()) - .map_err(|e| RpcError::LocalUsageError(Box::new(e))) - .map(|u| u.to::()) + self.inner.get_block_number().await } /// Creates a new [AlloyL2ChainProvider] from the provided [reqwest::Url].