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