Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add argument
  • Loading branch information
pmikolajczyk41 committed Aug 23, 2022
commit 16841caa2c9cb3130166c33fcb29fca66952bfd5
5 changes: 5 additions & 0 deletions utils/frame/try-runtime/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ use sp_runtime::{
};
use sp_state_machine::{OverlayedChanges, StateMachine, TrieBackendBuilder};
use std::{fmt::Debug, path::PathBuf, str::FromStr};
use sp_version::StateVersion;

mod commands;
pub(crate) mod parse;
Expand Down Expand Up @@ -421,6 +422,10 @@ pub struct SharedParams {
/// When enabled, the spec name check will not panic, and instead only show a warning.
#[clap(long)]
pub no_spec_name_check: bool,

/// State version that is used by the chain.
#[clap(long, default_value = "1", parse(try_from_str = parse::state_version))]
pub state_version: StateVersion,
}

/// Our `try-runtime` command.
Expand Down
11 changes: 11 additions & 0 deletions utils/frame/try-runtime/cli/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

//! Utils for parsing user input

use std::num::ParseIntError;
use sp_version::StateVersion;

pub(crate) fn hash(block_hash: &str) -> Result<String, String> {
let (block_hash, offset) = if let Some(block_hash) = block_hash.strip_prefix("0x") {
(block_hash, 2)
Expand All @@ -42,3 +45,11 @@ pub(crate) fn url(s: &str) -> Result<String, &'static str> {
Err("not a valid WS(S) url: must start with 'ws://' or 'wss://'")
}
}

pub(crate) fn state_version(s: &str) -> Result<StateVersion, &'static str> {
match s.parse::<u32>() {
Ok(0) => Ok(StateVersion::V0),
Ok(1) => Ok(StateVersion::V1),
_ => Err("State version couldn't have been parsed.")
}
}