Skip to main content

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		#[serde(skip_serializing)]
30		#[clap(short = 'p', long = "path", alias = "snapshot-path")]
31		path: Option<PathBuf>,
32	},
33}
34
35/// A `Live` variant for [`State`]
36#[derive(Debug, Default, Clone, clap::Args, Serialize)]
37pub struct LiveState {
38	/// The url to connect to.
39	#[arg(
40		short,
41		long,
42		value_parser = super::parse::url,
43	)]
44	pub uri: Option<String>,
45
46	/// The block hash at which to fetch the state.
47	///
48	/// If not provided the latest finalised head is used.
49	#[arg(
50		short,
51		long,
52		value_parser = super::parse::hash,
53	)]
54	pub at: Option<String>,
55
56	/// A pallet to scrape. Can be provided multiple times. If empty, entire chain state will
57	/// be scraped.
58	///
59	/// This is equivalent to passing `xx_hash_64(pallet)` to `--hashed_prefixes`.
60	#[arg(short, long, num_args = 1..)]
61	pub pallet: Vec<String>,
62
63	/// Storage entry key prefixes to scrape and inject into the test externalities. Pass as 0x
64	/// prefixed hex strings. By default, all keys are scraped and included.
65	#[arg(long = "prefix", value_parser = super::parse::hash, num_args = 1..)]
66	pub hashed_prefixes: Vec<String>,
67
68	/// Fetch the child-keys.
69	///
70	/// Default is `false`, if `--pallets` are specified, `true` otherwise. In other
71	/// words, if you scrape the whole state the child tree data is included out of the box.
72	/// Otherwise, it must be enabled explicitly using this flag.
73	#[arg(long)]
74	pub child_tree: bool,
75}