Skip to content

Commit

Permalink
feat: Add parachaininfo pallet (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyli7 authored Jun 14, 2023
1 parent 458112e commit 88e9dd7
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"rpc",
"substrate-node/node",
"substrate-node/runtime",
"parachain-info",
]

exclude = [
Expand Down
26 changes: 26 additions & 0 deletions parachain-info/Cargo.toml
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"]
76 changes: 76 additions & 0 deletions parachain-info/src/lib.rs
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()
}
}
}
1 change: 1 addition & 0 deletions substrate-node/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/sub
sp-keyring = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.42" }

# These dependencies are used for the node template's RPCs
jsonrpsee = { version = "0.16.2", features = ["server"] }
Expand Down
4 changes: 4 additions & 0 deletions substrate-node/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// The Licensed Work is (c) 2022 Sygma
// SPDX-License-Identifier: LGPL-3.0-only

use cumulus_primitives_core::ParaId;
use node_template_runtime::{
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, Signature, SudoConfig,
SystemConfig, WASM_BINARY,
Expand Down Expand Up @@ -135,6 +136,8 @@ fn testnet_genesis(
endowed_accounts: Vec<AccountId>,
_enable_println: bool,
) -> GenesisConfig {
// hardcoded dummy parachainID
let id: ParaId = ParaId::from(1000);
GenesisConfig {
system: SystemConfig {
// Add Wasm runtime to storage.
Expand All @@ -154,6 +157,7 @@ fn testnet_genesis(
// Assign network admin rights.
key: Some(root_key),
},
parachain_info: node_template_runtime::ParachainInfoConfig { parachain_id: id },
transaction_payment: Default::default(),
}
}
1 change: 1 addition & 0 deletions substrate-node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ sygma-bridge = { path = "../../bridge", default-features = false }
sygma-access-segregator = { path = "../../access-segregator", default-features = false }
sygma-fee-handler-router = { path = "../../fee-handler-router", default-features = false }
sygma-runtime-api = { path = "../../runtime-api", default-features = false }
pallet-parachain-info = { path = "../../parachain-info", default-features = false }

[build-dependencies]
substrate-wasm-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
Expand Down
3 changes: 3 additions & 0 deletions substrate-node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ impl frame_system::Config for Runtime {

impl pallet_insecure_randomness_collective_flip::Config for Runtime {}

impl pallet_parachain_info::Config for Runtime {}

impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
type DisabledValidators = ();
Expand Down Expand Up @@ -748,6 +750,7 @@ construct_runtime!(
SygmaBasicFeeHandler: sygma_basic_feehandler::{Pallet, Call, Storage, Event<T>} = 10,
SygmaBridge: sygma_bridge::{Pallet, Call, Storage, Event<T>} = 11,
SygmaFeeHandlerRouter: sygma_fee_handler_router::{Pallet, Call, Storage, Event<T>} = 12,
ParachainInfo: pallet_parachain_info::{Pallet, Storage, Config} = 20,
}
);

Expand Down

0 comments on commit 88e9dd7

Please sign in to comment.