referrerpolicy=no-referrer-when-downgrade

staging_parachain_info/
lib.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3// SPDX-License-Identifier: Apache-2.0
4
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// 	http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
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}