use clap::ValueEnum;
use std::str::FromStr;
#[derive(Debug, Clone, Copy, ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum WasmtimeInstantiationStrategy {
PoolingCopyOnWrite,
RecreateInstanceCopyOnWrite,
Pooling,
RecreateInstance,
}
pub const DEFAULT_WASMTIME_INSTANTIATION_STRATEGY: WasmtimeInstantiationStrategy =
WasmtimeInstantiationStrategy::PoolingCopyOnWrite;
#[derive(Debug, Clone, Copy, ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum WasmExecutionMethod {
#[clap(name = "interpreted-i-know-what-i-do")]
Interpreted,
Compiled,
}
impl std::fmt::Display for WasmExecutionMethod {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Interpreted => write!(f, "Interpreted"),
Self::Compiled => write!(f, "Compiled"),
}
}
}
pub fn execution_method_from_cli(
execution_method: WasmExecutionMethod,
instantiation_strategy: WasmtimeInstantiationStrategy,
) -> sc_service::config::WasmExecutionMethod {
if let WasmExecutionMethod::Interpreted = execution_method {
log::warn!(
"`interpreted-i-know-what-i-do` is deprecated and will be removed in the future. Defaults to `compiled` execution mode."
);
}
sc_service::config::WasmExecutionMethod::Compiled {
instantiation_strategy: match instantiation_strategy {
WasmtimeInstantiationStrategy::PoolingCopyOnWrite =>
sc_service::config::WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
WasmtimeInstantiationStrategy::RecreateInstanceCopyOnWrite =>
sc_service::config::WasmtimeInstantiationStrategy::RecreateInstanceCopyOnWrite,
WasmtimeInstantiationStrategy::Pooling =>
sc_service::config::WasmtimeInstantiationStrategy::Pooling,
WasmtimeInstantiationStrategy::RecreateInstance =>
sc_service::config::WasmtimeInstantiationStrategy::RecreateInstance,
},
}
}
pub const DEFAULT_WASM_EXECUTION_METHOD: WasmExecutionMethod = WasmExecutionMethod::Compiled;
#[allow(missing_docs)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum TracingReceiver {
Log,
}
impl Into<sc_tracing::TracingReceiver> for TracingReceiver {
fn into(self) -> sc_tracing::TracingReceiver {
match self {
TracingReceiver::Log => sc_tracing::TracingReceiver::Log,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum NodeKeyType {
Ed25519,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum CryptoScheme {
Ed25519,
Sr25519,
Ecdsa,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum OutputType {
Json,
Text,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum ExecutionStrategy {
Native,
Wasm,
Both,
NativeElseWasm,
}
#[allow(missing_docs)]
#[derive(Debug, Copy, Clone, PartialEq, ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum RpcMethods {
Auto,
Safe,
Unsafe,
}
impl FromStr for RpcMethods {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"safe" => Ok(RpcMethods::Safe),
"unsafe" => Ok(RpcMethods::Unsafe),
"auto" => Ok(RpcMethods::Auto),
invalid => Err(format!("Invalid rpc methods {invalid}")),
}
}
}
impl Into<sc_service::config::RpcMethods> for RpcMethods {
fn into(self) -> sc_service::config::RpcMethods {
match self {
RpcMethods::Auto => sc_service::config::RpcMethods::Auto,
RpcMethods::Safe => sc_service::config::RpcMethods::Safe,
RpcMethods::Unsafe => sc_service::config::RpcMethods::Unsafe,
}
}
}
#[derive(Clone, Debug)]
pub enum Cors {
All,
List(Vec<String>),
}
impl From<Cors> for Option<Vec<String>> {
fn from(cors: Cors) -> Self {
match cors {
Cors::All => None,
Cors::List(list) => Some(list),
}
}
}
impl FromStr for Cors {
type Err = crate::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut is_all = false;
let mut origins = Vec::new();
for part in s.split(',') {
match part {
"all" | "*" => {
is_all = true;
break
},
other => origins.push(other.to_owned()),
}
}
if is_all {
Ok(Cors::All)
} else {
Ok(Cors::List(origins))
}
}
}
#[derive(Debug, Clone, PartialEq, Copy, clap::ValueEnum)]
#[value(rename_all = "lower")]
pub enum Database {
#[cfg(feature = "rocksdb")]
RocksDb,
ParityDb,
Auto,
#[value(name = "paritydb-experimental")]
ParityDbDeprecated,
}
impl Database {
pub const fn variants() -> &'static [&'static str] {
&[
#[cfg(feature = "rocksdb")]
"rocksdb",
"paritydb",
"paritydb-experimental",
"auto",
]
}
}
#[allow(missing_docs)]
#[derive(Debug, Clone, ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum OffchainWorkerEnabled {
Always,
Never,
WhenAuthority,
}
#[derive(Debug, Clone, Copy, ValueEnum, PartialEq)]
#[value(rename_all = "kebab-case")]
pub enum SyncMode {
Full,
Fast,
FastUnsafe,
Warp,
}
impl Into<sc_network::config::SyncMode> for SyncMode {
fn into(self) -> sc_network::config::SyncMode {
match self {
SyncMode::Full => sc_network::config::SyncMode::Full,
SyncMode::Fast => sc_network::config::SyncMode::LightState {
skip_proofs: false,
storage_chain_mode: false,
},
SyncMode::FastUnsafe => sc_network::config::SyncMode::LightState {
skip_proofs: true,
storage_chain_mode: false,
},
SyncMode::Warp => sc_network::config::SyncMode::Warp,
}
}
}
#[derive(Debug, Clone, Copy, ValueEnum, PartialEq)]
#[value(rename_all = "lower")]
pub enum NetworkBackendType {
Libp2p,
Litep2p,
}
impl Into<sc_network::config::NetworkBackendType> for NetworkBackendType {
fn into(self) -> sc_network::config::NetworkBackendType {
match self {
Self::Libp2p => sc_network::config::NetworkBackendType::Libp2p,
Self::Litep2p => sc_network::config::NetworkBackendType::Litep2p,
}
}
}