try-runtime - support all state versions (#12089)

* Add argument

* Apply

* More verbose parsing

* fmt

* fmt again

* Invalid state version

* reuse parsing

* type mismatch
This commit is contained in:
Piotr Mikołajczyk
2022-08-27 06:56:24 +02:00
committed by GitHub
parent 75a76d967b
commit 9e5b211828
6 changed files with 25 additions and 8 deletions
@@ -17,6 +17,8 @@
//! Utils for parsing user input
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)
@@ -42,3 +44,10 @@ 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> {
s.parse::<u8>()
.map_err(|_| ())
.and_then(StateVersion::try_from)
.map_err(|_| "Invalid state version.")
}