Skip to main content

pezstaging_teyrchain_info/
lib.rs

1// Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute
2// This file is part of Pezcumulus.
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 Pezpallet that injects a TeyrchainId into Runtime storage from
18
19#![cfg_attr(not(feature = "std"), no_std)]
20
21pub use pezpallet::*;
22
23#[pezframe_support::pezpallet]
24pub mod pezpallet {
25	use pezcumulus_primitives_core::ParaId;
26	use pezframe_support::pezpallet_prelude::*;
27	use pezframe_system::pezpallet_prelude::*;
28
29	#[pezpallet::pezpallet]
30	pub struct Pezpallet<T>(_);
31
32	#[pezpallet::config]
33	pub trait Config: pezframe_system::Config {}
34
35	#[pezpallet::hooks]
36	impl<T: Config> Hooks<BlockNumberFor<T>> for Pezpallet<T> {}
37
38	#[pezpallet::call]
39	impl<T: Config> Pezpallet<T> {}
40
41	#[pezpallet::genesis_config]
42	pub struct GenesisConfig<T: Config> {
43		#[serde(skip)]
44		pub _config: core::marker::PhantomData<T>,
45		pub teyrchain_id: ParaId,
46	}
47
48	impl<T: Config> Default for GenesisConfig<T> {
49		fn default() -> Self {
50			Self { teyrchain_id: 100.into(), _config: Default::default() }
51		}
52	}
53
54	#[pezpallet::genesis_build]
55	impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
56		fn build(&self) {
57			TeyrchainId::<T>::put(self.teyrchain_id);
58		}
59	}
60
61	#[pezpallet::type_value]
62	pub(super) fn DefaultForTeyrchainId() -> ParaId {
63		100.into()
64	}
65
66	#[pezpallet::storage]
67	pub(super) type TeyrchainId<T: Config> =
68		StorageValue<_, ParaId, ValueQuery, DefaultForTeyrchainId>;
69
70	impl<T: Config> Get<ParaId> for Pezpallet<T> {
71		fn get() -> ParaId {
72			TeyrchainId::<T>::get()
73		}
74	}
75
76	impl<T: Config> Pezpallet<T> {
77		pub fn teyrchain_id() -> ParaId {
78			TeyrchainId::<T>::get()
79		}
80	}
81}