Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions substrate/bin/utils/chain-spec-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
//! [sp-genesis-builder-list]: ../sp_genesis_builder/trait.GenesisBuilder.html#method.preset_names
//! [sp-genesis-builder-get-preset]: ../sp_genesis_builder/trait.GenesisBuilder.html#method.get_preset

use std::{fs, path::PathBuf};
use std::{fs, path::PathBuf, str::FromStr};

use clap::{Parser, Subcommand};
use sc_chain_spec::{GenericChainSpec, GenesisConfigBuilderRuntimeCaller};
Expand Down Expand Up @@ -154,6 +154,9 @@ pub struct CreateCmd {
/// The chain id.
#[arg(long, short = 'i', default_value = "custom")]
chain_id: String,
/// The chain type.
#[arg(long, short = 't', default_value = "Live")]
chain_type: String,
/// The path to runtime wasm blob.
#[arg(long, short)]
runtime_wasm_path: PathBuf,
Expand Down Expand Up @@ -256,10 +259,13 @@ pub fn generate_chain_spec_for_runtime(cmd: &CreateCmd) -> Result<String, String
let code = fs::read(cmd.runtime_wasm_path.as_path())
.map_err(|e| format!("wasm blob shall be readable {e}"))?;

let chain_type = sc_chain_spec::ChainType::from_str(&cmd.chain_type[..])
.map_err(|_| "chain type should be valid".to_string())?;

let builder = GenericChainSpec::<()>::builder(&code[..], Default::default())
.with_name(&cmd.chain_name[..])
.with_id(&cmd.chain_id[..])
.with_chain_type(sc_chain_spec::ChainType::Live);
.with_chain_type(chain_type);

let builder = match cmd.action {
GenesisBuildAction::NamedPreset(NamedPresetCmd { ref preset_name }) =>
Expand Down
15 changes: 15 additions & 0 deletions substrate/client/chain-spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ mod genesis_block;
mod genesis_config_builder;
pub mod json_patch;

use std::str::FromStr;

pub use self::{
chain_spec::{
update_code_in_json_chain_spec, ChainSpec as GenericChainSpec, ChainSpecBuilder,
Expand Down Expand Up @@ -370,6 +372,19 @@ impl Default for ChainType {
}
}

impl FromStr for ChainType {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"Development" => ChainType::Development,
"Local" => ChainType::Local,
"Live" => ChainType::Live,
_ => ChainType::Custom(s.to_string()),
})
}
}

/// Arbitrary properties defined in chain spec as a JSON object
pub type Properties = serde_json::map::Map<String, serde_json::Value>;

Expand Down