1use clap::ValueEnum;
22use std::str::FromStr;
23
24#[derive(Debug, Clone, Copy, ValueEnum)]
26#[value(rename_all = "kebab-case")]
27pub enum WasmtimeInstantiationStrategy {
28 PoolingCopyOnWrite,
31
32 RecreateInstanceCopyOnWrite,
35
36 Pooling,
39
40 RecreateInstance,
42}
43
44pub const DEFAULT_WASMTIME_INSTANTIATION_STRATEGY: WasmtimeInstantiationStrategy =
46 WasmtimeInstantiationStrategy::PoolingCopyOnWrite;
47
48#[derive(Debug, Clone, Copy, ValueEnum)]
50#[value(rename_all = "kebab-case")]
51pub enum WasmExecutionMethod {
52 #[clap(name = "interpreted-i-know-what-i-do")]
54 Interpreted,
55 Compiled,
57}
58
59impl std::fmt::Display for WasmExecutionMethod {
60 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 match self {
62 Self::Interpreted => write!(f, "Interpreted"),
63 Self::Compiled => write!(f, "Compiled"),
64 }
65 }
66}
67
68pub fn execution_method_from_cli(
71 execution_method: WasmExecutionMethod,
72 instantiation_strategy: WasmtimeInstantiationStrategy,
73) -> sc_service::config::WasmExecutionMethod {
74 if let WasmExecutionMethod::Interpreted = execution_method {
75 log::warn!(
76 "`interpreted-i-know-what-i-do` is deprecated and will be removed in the future. Defaults to `compiled` execution mode."
77 );
78 }
79
80 sc_service::config::WasmExecutionMethod::Compiled {
81 instantiation_strategy: match instantiation_strategy {
82 WasmtimeInstantiationStrategy::PoolingCopyOnWrite =>
83 sc_service::config::WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
84 WasmtimeInstantiationStrategy::RecreateInstanceCopyOnWrite =>
85 sc_service::config::WasmtimeInstantiationStrategy::RecreateInstanceCopyOnWrite,
86 WasmtimeInstantiationStrategy::Pooling =>
87 sc_service::config::WasmtimeInstantiationStrategy::Pooling,
88 WasmtimeInstantiationStrategy::RecreateInstance =>
89 sc_service::config::WasmtimeInstantiationStrategy::RecreateInstance,
90 },
91 }
92}
93
94pub const DEFAULT_WASM_EXECUTION_METHOD: WasmExecutionMethod = WasmExecutionMethod::Compiled;
96
97#[allow(missing_docs)]
98#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
99#[value(rename_all = "kebab-case")]
100pub enum TracingReceiver {
101 Log,
103}
104
105impl Into<sc_tracing::TracingReceiver> for TracingReceiver {
106 fn into(self) -> sc_tracing::TracingReceiver {
107 match self {
108 TracingReceiver::Log => sc_tracing::TracingReceiver::Log,
109 }
110 }
111}
112
113#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
115#[value(rename_all = "kebab-case")]
116pub enum NodeKeyType {
117 Ed25519,
119}
120
121#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
123#[value(rename_all = "kebab-case")]
124pub enum CryptoScheme {
125 Ed25519,
127 Sr25519,
129 Ecdsa,
131}
132
133#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
135#[value(rename_all = "kebab-case")]
136pub enum OutputType {
137 Json,
139 Text,
141}
142
143#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
145#[value(rename_all = "kebab-case")]
146pub enum ExecutionStrategy {
147 Native,
149 Wasm,
151 Both,
153 NativeElseWasm,
155}
156
157#[allow(missing_docs)]
159#[derive(Debug, Copy, Clone, PartialEq, ValueEnum)]
160#[value(rename_all = "kebab-case")]
161pub enum RpcMethods {
162 Auto,
165 Safe,
167 Unsafe,
169}
170
171impl FromStr for RpcMethods {
172 type Err = String;
173
174 fn from_str(s: &str) -> Result<Self, Self::Err> {
175 match s {
176 "safe" => Ok(RpcMethods::Safe),
177 "unsafe" => Ok(RpcMethods::Unsafe),
178 "auto" => Ok(RpcMethods::Auto),
179 invalid => Err(format!("Invalid rpc methods {invalid}")),
180 }
181 }
182}
183
184impl Into<sc_service::config::RpcMethods> for RpcMethods {
185 fn into(self) -> sc_service::config::RpcMethods {
186 match self {
187 RpcMethods::Auto => sc_service::config::RpcMethods::Auto,
188 RpcMethods::Safe => sc_service::config::RpcMethods::Safe,
189 RpcMethods::Unsafe => sc_service::config::RpcMethods::Unsafe,
190 }
191 }
192}
193
194#[derive(Clone, Debug)]
198pub enum Cors {
199 All,
201 List(Vec<String>),
203}
204
205impl From<Cors> for Option<Vec<String>> {
206 fn from(cors: Cors) -> Self {
207 match cors {
208 Cors::All => None,
209 Cors::List(list) => Some(list),
210 }
211 }
212}
213
214impl FromStr for Cors {
215 type Err = crate::Error;
216
217 fn from_str(s: &str) -> Result<Self, Self::Err> {
218 let mut is_all = false;
219 let mut origins = Vec::new();
220 for part in s.split(',') {
221 match part {
222 "all" | "*" => {
223 is_all = true;
224 break
225 },
226 other => origins.push(other.to_owned()),
227 }
228 }
229
230 if is_all {
231 Ok(Cors::All)
232 } else {
233 Ok(Cors::List(origins))
234 }
235 }
236}
237
238#[derive(Debug, Clone, PartialEq, Copy, clap::ValueEnum)]
240#[value(rename_all = "lower")]
241pub enum Database {
242 #[cfg(feature = "rocksdb")]
244 RocksDb,
245 ParityDb,
247 Auto,
250 #[value(name = "paritydb-experimental")]
252 ParityDbDeprecated,
253}
254
255impl Database {
256 pub const fn variants() -> &'static [&'static str] {
258 &[
259 #[cfg(feature = "rocksdb")]
260 "rocksdb",
261 "paritydb",
262 "paritydb-experimental",
263 "auto",
264 ]
265 }
266}
267
268#[allow(missing_docs)]
270#[derive(Debug, Clone, ValueEnum)]
271#[value(rename_all = "kebab-case")]
272pub enum OffchainWorkerEnabled {
273 Always,
275 Never,
277 WhenAuthority,
280}
281
282#[derive(Debug, Clone, Copy, ValueEnum, PartialEq)]
284#[value(rename_all = "kebab-case")]
285pub enum SyncMode {
286 Full,
288 Fast,
290 FastUnsafe,
292 Warp,
294}
295
296impl Into<sc_network::config::SyncMode> for SyncMode {
297 fn into(self) -> sc_network::config::SyncMode {
298 match self {
299 SyncMode::Full => sc_network::config::SyncMode::Full,
300 SyncMode::Fast => sc_network::config::SyncMode::LightState {
301 skip_proofs: false,
302 storage_chain_mode: false,
303 },
304 SyncMode::FastUnsafe => sc_network::config::SyncMode::LightState {
305 skip_proofs: true,
306 storage_chain_mode: false,
307 },
308 SyncMode::Warp => sc_network::config::SyncMode::Warp,
309 }
310 }
311}
312
313#[derive(Debug, Clone, Copy, ValueEnum, PartialEq)]
315#[value(rename_all = "lower")]
316pub enum NetworkBackendType {
317 Libp2p,
319
320 Litep2p,
322}
323
324impl Into<sc_network::config::NetworkBackendType> for NetworkBackendType {
325 fn into(self) -> sc_network::config::NetworkBackendType {
326 match self {
327 Self::Libp2p => sc_network::config::NetworkBackendType::Libp2p,
328 Self::Litep2p => sc_network::config::NetworkBackendType::Litep2p,
329 }
330 }
331}