123#![cfg_attr(not(feature = "std"), no_std)]45#![recursion_limit="256"]678#[cfg(feature = "std")]9include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));1011use sp_std::prelude::*;12use sp_core::OpaqueMetadata;13use sp_runtime::{14 ApplyExtrinsicResult, transaction_validity::TransactionValidity, generic, create_runtime_str,15 impl_opaque_keys, MultiSignature16};17use sp_runtime::traits::{18 NumberFor, BlakeTwo256, Block as BlockT, StaticLookup, Verify, ConvertInto, IdentifyAccount19};20use sp_api::impl_runtime_apis;21use sp_consensus_aura::sr25519::AuthorityId as AuraId;22use grandpa::AuthorityList as GrandpaAuthorityList;23use grandpa::fg_primitives;24use sp_version::RuntimeVersion;25#[cfg(feature = "std")]26use sp_version::NativeVersion;272829#[cfg(any(feature = "std", test))]30pub use sp_runtime::BuildStorage;31pub use timestamp::Call as TimestampCall;32pub use balances::Call as BalancesCall;33pub use sp_runtime::{Permill, Perbill};34pub use frame_support::{35 StorageValue, construct_runtime, parameter_types,36 traits::Randomness,37 weights::Weight,38};394041pub type BlockNumber = u32;424344pub type Signature = MultiSignature;45464748pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;49505152pub type AccountIndex = u32;535455pub type Balance = u128;565758pub type Index = u32;596061pub type Hash = sp_core::H256;626364pub type DigestItem = generic::DigestItem<Hash>;656667mod template;686970717273pub mod opaque {74 use super::*;7576 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;7778 79 pub type Header = generic::Header<BlockNumber, BlakeTwo256>;80 81 pub type Block = generic::Block<Header, UncheckedExtrinsic>;82 83 pub type BlockId = generic::BlockId<Block>;8485 impl_opaque_keys! {86 pub struct SessionKeys {87 pub aura: Aura,88 pub grandpa: Grandpa,89 }90 }91}929394pub const VERSION: RuntimeVersion = RuntimeVersion {95 spec_name: create_runtime_str!("node-template"),96 impl_name: create_runtime_str!("node-template"),97 authoring_version: 1,98 spec_version: 1,99 impl_version: 1,100 apis: RUNTIME_API_VERSIONS,101};102103pub const MILLISECS_PER_BLOCK: u64 = 6000;104105pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;106107108pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);109pub const HOURS: BlockNumber = MINUTES * 60;110pub const DAYS: BlockNumber = HOURS * 24;111112113#[cfg(feature = "std")]114pub fn native_version() -> NativeVersion {115 NativeVersion {116 runtime_version: VERSION,117 can_author_with: Default::default(),118 }119}120121parameter_types! {122 pub const BlockHashCount: BlockNumber = 250;123 pub const MaximumBlockWeight: Weight = 1_000_000;124 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);125 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;126 pub const Version: RuntimeVersion = VERSION;127}128129impl system::Trait for Runtime {130 131 type AccountId = AccountId;132 133 type Call = Call;134 135 type Lookup = Indices;136 137 type Index = Index;138 139 type BlockNumber = BlockNumber;140 141 type Hash = Hash;142 143 type Hashing = BlakeTwo256;144 145 type Header = generic::Header<BlockNumber, BlakeTwo256>;146 147 type Event = Event;148 149 type Origin = Origin;150 151 type BlockHashCount = BlockHashCount;152 153 type MaximumBlockWeight = MaximumBlockWeight;154 155 type MaximumBlockLength = MaximumBlockLength;156 157 type AvailableBlockRatio = AvailableBlockRatio;158 159 type Version = Version;160 161 162 163 type ModuleToIndex = ModuleToIndex;164}165166impl aura::Trait for Runtime {167 type AuthorityId = AuraId;168}169170impl grandpa::Trait for Runtime {171 type Event = Event;172}173174impl indices::Trait for Runtime {175 176 177 type AccountIndex = AccountIndex;178 179 type ResolveHint = indices::SimpleResolveHint<Self::AccountId, Self::AccountIndex>;180 181 type IsDeadAccount = Balances;182 183 type Event = Event;184}185186parameter_types! {187 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;188}189190impl timestamp::Trait for Runtime {191 192 type Moment = u64;193 type OnTimestampSet = Aura;194 type MinimumPeriod = MinimumPeriod;195}196197parameter_types! {198 pub const ExistentialDeposit: u128 = 500;199 pub const TransferFee: u128 = 0;200 pub const CreationFee: u128 = 0;201}202203impl balances::Trait for Runtime {204 205 type Balance = Balance;206 207 type OnFreeBalanceZero = ();208 209 type OnNewAccount = Indices;210 211 type Event = Event;212 type DustRemoval = ();213 type TransferPayment = ();214 type ExistentialDeposit = ExistentialDeposit;215 type TransferFee = TransferFee;216 type CreationFee = CreationFee;217}218219parameter_types! {220 pub const TransactionBaseFee: Balance = 0;221 pub const TransactionByteFee: Balance = 1;222}223224impl transaction_payment::Trait for Runtime {225 type Currency = balances::Module<Runtime>;226 type OnTransactionPayment = ();227 type TransactionBaseFee = TransactionBaseFee;228 type TransactionByteFee = TransactionByteFee;229 type WeightToFee = ConvertInto;230 type FeeMultiplierUpdate = ();231}232233impl sudo::Trait for Runtime {234 type Event = Event;235 type Proposal = Call;236}237238239impl template::Trait for Runtime {240 type Event = Event;241}242243construct_runtime!(244 pub enum Runtime where245 Block = Block,246 NodeBlock = opaque::Block,247 UncheckedExtrinsic = UncheckedExtrinsic248 {249 System: system::{Module, Call, Storage, Config, Event},250 Timestamp: timestamp::{Module, Call, Storage, Inherent},251 Aura: aura::{Module, Config<T>, Inherent(Timestamp)},252 Grandpa: grandpa::{Module, Call, Storage, Config, Event},253 Indices: indices,254 Balances: balances,255 TransactionPayment: transaction_payment::{Module, Storage},256 Sudo: sudo,257 258 TemplateModule: template::{Module, Call, Storage, Event<T>},259 RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},260 }261);262263264pub type Address = <Indices as StaticLookup>::Source;265266pub type Header = generic::Header<BlockNumber, BlakeTwo256>;267268pub type Block = generic::Block<Header, UncheckedExtrinsic>;269270pub type SignedBlock = generic::SignedBlock<Block>;271272pub type BlockId = generic::BlockId<Block>;273274pub type SignedExtra = (275 system::CheckVersion<Runtime>,276 system::CheckGenesis<Runtime>,277 system::CheckEra<Runtime>,278 system::CheckNonce<Runtime>,279 system::CheckWeight<Runtime>,280 transaction_payment::ChargeTransactionPayment<Runtime>281);282283pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;284285pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;286287pub type Executive = frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;288289impl_runtime_apis! {290 impl sp_api::Core<Block> for Runtime {291 fn version() -> RuntimeVersion {292 VERSION293 }294295 fn execute_block(block: Block) {296 Executive::execute_block(block)297 }298299 fn initialize_block(header: &<Block as BlockT>::Header) {300 Executive::initialize_block(header)301 }302 }303304 impl sp_api::Metadata<Block> for Runtime {305 fn metadata() -> OpaqueMetadata {306 Runtime::metadata().into()307 }308 }309310 impl sp_block_builder::BlockBuilder<Block> for Runtime {311 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {312 Executive::apply_extrinsic(extrinsic)313 }314315 fn finalize_block() -> <Block as BlockT>::Header {316 Executive::finalize_block()317 }318319 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {320 data.create_extrinsics()321 }322323 fn check_inherents(324 block: Block,325 data: sp_inherents::InherentData,326 ) -> sp_inherents::CheckInherentsResult {327 data.check_extrinsics(&block)328 }329330 fn random_seed() -> <Block as BlockT>::Hash {331 RandomnessCollectiveFlip::random_seed()332 }333 }334335 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {336 fn validate_transaction(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity {337 Executive::validate_transaction(tx)338 }339 }340341 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {342 fn offchain_worker(number: NumberFor<Block>) {343 Executive::offchain_worker(number)344 }345 }346347 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {348 fn slot_duration() -> u64 {349 Aura::slot_duration()350 }351352 fn authorities() -> Vec<AuraId> {353 Aura::authorities()354 }355 }356357 impl sp_session::SessionKeys<Block> for Runtime {358 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {359 opaque::SessionKeys::generate(seed)360 }361 }362363 impl fg_primitives::GrandpaApi<Block> for Runtime {364 fn grandpa_authorities() -> GrandpaAuthorityList {365 Grandpa::grandpa_authorities()366 }367 }368}