-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add parachaininfo pallet (#110)
- Loading branch information
Showing
8 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ members = [ | |
"rpc", | ||
"substrate-node/node", | ||
"substrate-node/runtime", | ||
"parachain-info", | ||
] | ||
|
||
exclude = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
authors = ["Parity Technologies <[email protected]>"] | ||
edition = "2021" | ||
name = "pallet-parachain-info" | ||
version = "0.1.0" | ||
license = "LGPL-3.0" | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "3.0", default-features = false, features = ["derive"] } | ||
scale-info = { version = "2.0", default-features = false, features = ["derive"] } | ||
|
||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false } | ||
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false } | ||
|
||
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.42", default-features = false } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"codec/std", | ||
"scale-info/std", | ||
"cumulus-primitives-core/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
] | ||
try-runtime = ["frame-support/try-runtime"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2020-2021 Parity Technologies (UK) Ltd. | ||
// This file is part of Cumulus. | ||
|
||
// Cumulus is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Cumulus is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Minimal Pallet that injects a ParachainId into Runtime storage from | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
pub use pallet::*; | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use cumulus_primitives_core::ParaId; | ||
use frame_support::pallet_prelude::*; | ||
use frame_system::pallet_prelude::*; | ||
|
||
#[pallet::pallet] | ||
#[pallet::without_storage_info] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config {} | ||
|
||
#[pallet::hooks] | ||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {} | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> {} | ||
|
||
#[pallet::genesis_config] | ||
pub struct GenesisConfig { | ||
pub parachain_id: ParaId, | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
impl Default for GenesisConfig { | ||
fn default() -> Self { | ||
Self { parachain_id: 100.into() } | ||
} | ||
} | ||
|
||
#[pallet::genesis_build] | ||
impl<T: Config> GenesisBuild<T> for GenesisConfig { | ||
fn build(&self) { | ||
<ParachainId<T>>::put(&self.parachain_id); | ||
} | ||
} | ||
|
||
#[pallet::type_value] | ||
pub(super) fn DefaultForParachainId() -> ParaId { | ||
100.into() | ||
} | ||
|
||
#[pallet::storage] | ||
#[pallet::getter(fn parachain_id)] | ||
pub(super) type ParachainId<T: Config> = | ||
StorageValue<_, ParaId, ValueQuery, DefaultForParachainId>; | ||
|
||
impl<T: Config> Get<ParaId> for Pallet<T> { | ||
fn get() -> ParaId { | ||
Self::parachain_id() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters