1use clap::ValueEnum;
10use std::str::FromStr;
11
12#[derive(Debug, Clone, Copy, ValueEnum)]
14#[value(rename_all = "kebab-case")]
15pub enum WasmtimeInstantiationStrategy {
16 PoolingCopyOnWrite,
19
20 RecreateInstanceCopyOnWrite,
23
24 Pooling,
27
28 RecreateInstance,
30}
31
32pub const DEFAULT_WASMTIME_INSTANTIATION_STRATEGY: WasmtimeInstantiationStrategy =
34 WasmtimeInstantiationStrategy::PoolingCopyOnWrite;
35
36#[derive(Debug, Clone, Copy, ValueEnum)]
38#[value(rename_all = "kebab-case")]
39pub enum WasmExecutionMethod {
40 #[clap(name = "interpreted-i-know-what-i-do")]
42 Interpreted,
43 Compiled,
45}
46
47impl std::fmt::Display for WasmExecutionMethod {
48 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49 match self {
50 Self::Interpreted => write!(f, "Interpreted"),
51 Self::Compiled => write!(f, "Compiled"),
52 }
53 }
54}
55
56pub fn execution_method_from_cli(
59 execution_method: WasmExecutionMethod,
60 instantiation_strategy: WasmtimeInstantiationStrategy,
61) -> soil_service::config::WasmExecutionMethod {
62 if let WasmExecutionMethod::Interpreted = execution_method {
63 log::warn!(
64 "`interpreted-i-know-what-i-do` is deprecated and will be removed in the future. Defaults to `compiled` execution mode."
65 );
66 }
67
68 soil_service::config::WasmExecutionMethod::Compiled {
69 instantiation_strategy: match instantiation_strategy {
70 WasmtimeInstantiationStrategy::PoolingCopyOnWrite => {
71 soil_service::config::WasmtimeInstantiationStrategy::PoolingCopyOnWrite
72 },
73 WasmtimeInstantiationStrategy::RecreateInstanceCopyOnWrite => {
74 soil_service::config::WasmtimeInstantiationStrategy::RecreateInstanceCopyOnWrite
75 },
76 WasmtimeInstantiationStrategy::Pooling => {
77 soil_service::config::WasmtimeInstantiationStrategy::Pooling
78 },
79 WasmtimeInstantiationStrategy::RecreateInstance => {
80 soil_service::config::WasmtimeInstantiationStrategy::RecreateInstance
81 },
82 },
83 }
84}
85
86pub const DEFAULT_WASM_EXECUTION_METHOD: WasmExecutionMethod = WasmExecutionMethod::Compiled;
88
89#[allow(missing_docs)]
90#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
91#[value(rename_all = "kebab-case")]
92pub enum TracingReceiver {
93 Log,
95}
96
97impl Into<soil_client::tracing::TracingReceiver> for TracingReceiver {
98 fn into(self) -> soil_client::tracing::TracingReceiver {
99 match self {
100 TracingReceiver::Log => soil_client::tracing::TracingReceiver::Log,
101 }
102 }
103}
104
105#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
107#[value(rename_all = "kebab-case")]
108pub enum NodeKeyType {
109 Ed25519,
111}
112
113#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
115#[value(rename_all = "kebab-case")]
116pub enum CryptoScheme {
117 Ed25519,
119 Sr25519,
121 Ecdsa,
123}
124
125#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
127#[value(rename_all = "kebab-case")]
128pub enum OutputType {
129 Json,
131 Text,
133}
134
135#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
137#[value(rename_all = "kebab-case")]
138pub enum ExecutionStrategy {
139 Native,
141 Wasm,
143 Both,
145 NativeElseWasm,
147}
148
149#[allow(missing_docs)]
151#[derive(Debug, Copy, Clone, PartialEq, ValueEnum)]
152#[value(rename_all = "kebab-case")]
153pub enum RpcMethods {
154 Auto,
157 Safe,
159 Unsafe,
161}
162
163impl FromStr for RpcMethods {
164 type Err = String;
165
166 fn from_str(s: &str) -> Result<Self, Self::Err> {
167 match s {
168 "safe" => Ok(RpcMethods::Safe),
169 "unsafe" => Ok(RpcMethods::Unsafe),
170 "auto" => Ok(RpcMethods::Auto),
171 invalid => Err(format!("Invalid rpc methods {invalid}")),
172 }
173 }
174}
175
176impl Into<soil_service::config::RpcMethods> for RpcMethods {
177 fn into(self) -> soil_service::config::RpcMethods {
178 match self {
179 RpcMethods::Auto => soil_service::config::RpcMethods::Auto,
180 RpcMethods::Safe => soil_service::config::RpcMethods::Safe,
181 RpcMethods::Unsafe => soil_service::config::RpcMethods::Unsafe,
182 }
183 }
184}
185
186#[derive(Clone, Debug)]
190pub enum Cors {
191 All,
193 List(Vec<String>),
195}
196
197impl From<Cors> for Option<Vec<String>> {
198 fn from(cors: Cors) -> Self {
199 match cors {
200 Cors::All => None,
201 Cors::List(list) => Some(list),
202 }
203 }
204}
205
206impl FromStr for Cors {
207 type Err = crate::Error;
208
209 fn from_str(s: &str) -> Result<Self, Self::Err> {
210 let mut is_all = false;
211 let mut origins = Vec::new();
212 for part in s.split(',') {
213 match part {
214 "all" | "*" => {
215 is_all = true;
216 break;
217 },
218 other => origins.push(other.to_owned()),
219 }
220 }
221
222 if is_all {
223 Ok(Cors::All)
224 } else {
225 Ok(Cors::List(origins))
226 }
227 }
228}
229
230#[derive(Debug, Clone, PartialEq, Copy, clap::ValueEnum)]
232#[value(rename_all = "lower")]
233pub enum Database {
234 #[cfg(feature = "rocksdb")]
236 RocksDb,
237 ParityDb,
239 Auto,
242 #[value(name = "paritydb-experimental")]
244 ParityDbDeprecated,
245}
246
247impl Database {
248 pub const fn variants() -> &'static [&'static str] {
250 &[
251 #[cfg(feature = "rocksdb")]
252 "rocksdb",
253 "paritydb",
254 "paritydb-experimental",
255 "auto",
256 ]
257 }
258}
259
260#[allow(missing_docs)]
262#[derive(Debug, Clone, ValueEnum)]
263#[value(rename_all = "kebab-case")]
264pub enum OffchainWorkerEnabled {
265 Always,
267 Never,
269 WhenAuthority,
272}
273
274#[derive(Debug, Clone, Copy, ValueEnum, PartialEq)]
276#[value(rename_all = "kebab-case")]
277pub enum SyncMode {
278 Full,
280 Fast,
282 FastUnsafe,
284 Warp,
289}
290
291impl Into<soil_network::config::SyncMode> for SyncMode {
292 fn into(self) -> soil_network::config::SyncMode {
293 match self {
294 SyncMode::Full => soil_network::config::SyncMode::Full,
295 SyncMode::Fast => soil_network::config::SyncMode::LightState {
296 skip_proofs: false,
297 storage_chain_mode: false,
298 },
299 SyncMode::FastUnsafe => soil_network::config::SyncMode::LightState {
300 skip_proofs: true,
301 storage_chain_mode: false,
302 },
303 SyncMode::Warp => soil_network::config::SyncMode::Warp,
304 }
305 }
306}
307
308#[derive(Debug, Clone, Copy, ValueEnum, PartialEq)]
310#[value(rename_all = "lower")]
311pub enum NetworkBackendType {
312 Libp2p,
314
315 Litep2p,
317}
318
319impl Into<soil_network::config::NetworkBackendType> for NetworkBackendType {
320 fn into(self) -> soil_network::config::NetworkBackendType {
321 match self {
322 Self::Libp2p => soil_network::config::NetworkBackendType::Libp2p,
323 Self::Litep2p => soil_network::config::NetworkBackendType::Litep2p,
324 }
325 }
326}