From f5021a4072989e15123ca9b76643f509feceb10e Mon Sep 17 00:00:00 2001 From: refcell <abigger87@gmail.com> Date: Mon, 9 Sep 2024 18:35:18 -0400 Subject: [PATCH] feat: add latest block number to chain provider for op-rs --- crates/derive/src/online/alloy_providers.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/derive/src/online/alloy_providers.rs b/crates/derive/src/online/alloy_providers.rs index acf5fe30d..6caed0216 100644 --- a/crates/derive/src/online/alloy_providers.rs +++ b/crates/derive/src/online/alloy_providers.rs @@ -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)) + } + Err(e) => Err(anyhow!(e)), + } + } + /// Returns the chain ID. pub async fn chain_id(&mut self) -> Result<u64> { let chain_id: TransportResult<alloc::string::String> =