Skip to content

Commit

Permalink
feat: add latest block number to chain provider for op-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Sep 9, 2024
1 parent b6d6db6 commit f5021a4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/derive/src/online/alloy_providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ impl AlloyChainProvider {
Self::new(inner)
}

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

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

View check run for this annotation

Codecov / codecov/patch

crates/derive/src/online/alloy_providers.rs#L63-L69

Added lines #L63 - L69 were not covered by tests
}
Err(e) => Err(anyhow!(e)),

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L71 was not covered by tests
}
}

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L73 was not covered by tests

/// Returns the chain ID.
pub async fn chain_id(&mut self) -> Result<u64> {
let chain_id: TransportResult<alloc::string::String> =
Expand Down

0 comments on commit f5021a4

Please sign in to comment.