pop_chains/try_runtime/
state.rs

1// SPDX-License-Identifier: GPL-3.0
2
3use serde::Serialize;
4use std::path::PathBuf;
5use strum::{Display, EnumDiscriminants};
6use strum_macros::{AsRefStr, EnumMessage, EnumString, VariantArray};
7
8/// The runtime *state*.
9#[derive(Clone, Debug, clap::Subcommand, EnumDiscriminants, Serialize)]
10#[strum_discriminants(derive(AsRefStr, EnumString, EnumMessage, VariantArray, Display))]
11#[strum_discriminants(name(StateCommand))]
12pub enum State {
13	/// A live chain.
14	#[strum_discriminants(strum(
15		serialize = "live",
16		message = "Live",
17		detailed_message = "Run the migrations on top of live state.",
18	))]
19	Live(LiveState),
20
21	/// A state snapshot.
22	#[strum_discriminants(strum(
23		serialize = "snap",
24		message = "Snapshot",
25		detailed_message = "Run the migrations on top of a chain snapshot."
26	))]
27	Snap {
28		/// Path to the snapshot file.
29		#[clap(short = 'p', long = "path", alias = "snapshot-path")]
30		path: Option<PathBuf>,
31	},
32}
33
34/// A `Live` variant for [`State`]
35#[derive(Debug, Default, Clone, clap::Args, Serialize)]
36pub struct LiveState {
37	/// The url to connect to.
38	#[arg(
39		short,
40		long,
41		value_parser = super::parse::url,
42	)]
43	pub uri: Option<String>,
44
45	/// The block hash at which to fetch the state.
46	///
47	/// If not provided the latest finalised head is used.
48	#[arg(
49		short,
50		long,
51		value_parser = super::parse::hash,
52	)]
53	pub at: Option<String>,
54
55	/// A pallet to scrape. Can be provided multiple times. If empty, entire chain state will
56	/// be scraped.
57	///
58	/// This is equivalent to passing `xx_hash_64(pallet)` to `--hashed_prefixes`.
59	#[arg(short, long, num_args = 1..)]
60	pub pallet: Vec<String>,
61
62	/// Storage entry key prefixes to scrape and inject into the test externalities. Pass as 0x
63	/// prefixed hex strings. By default, all keys are scraped and included.
64	#[arg(long = "prefix", value_parser = super::parse::hash, num_args = 1..)]
65	pub hashed_prefixes: Vec<String>,
66
67	/// Fetch the child-keys.
68	///
69	/// Default is `false`, if `--pallets` are specified, `true` otherwise. In other
70	/// words, if you scrape the whole state the child tree data is included out of the box.
71	/// Otherwise, it must be enabled explicitly using this flag.
72	#[arg(long)]
73	pub child_tree: bool,
74}