referrerpolicy=no-referrer-when-downgrade

chain_spec_guide_runtime/
runtime.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! A minimal runtime that shows runtime genesis state.
19
20// Make the WASM binary available.
21#[cfg(feature = "std")]
22include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
23
24use crate::{
25	pallets::{pallet_bar, pallet_foo},
26	presets::*,
27};
28use alloc::{vec, vec::Vec};
29use frame::{
30	deps::frame_support::{
31		genesis_builder_helper::{build_state, get_preset},
32		runtime,
33	},
34	prelude::*,
35	runtime::{apis, prelude::*},
36};
37use sp_genesis_builder::PresetId;
38
39/// The runtime version.
40#[runtime_version]
41pub const VERSION: RuntimeVersion = RuntimeVersion {
42	spec_name: alloc::borrow::Cow::Borrowed("minimal-template-runtime"),
43	impl_name: alloc::borrow::Cow::Borrowed("minimal-template-runtime"),
44	authoring_version: 1,
45	spec_version: 0,
46	impl_version: 1,
47	apis: RUNTIME_API_VERSIONS,
48	transaction_version: 1,
49	system_version: 1,
50};
51
52/// The signed extensions that are added to the runtime.
53type SignedExtra = ();
54
55// Composes the runtime by adding all the used pallets and deriving necessary types.
56#[runtime]
57mod runtime {
58	/// The main runtime type.
59	#[runtime::runtime]
60	#[runtime::derive(
61		RuntimeCall,
62		RuntimeEvent,
63		RuntimeError,
64		RuntimeOrigin,
65		RuntimeTask,
66		RuntimeViewFunction
67	)]
68	pub struct Runtime;
69
70	/// Mandatory system pallet that should always be included in a FRAME runtime.
71	#[runtime::pallet_index(0)]
72	pub type System = frame_system;
73
74	/// Sample pallet 1
75	#[runtime::pallet_index(1)]
76	pub type Bar = pallet_bar;
77
78	/// Sample pallet 2
79	#[runtime::pallet_index(2)]
80	pub type Foo = pallet_foo;
81}
82
83parameter_types! {
84	pub const Version: RuntimeVersion = VERSION;
85}
86
87/// Implements the types required for the system pallet.
88#[derive_impl(frame_system::config_preludes::SolochainDefaultConfig)]
89impl frame_system::Config for Runtime {
90	type Block = Block;
91	type Version = Version;
92}
93
94impl pallet_bar::Config for Runtime {}
95impl pallet_foo::Config for Runtime {}
96
97type Block = frame::runtime::types_common::BlockOf<Runtime, SignedExtra>;
98type Header = HeaderFor<Runtime>;
99
100#[docify::export(runtime_impl)]
101impl_runtime_apis! {
102	impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
103		fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
104			build_state::<RuntimeGenesisConfig>(config)
105		}
106
107		fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
108			get_preset::<RuntimeGenesisConfig>(id, get_builtin_preset)
109		}
110
111		fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
112			vec![
113				PresetId::from(PRESET_1),
114				PresetId::from(PRESET_2),
115				PresetId::from(PRESET_3),
116				PresetId::from(PRESET_4),
117				PresetId::from(PRESET_INVALID)
118			]
119		}
120	}
121
122	impl apis::Core<Block> for Runtime {
123		fn version() -> RuntimeVersion { VERSION }
124		fn execute_block(_: Block) { }
125		fn initialize_block(_: &Header) -> ExtrinsicInclusionMode { ExtrinsicInclusionMode::default() }
126	}
127}