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