pop_chains/try_runtime/
shared_parameters.rs1use super::parse::state_version;
19use sc_cli::{
20 DEFAULT_WASM_EXECUTION_METHOD, DEFAULT_WASMTIME_INSTANTIATION_STRATEGY, WasmExecutionMethod,
21 WasmtimeInstantiationStrategy,
22};
23use serde::Serialize;
24use sp_runtime::StateVersion;
25use std::{path::PathBuf, str::FromStr};
26
27const SHARED_PARAMS: [&str; 7] = [
29 "--runtime",
30 "--disable-spec-name-check",
31 "--wasm-execution",
32 "--wasm-instantiation-strategy",
33 "--heap-pages",
34 "--export-proof",
35 "--overwrite-state-version",
36];
37
38#[derive(Debug, Clone, clap::Parser, Serialize)]
40#[group(skip)]
41pub struct SharedParams {
42 #[serde(skip_serializing)]
51 #[arg(long, default_value = "existing")]
52 pub runtime: Runtime,
53
54 #[clap(long, default_value = "false", default_missing_value = "true")]
56 pub disable_spec_name_check: bool,
57
58 #[serde(skip_serializing)]
60 #[arg(
61 long = "wasm-execution",
62 value_name = "METHOD",
63 value_enum,
64 ignore_case = true,
65 default_value_t = DEFAULT_WASM_EXECUTION_METHOD,
66 )]
67 pub wasm_method: WasmExecutionMethod,
68
69 #[serde(skip_serializing)]
73 #[arg(
74 long = "wasm-instantiation-strategy",
75 value_name = "STRATEGY",
76 default_value_t = DEFAULT_WASMTIME_INSTANTIATION_STRATEGY,
77 value_enum,
78 )]
79 pub wasmtime_instantiation_strategy: WasmtimeInstantiationStrategy,
80
81 #[clap(long)]
85 pub export_proof: Option<PathBuf>,
86
87 #[serde(skip_serializing)]
91 #[arg(long, value_parser = state_version)]
92 pub overwrite_state_version: Option<StateVersion>,
93}
94
95impl Default for SharedParams {
96 fn default() -> Self {
97 SharedParams {
98 runtime: Runtime::Existing,
99 disable_spec_name_check: false,
100 wasm_method: DEFAULT_WASM_EXECUTION_METHOD,
101 wasmtime_instantiation_strategy: DEFAULT_WASMTIME_INSTANTIATION_STRATEGY,
102 export_proof: None,
103 overwrite_state_version: None,
104 }
105 }
106}
107
108impl SharedParams {
109 pub fn has_argument(arg: &str) -> bool {
111 SHARED_PARAMS.iter().any(|a| arg.starts_with(a))
112 }
113}
114
115#[derive(Debug, Clone, Serialize)]
117pub enum Runtime {
118 Path(PathBuf),
122
123 Existing,
128}
129
130impl FromStr for Runtime {
131 type Err = String;
132
133 fn from_str(s: &str) -> Result<Self, Self::Err> {
134 Ok(match s.to_lowercase().as_ref() {
135 "existing" => Runtime::Existing,
136 x => Runtime::Path(x.into()),
137 })
138 }
139}
140
141#[cfg(test)]
142mod tests {
143 use super::*;
144
145 #[test]
146 fn is_shared_params_works() {
147 assert!(SHARED_PARAMS.into_iter().all(SharedParams::has_argument));
148 }
149}