referrerpolicy=no-referrer-when-downgrade

solochain_template_runtime/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3#[cfg(feature = "std")]
4include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
5
6pub mod apis;
7#[cfg(feature = "runtime-benchmarks")]
8mod benchmarks;
9pub mod configs;
10
11extern crate alloc;
12use alloc::vec::Vec;
13use sp_runtime::{
14	generic, impl_opaque_keys,
15	traits::{BlakeTwo256, IdentifyAccount, Verify},
16	MultiAddress, MultiSignature,
17};
18use sp_version::RuntimeVersion;
19
20pub use frame_system::Call as SystemCall;
21pub use pallet_balances::Call as BalancesCall;
22pub use pallet_timestamp::Call as TimestampCall;
23#[cfg(any(feature = "std", test))]
24pub use sp_runtime::BuildStorage;
25
26pub mod genesis_config_presets;
27
28/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
29/// the specifics of the runtime. They can then be made to be agnostic over specific formats
30/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
31/// to even the core data structures.
32pub mod opaque {
33	use super::*;
34	use sp_runtime::{
35		generic,
36		traits::{BlakeTwo256, Hash as HashT},
37	};
38
39	pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;
40
41	/// Opaque block header type.
42	pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
43	/// Opaque block type.
44	pub type Block = generic::Block<Header, UncheckedExtrinsic>;
45	/// Opaque block identifier type.
46	pub type BlockId = generic::BlockId<Block>;
47	/// Opaque block hash type.
48	pub type Hash = <BlakeTwo256 as HashT>::Output;
49}
50
51impl_opaque_keys! {
52	pub struct SessionKeys {
53		pub aura: Aura,
54		pub grandpa: Grandpa,
55	}
56}
57
58// To learn more about runtime versioning, see:
59// https://docs.substrate.io/main-docs/build/upgrade#runtime-versioning
60#[sp_version::runtime_version]
61pub const VERSION: RuntimeVersion = RuntimeVersion {
62	spec_name: alloc::borrow::Cow::Borrowed("solochain-template-runtime"),
63	impl_name: alloc::borrow::Cow::Borrowed("solochain-template-runtime"),
64	authoring_version: 1,
65	// The version of the runtime specification. A full node will not attempt to use its native
66	//   runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`,
67	//   `spec_version`, and `authoring_version` are the same between Wasm and native.
68	// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
69	//   the compatible custom types.
70	spec_version: 100,
71	impl_version: 1,
72	apis: apis::RUNTIME_API_VERSIONS,
73	transaction_version: 1,
74	system_version: 1,
75};
76
77mod block_times {
78	/// This determines the average expected block time that we are targeting. Blocks will be
79	/// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by
80	/// `pallet_timestamp` which is in turn picked up by `pallet_aura` to implement `fn
81	/// slot_duration()`.
82	///
83	/// Change this to adjust the block time.
84	pub const MILLI_SECS_PER_BLOCK: u64 = 6000;
85
86	// NOTE: Currently it is not possible to change the slot duration after the chain has started.
87	// Attempting to do so will brick block production.
88	pub const SLOT_DURATION: u64 = MILLI_SECS_PER_BLOCK;
89}
90pub use block_times::*;
91
92// Time is measured by number of blocks.
93pub const MINUTES: BlockNumber = 60_000 / (MILLI_SECS_PER_BLOCK as BlockNumber);
94pub const HOURS: BlockNumber = MINUTES * 60;
95pub const DAYS: BlockNumber = HOURS * 24;
96
97pub const BLOCK_HASH_COUNT: BlockNumber = 2400;
98
99// Unit = the base number of indivisible units for balances
100pub const UNIT: Balance = 1_000_000_000_000;
101pub const MILLI_UNIT: Balance = 1_000_000_000;
102pub const MICRO_UNIT: Balance = 1_000_000;
103
104/// Existential deposit.
105pub const EXISTENTIAL_DEPOSIT: Balance = MILLI_UNIT;
106
107/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
108pub type Signature = MultiSignature;
109
110/// Some way of identifying an account on the chain. We intentionally make it equivalent
111/// to the public key of our transaction signing scheme.
112pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
113
114/// Balance of an account.
115pub type Balance = u128;
116
117/// Index of a transaction in the chain.
118pub type Nonce = u32;
119
120/// A hash of some data used by the chain.
121pub type Hash = sp_core::H256;
122
123/// An index to a block.
124pub type BlockNumber = u32;
125
126/// The address format for describing accounts.
127pub type Address = MultiAddress<AccountId, ()>;
128
129/// Block header type as expected by this runtime.
130pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
131
132/// Block type as expected by this runtime.
133pub type Block = generic::Block<Header, UncheckedExtrinsic>;
134
135/// A Block signed with a Justification
136pub type SignedBlock = generic::SignedBlock<Block>;
137
138/// BlockId type as expected by this runtime.
139pub type BlockId = generic::BlockId<Block>;
140
141/// The `TransactionExtension` to the basic transaction logic.
142pub type TxExtension = (
143	frame_system::AuthorizeCall<Runtime>,
144	frame_system::CheckNonZeroSender<Runtime>,
145	frame_system::CheckSpecVersion<Runtime>,
146	frame_system::CheckTxVersion<Runtime>,
147	frame_system::CheckGenesis<Runtime>,
148	frame_system::CheckEra<Runtime>,
149	frame_system::CheckNonce<Runtime>,
150	frame_system::CheckWeight<Runtime>,
151	pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
152	frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
153	frame_system::WeightReclaim<Runtime>,
154);
155
156/// Unchecked extrinsic type as expected by this runtime.
157pub type UncheckedExtrinsic =
158	generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
159
160/// The payload being signed in transactions.
161pub type SignedPayload = generic::SignedPayload<RuntimeCall, TxExtension>;
162
163/// Executive: handles dispatch to the various modules.
164pub type Executive = frame_executive::Executive<
165	Runtime,
166	Block,
167	frame_system::ChainContext<Runtime>,
168	Runtime,
169	AllPalletsWithSystem,
170>;
171
172// Create the runtime by composing the FRAME pallets that were previously configured.
173#[frame_support::runtime]
174mod runtime {
175	#[runtime::runtime]
176	#[runtime::derive(
177		RuntimeCall,
178		RuntimeEvent,
179		RuntimeError,
180		RuntimeOrigin,
181		RuntimeFreezeReason,
182		RuntimeHoldReason,
183		RuntimeSlashReason,
184		RuntimeLockId,
185		RuntimeTask,
186		RuntimeViewFunction
187	)]
188	pub struct Runtime;
189
190	#[runtime::pallet_index(0)]
191	pub type System = frame_system;
192
193	#[runtime::pallet_index(1)]
194	pub type Timestamp = pallet_timestamp;
195
196	#[runtime::pallet_index(2)]
197	pub type Aura = pallet_aura;
198
199	#[runtime::pallet_index(3)]
200	pub type Grandpa = pallet_grandpa;
201
202	#[runtime::pallet_index(4)]
203	pub type Balances = pallet_balances;
204
205	#[runtime::pallet_index(5)]
206	pub type TransactionPayment = pallet_transaction_payment;
207
208	#[runtime::pallet_index(6)]
209	pub type Sudo = pallet_sudo;
210
211	// Include the custom logic from the pallet-template in the runtime.
212	#[runtime::pallet_index(7)]
213	pub type Template = pallet_template;
214}