Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(derive): Latest BN #521

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 9 additions & 26 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_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 lru::LruCache;
use op_alloy_genesis::{RollupConfig, SystemConfig};
use op_alloy_protocol::{BlockInfo, L2BlockInfo};
Expand Down Expand Up @@ -60,17 +60,14 @@
Self::new(inner)
}

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

Check warning on line 66 in crates/derive/src/online/alloy_providers.rs

View check run for this annotation

Codecov / codecov/patch

crates/derive/src/online/alloy_providers.rs#L64-L66

Added lines #L64 - L66 were not covered by tests

/// 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

Check warning on line 70 in crates/derive/src/online/alloy_providers.rs

View check run for this annotation

Codecov / codecov/patch

crates/derive/src/online/alloy_providers.rs#L70

Added line #L70 was not covered by tests
}
}

Expand Down Expand Up @@ -294,26 +291,12 @@

/// 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

Check warning on line 294 in crates/derive/src/online/alloy_providers.rs

View check run for this annotation

Codecov / codecov/patch

crates/derive/src/online/alloy_providers.rs#L294

Added line #L294 was not covered by tests
}

/// 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

Check warning on line 299 in crates/derive/src/online/alloy_providers.rs

View check run for this annotation

Codecov / codecov/patch

crates/derive/src/online/alloy_providers.rs#L299

Added line #L299 was not covered by tests
}

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