Skip to content

Commit f37d592

Browse files
authored
feat: Implement engine api eth_getBlockByNumber (#478)
1 parent 3823ecc commit f37d592

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

  • crates/common/execution_engine/src

crates/common/execution_engine/src/lib.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod utils;
44
use std::path::PathBuf;
55

66
use alloy_primitives::{B64, B256, Bytes, hex};
7-
use alloy_rpc_types_eth::Block;
7+
use alloy_rpc_types_eth::{Block, BlockNumberOrTag};
88
use anyhow::anyhow;
99
use async_trait::async_trait;
1010
use jsonwebtoken::{EncodingKey, Header, encode, get_current_timestamp};
@@ -139,6 +139,28 @@ impl ExecutionEngine {
139139
.to_result()
140140
}
141141

142+
pub async fn eth_get_block_by_number(
143+
&self,
144+
block_number_or_tag: BlockNumberOrTag,
145+
hydrated: bool,
146+
) -> anyhow::Result<Block> {
147+
let request_body = JsonRpcRequest {
148+
id: 1,
149+
jsonrpc: "2.0".to_string(),
150+
method: "eth_getBlockByNumber".to_string(),
151+
params: vec![json!(block_number_or_tag), json!(hydrated)],
152+
};
153+
154+
let http_post_request = self.build_request(request_body)?;
155+
156+
self.http_client
157+
.execute(http_post_request)
158+
.await?
159+
.json::<JsonRpcResponse<Block>>()
160+
.await?
161+
.to_result()
162+
}
163+
142164
pub async fn eth_get_block_by_hash(
143165
&self,
144166
block_hash: B256,

0 commit comments

Comments
 (0)