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