From 2ad43a56bad4ff99ce36ca35366eba517ae50e00 Mon Sep 17 00:00:00 2001 From: Uncle Stretch Date: Tue, 29 Jul 2025 14:26:12 +0300 Subject: [PATCH] rustfmt chain-spec-builder and fix typos Signed-off-by: Uncle Stretch --- utils/chain-spec-builder/Cargo.toml | 2 +- utils/chain-spec-builder/bin/main.rs | 58 ++++++++++++++-------------- utils/chain-spec-builder/src/lib.rs | 23 ++++++----- 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/utils/chain-spec-builder/Cargo.toml b/utils/chain-spec-builder/Cargo.toml index 3e30929..99a2039 100644 --- a/utils/chain-spec-builder/Cargo.toml +++ b/utils/chain-spec-builder/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ghost-staging-chain-spec-builder" description = "Utility for building chain-specification files for Ghost and Casper runtimes on `sp-genesis-builder`" -version = "1.6.1" +version = "1.6.2" build = "build.rs" authors.workspace = true edition.workspace = true diff --git a/utils/chain-spec-builder/bin/main.rs b/utils/chain-spec-builder/bin/main.rs index a32710a..ff58ec2 100644 --- a/utils/chain-spec-builder/bin/main.rs +++ b/utils/chain-spec-builder/bin/main.rs @@ -1,20 +1,18 @@ use chain_spec_builder::{ - generate_chain_spec_for_runtime, ChainSpecBuilder, ChainSpecBuilderCmd, - ConvertToRawCmd, DisplayPresetCmd, ListPresetsCmd, UpdateCodeCmd, - VerifyCmd, + generate_chain_spec_for_runtime, ChainSpecBuilder, ChainSpecBuilderCmd, ConvertToRawCmd, + DisplayPresetCmd, ListPresetsCmd, UpdateCodeCmd, VerifyCmd, }; use clap::Parser; -use sc_chain_spec::{ - update_code_in_json_chain_spec, GenericChainSpec, - GenesisConfigBuilderRuntimeCaller, -}; use ghost_staging_chain_spec_builder as chain_spec_builder; +use sc_chain_spec::{ + update_code_in_json_chain_spec, GenericChainSpec, GenesisConfigBuilderRuntimeCaller, +}; use std::fs; fn main() { match inner_main() { Err(e) => eprintln!("{}", format!("{e}")), - _ => {}, + _ => {} } } @@ -28,16 +26,16 @@ fn inner_main() -> Result<(), String> { ChainSpecBuilderCmd::Create(cmd) => { let chain_spec_json = generate_chain_spec_for_runtime(&cmd)?; fs::write(chain_spec_path, chain_spec_json).map_err(|err| err.to_string())?; - }, + } ChainSpecBuilderCmd::UpdateCode(UpdateCodeCmd { ref input_chain_spec, ref runtime_wasm_path, }) => { let chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; - let mut chain_spec_json = serde_json::from_str::( - &chain_spec.as_json(false)? - ).map_err(|e| format!("Conversion to json failed: {e}"))?; + let mut chain_spec_json = + serde_json::from_str::(&chain_spec.as_json(false)?) + .map_err(|e| format!("Conversion to json failed: {e}"))?; update_code_in_json_chain_spec( &mut chain_spec_json, &fs::read(runtime_wasm_path.as_path()) @@ -47,27 +45,31 @@ fn inner_main() -> Result<(), String> { let chain_spec_json = serde_json::to_string_pretty(&chain_spec_json) .map_err(|e| format!("to pretty failed: {e}"))?; fs::write(chain_spec_path, chain_spec_json).map_err(|err| err.to_string())?; - }, - ChainSpecBuilderCmd::ConvertToRaw(ConvertToRawCmd { ref input_chain_spec }) => { + } + ChainSpecBuilderCmd::ConvertToRaw(ConvertToRawCmd { + ref input_chain_spec, + }) => { let chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; - let chain_spec_json = serde_json::from_str::( - &chain_spec.as_json(false)? - ).map_err(|e| format!("Conversion to json failed: {e}"))?; + let chain_spec_json = + serde_json::from_str::(&chain_spec.as_json(false)?) + .map_err(|e| format!("Conversion to json failed: {e}"))?; let chain_spec_json = serde_json::to_string_pretty(&chain_spec_json) .map_err(|e| format!("to pretty failed: {e}"))?; fs::write(chain_spec_path, chain_spec_json).map_err(|err| err.to_string())?; - }, - ChainSpecBuilderCmd::Verify(VerifyCmd { ref input_chain_spec }) => { + } + ChainSpecBuilderCmd::Verify(VerifyCmd { + ref input_chain_spec, + }) => { let chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; let _ = serde_json::from_str::(&chain_spec.as_json(true)?) .map_err(|e| format!("Conversion to json failed: {e}"))?; - }, + } ChainSpecBuilderCmd::ListPresets(ListPresetsCmd { runtime_wasm_path }) => { let code = fs::read(runtime_wasm_path.as_path()) .map_err(|e| format!("wasm blob shall be readable {e}"))?; - let caller: GenesisConfigBuilderRuntimeCaller = + let caller: GenesisConfigBuilderRuntimeCaller = GenesisConfigBuilderRuntimeCaller::new(&code[..]); let presets = caller .preset_names() @@ -77,26 +79,26 @@ fn inner_main() -> Result<(), String> { .map(|preset| { String::from( TryInto::<&str>::try_into(&preset) - .unwrap_or_else(|_| "cannot display preset id") - .to_string(), + .unwrap_or_else(|_| "cannot display preset id") + .to_string(), ) }) .collect(); println!("{}", serde_json::json!({"presets": presets}).to_string()); - }, - ChainSpecBuilderCmd::DisplayPreset(DisplayPresetCmd { - runtime_wasm_path, + } + ChainSpecBuilderCmd::DisplayPreset(DisplayPresetCmd { + runtime_wasm_path, preset_name, }) => { let code = fs::read(runtime_wasm_path.as_path()) .map_err(|e| format!("wasm blob shall be readable {e}"))?; - let caller: GenesisConfigBuilderRuntimeCaller = + let caller: GenesisConfigBuilderRuntimeCaller = GenesisConfigBuilderRuntimeCaller::new(&code[..]); let presets = caller .get_named_preset(preset_name.as_ref()) .map_err(|e| format!("getting default config from runtime should work: {e}"))?; println!("{presets}"); - }, + } }; Ok(()) diff --git a/utils/chain-spec-builder/src/lib.rs b/utils/chain-spec-builder/src/lib.rs index 995adf0..fc9b00d 100644 --- a/utils/chain-spec-builder/src/lib.rs +++ b/utils/chain-spec-builder/src/lib.rs @@ -1,10 +1,8 @@ use std::{fs, path::PathBuf}; use clap::{Parser, Subcommand}; +use sc_chain_spec::{ChainType, GenericChainSpec, GenesisConfigBuilderRuntimeCaller}; use serde_json::Value; -use sc_chain_spec::{ - ChainType, GenericChainSpec, GenesisConfigBuilderRuntimeCaller, -}; #[derive(Debug, Parser)] #[command(rename_all = "kebab-case", version, about)] @@ -94,7 +92,7 @@ struct NamedPresetCmd { /// The code field of the chain spec will be updated with the runtime provided /// in the command line. The operation supports both plain and raw formats. /// -/// This command does not update chain-spec file in-place. The result of this +/// This command does not update chain-spec file in-place. The result of this /// command will be stored in a file given as `-c/--chain-spec-path` command /// line argument. #[derive(Parser, Debug, Clone)] @@ -107,7 +105,7 @@ pub struct UpdateCodeCmd { pub runtime_wasm_path: PathBuf, } -/// Converts the given chain spec into raw format. +/// Converts the given chain spec into raw format. #[derive(Parser, Debug, Clone)] pub struct ConvertToRawCmd { /// Chain spec to be converted. @@ -137,7 +135,7 @@ pub struct DisplayPresetCmd { /// Verifies the provided input chain spec. /// /// Silently checks if given input chain spec can be converted to raw. It allows -/// to check if all `RuntimeGenesisConfig` fields are properly initialized and +/// to check if all `RuntimeGenesisConfig` fields are properly initialized and /// if the json does not contain invalid fields. #[derive(Parser, Debug, Clone)] pub struct VerifyCmd { @@ -156,22 +154,23 @@ pub fn generate_chain_spec_for_runtime(cmd: &CreateCmd) -> Result - builder.with_genesis_config_preset_name(&preset_name), + GenesisBuildAction::NamedPreset(NamedPresetCmd { ref preset_name }) => { + builder.with_genesis_config_preset_name(&preset_name) + } GenesisBuildAction::Patch(PatchCmd { ref patch_path }) => { let patch = fs::read(patch_path.as_path()) .map_err(|e| format!("patch file {patch_path:?} shall be readable: {e}"))?; builder.with_genesis_config_patch(serde_json::from_slice::(&patch[..]).map_err( |e| format!("patch file {patch_path:?} shall contain a valid json: {e}"), )?) - }, + } GenesisBuildAction::Full(FullCmd { ref config_path }) => { let config = fs::read(config_path.as_path()) .map_err(|e| format!("config file {config_path:?} shall be readable: {e}"))?; builder.with_genesis_config(serde_json::from_slice::(&config[..]).map_err( |e| format!("config file {config_path:?} shall contain a valid json: {e}"), )?) - }, + } GenesisBuildAction::Default(DefaultCmd {}) => { let caller: GenesisConfigBuilderRuntimeCaller = GenesisConfigBuilderRuntimeCaller::new(&code[..]); @@ -179,7 +178,7 @@ pub fn generate_chain_spec_for_runtime(cmd: &CreateCmd) -> Result Result chain_spec.as_json(false), } }