staging_parachain_info/
lib.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3
4// Cumulus is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Cumulus is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Cumulus.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Minimal Pallet that injects a ParachainId into Runtime storage from
18
19#![cfg_attr(not(feature = "std"), no_std)]
20
21pub use pallet::*;
22
23#[frame_support::pallet]
24pub mod pallet {
25	use cumulus_primitives_core::ParaId;
26	use frame_support::pallet_prelude::*;
27	use frame_system::pallet_prelude::*;
28
29	#[pallet::pallet]
30	pub struct Pallet<T>(_);
31
32	#[pallet::config]
33	pub trait Config: frame_system::Config {}
34
35	#[pallet::hooks]
36	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
37
38	#[pallet::call]
39	impl<T: Config> Pallet<T> {}
40
41	#[pallet::genesis_config]
42	pub struct GenesisConfig<T: Config> {
43		#[serde(skip)]
44		pub _config: core::marker::PhantomData<T>,
45		pub parachain_id: ParaId,
46	}
47
48	impl<T: Config> Default for GenesisConfig<T> {
49		fn default() -> Self {
50			Self { parachain_id: 100.into(), _config: Default::default() }
51		}
52	}
53
54	#[pallet::genesis_build]
55	impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
56		fn build(&self) {
57			ParachainId::<T>::put(self.parachain_id);
58		}
59	}
60
61	#[pallet::type_value]
62	pub(super) fn DefaultForParachainId() -> ParaId {
63		100.into()
64	}
65
66	#[pallet::storage]
67	pub(super) type ParachainId<T: Config> =
68		StorageValue<_, ParaId, ValueQuery, DefaultForParachainId>;
69
70	impl<T: Config> Get<ParaId> for Pallet<T> {
71		fn get() -> ParaId {
72			ParachainId::<T>::get()
73		}
74	}
75
76	impl<T: Config> Pallet<T> {
77		pub fn parachain_id() -> ParaId {
78			ParachainId::<T>::get()
79		}
80	}
81}