reth_rpc_engine_api/
capabilities.rs

1use std::collections::HashSet;
2
3/// The list of all supported Engine capabilities available over the engine endpoint.
4pub const CAPABILITIES: &[&str] = &[
5    "engine_forkchoiceUpdatedV1",
6    "engine_forkchoiceUpdatedV2",
7    "engine_forkchoiceUpdatedV3",
8    "engine_getClientVersionV1",
9    "engine_getPayloadV1",
10    "engine_getPayloadV2",
11    "engine_getPayloadV3",
12    "engine_getPayloadV4",
13    "engine_newPayloadV1",
14    "engine_newPayloadV2",
15    "engine_newPayloadV3",
16    "engine_newPayloadV4",
17    "engine_getPayloadBodiesByHashV1",
18    "engine_getPayloadBodiesByRangeV1",
19    "engine_getBlobsV1",
20];
21
22// The list of all supported Engine capabilities available over the engine endpoint.
23///
24/// Latest spec: Prague
25#[derive(Debug, Clone)]
26pub struct EngineCapabilities {
27    inner: HashSet<String>,
28}
29
30impl EngineCapabilities {
31    /// Creates a new `EngineCapabilities` instance with the given capabilities.
32    pub fn new(capabilities: impl IntoIterator<Item: Into<String>>) -> Self {
33        Self { inner: capabilities.into_iter().map(Into::into).collect() }
34    }
35
36    /// Returns the list of all supported Engine capabilities for Prague spec.
37    fn prague() -> Self {
38        Self { inner: CAPABILITIES.iter().copied().map(str::to_owned).collect() }
39    }
40
41    /// Returns the list of all supported Engine capabilities.
42    pub fn list(&self) -> Vec<String> {
43        self.inner.iter().cloned().collect()
44    }
45
46    /// Inserts a new capability.
47    pub fn add_capability(&mut self, capability: impl Into<String>) {
48        self.inner.insert(capability.into());
49    }
50
51    /// Removes a capability.
52    pub fn remove_capability(&mut self, capability: &str) -> Option<String> {
53        self.inner.take(capability)
54    }
55}
56
57impl Default for EngineCapabilities {
58    fn default() -> Self {
59        Self::prague()
60    }
61}