pop_chains/try_runtime/
state.rs

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