reth_node_builder/
engine_api_ext.rs1use crate::rpc::EngineApiBuilder;
6use eyre::Result;
7use reth_node_api::{AddOnsContext, FullNodeComponents};
8use reth_rpc_api::IntoEngineApiRpcModule;
9
10#[derive(Debug)]
12pub struct EngineApiExt<B, F> {
13 inner: B,
15 callback: Option<F>,
17}
18
19impl<B, F> EngineApiExt<B, F> {
20 pub const fn new(inner: B, callback: F) -> Self {
22 Self { inner, callback: Some(callback) }
23 }
24}
25
26impl<N, B, F> EngineApiBuilder<N> for EngineApiExt<B, F>
27where
28 B: EngineApiBuilder<N>,
29 N: FullNodeComponents,
30 B::EngineApi: IntoEngineApiRpcModule + Send + Sync + Clone + 'static,
31 F: FnOnce(B::EngineApi) + Send + Sync + 'static,
32{
33 type EngineApi = B::EngineApi;
34
35 async fn build_engine_api(mut self, ctx: &AddOnsContext<'_, N>) -> Result<Self::EngineApi> {
37 let api = self.inner.build_engine_api(ctx).await?;
38
39 if let Some(callback) = self.callback.take() {
40 callback(api.clone());
41 }
42
43 Ok(api)
44 }
45}