diff --git a/src/client/client.rs b/src/client/client.rs index a5bde12..f86460c 100644 --- a/src/client/client.rs +++ b/src/client/client.rs @@ -90,6 +90,11 @@ impl Client { Ok(tip) } + pub async fn get_block_number(&self) -> Result { + let payload = self.consensus.get_execution_payload().await?; + Ok(payload.block_number) + } + pub fn chain_id(&self) -> u64 { self.config.general.chain_id } diff --git a/src/client/rpc.rs b/src/client/rpc.rs index 71d27fd..9177226 100644 --- a/src/client/rpc.rs +++ b/src/client/rpc.rs @@ -57,6 +57,8 @@ trait EthRpc { async fn gas_price(&self) -> Result; #[method(name = "maxPriorityFeePerGas")] async fn max_priority_fee_per_gas(&self) -> Result; + #[method(name = "blockNumber")] + async fn block_number(&self) -> Result; } struct RpcInner { @@ -144,6 +146,11 @@ impl EthRpcServer for RpcInner { let tip = convert_err(self.client.get_priority_fee().await)?; Ok(tip.encode_hex()) } + + async fn block_number(&self) -> Result { + let num = convert_err(self.client.get_block_number().await)?; + Ok(u64_to_hex_string(num)) + } } async fn start(rpc: RpcInner) -> Result<(HttpServerHandle, SocketAddr)> {