Skip to main content

pop_chains/new_pallet/
new_pallet_options.rs

1use clap::ValueEnum;
2use serde::Serialize;
3use std::{fmt, fmt::Formatter};
4use strum::EnumMessage as _;
5use strum_macros::{EnumIter, EnumMessage};
6
7/// This enum is used to register from the CLI which types that are kind of usual in config traits
8/// are included in the pallet
9#[derive(Debug, Copy, Clone, PartialEq, EnumIter, EnumMessage, ValueEnum, Serialize)]
10pub enum TemplatePalletConfigCommonTypes {
11	/// This type will enable your pallet to emit events.
12	#[strum(
13		message = "RuntimeEvent",
14		detailed_message = "This type will enable your pallet to emit events."
15	)]
16	RuntimeEvent,
17	/// This type will be helpful if your pallet needs to deal with the outer RuntimeOrigin enum,
18	/// or if your pallet needs to use custom origins. Note: If you have run the command using -o,
19	/// this type will be added anyway.
20	#[strum(
21		message = "RuntimeOrigin",
22		detailed_message = "This type will be helpful if your pallet needs to deal with the outer RuntimeOrigin enum, or if your pallet needs to use custom origins. Note: If you have run the command using -o, this type will be added anyway."
23	)]
24	RuntimeOrigin,
25	/// This type will allow your pallet to interact with the native currency of the blockchain.
26	#[strum(
27		message = "Currency",
28		detailed_message = "This type will allow your pallet to interact with the native currency of the blockchain."
29	)]
30	Currency,
31}
32
33impl fmt::Display for TemplatePalletConfigCommonTypes {
34	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
35		write!(f, "{}", self.get_message().unwrap_or("Unknown"))
36	}
37}
38
39/// This enum is used to determine which storage shape has a storage item in the pallet
40#[derive(Debug, Copy, Clone, PartialEq, EnumIter, EnumMessage, ValueEnum, Serialize)]
41pub enum TemplatePalletStorageTypes {
42	/// A storage value is a single value of a given type stored on-chain.
43	#[strum(
44		message = "StorageValue",
45		detailed_message = "A storage value is a single value of a given type stored on-chain."
46	)]
47	StorageValue,
48	/// A storage map is a mapping of keys to values of a given type stored on-chain.
49	#[strum(
50		message = "StorageMap",
51		detailed_message = "A storage map is a mapping of keys to values of a given type stored on-chain."
52	)]
53	StorageMap,
54	/// A wrapper around a StorageMap and a StorageValue (with the value being u32) to keep track
55	/// of how many items are in a map.
56	#[strum(
57		message = "CountedStorageMap",
58		detailed_message = "A wrapper around a StorageMap and a StorageValue (with the value being u32) to keep track of how many items are in a map."
59	)]
60	CountedStorageMap,
61	/// This structure associates a pair of keys with a value of a specified type stored on-chain.
62	#[strum(
63		message = "StorageDoubleMap",
64		detailed_message = "This structure associates a pair of keys with a value of a specified type stored on-chain."
65	)]
66	StorageDoubleMap,
67	/// This structure associates an arbitrary number of keys with a value of a specified type
68	/// stored on-chain.
69	#[strum(
70		message = "StorageNMap",
71		detailed_message = "This structure associates an arbitrary number of keys with a value of a specified type stored on-chain."
72	)]
73	StorageNMap,
74	/// A wrapper around a StorageNMap and a StorageValue (with the value being u32) to keep track
75	/// of how many items are in a map.
76	#[strum(
77		message = "CountedStorageNMap",
78		detailed_message = "A wrapper around a StorageNMap and a StorageValue (with the value being u32) to keep track of how many items are in a map."
79	)]
80	CountedStorageNMap,
81}
82
83impl fmt::Display for TemplatePalletStorageTypes {
84	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
85		write!(f, "{}", self.get_message().unwrap_or("Unknown"))
86	}
87}
88
89/// This enum is used to register from the CLI which options are selected by the user to be included
90/// in the pallet.
91#[derive(Debug, Copy, Clone, PartialEq, EnumIter, EnumMessage)]
92pub enum TemplatePalletOptions {
93	/// Uses a default configuration for the pallet's config trait.
94	#[strum(
95		message = "DefaultConfig",
96		detailed_message = "Use a default configuration for your config trait."
97	)]
98	DefaultConfig,
99	/// Adds a genesis config to the pallet.
100	#[strum(message = "GenesisConfig", detailed_message = "Add a genesis config to your pallet.")]
101	GenesisConfig,
102	/// Adds a custom origin to the pallet.
103	#[strum(message = "Custom Origin", detailed_message = "Add a custom origin to your pallet.")]
104	CustomOrigin,
105}