Skip to content

Commit

Permalink
fix: use upstream provider types
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Sep 23, 2024
1 parent b41908e commit b67d258
Showing 1 changed file with 6 additions and 36 deletions.
42 changes: 6 additions & 36 deletions crates/derive/src/online/alloy_providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -59,29 +59,13 @@ impl AlloyChainProvider {
}

/// Returns the latest L2 block number.
pub async fn latest_block_number(&mut self) -> Result<u64> {
let b: TransportResult<alloc::string::String> =
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<u64, RpcError<TransportErrorKind>> {
self.inner.get_block_number().await
}

/// Returns the chain ID.
pub async fn chain_id(&mut self) -> Result<u64, RpcError<TransportErrorKind>> {
let chain_id: TransportResult<alloc::string::String> =
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::<u64>())
self.inner.get_chain_id().await
}
}

Expand Down Expand Up @@ -305,26 +289,12 @@ impl AlloyL2ChainProvider {

/// Returns the chain ID.
pub async fn chain_id(&mut self) -> Result<u64, RpcError<TransportErrorKind>> {
let chain_id: TransportResult<alloc::string::String> =
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::<u64>())
self.inner.get_chain_id().await
}

/// Returns the latest L2 block number.
pub async fn latest_block_number(&mut self) -> Result<u64, RpcError<TransportErrorKind>> {
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::<u64>())
self.inner.get_block_number().await
}

/// Creates a new [AlloyL2ChainProvider] from the provided [reqwest::Url].
Expand Down

0 comments on commit b67d258

Please sign in to comment.