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