rustfmt chain-spec-builder and fix typos

Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
Uncle Stretch
2025-07-29 14:26:12 +03:00
parent 6d06fcf9a0
commit 2ad43a56ba
3 changed files with 42 additions and 41 deletions

View File

@@ -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<String, String
.with_chain_type(ChainType::Live);
let builder = match cmd.action {
GenesisBuildAction::NamedPreset(NamedPresetCmd { ref preset_name }) =>
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::<Value>(&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::<Value>(&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<String, String
.get_default_config()
.map_err(|e| format!("getting default config from runtime should work: {e}"))?;
builder.with_genesis_config(default_config)
},
}
};
let chain_spec = builder.build();
@@ -190,7 +189,7 @@ pub fn generate_chain_spec_for_runtime(cmd: &CreateCmd) -> Result<String, String
chain_spec.as_json(true)?;
println!("Genesis config verification: OK");
chain_spec.as_json(false)
},
}
(false, false) => chain_spec.as_json(false),
}
}