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 rstd::prelude::*;12use primitives::{OpaqueMetadata, crypto::key_types};13use sr_primitives::{14 ApplyResult, transaction_validity::TransactionValidity, generic, create_runtime_str,15 impl_opaque_keys, AnySignature16};17use sr_primitives::traits::{NumberFor, BlakeTwo256, Block as BlockT, DigestFor, StaticLookup, Verify, ConvertInto};18use sr_primitives::weights::Weight;19use babe::{AuthorityId as BabeId};20use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};21use grandpa::fg_primitives::{self, ScheduledChange};22use client::{23 block_builder::api::{CheckInherentsResult, InherentData, self as block_builder_api},24 runtime_api as client_api, impl_runtime_apis25};26use version::RuntimeVersion;27#[cfg(feature = "std")]28use version::NativeVersion;293031#[cfg(any(feature = "std", test))]32pub use sr_primitives::BuildStorage;33pub use timestamp::Call as TimestampCall;34pub use balances::Call as BalancesCall;35pub use sr_primitives::{Permill, Perbill};36pub use support::{StorageValue, construct_runtime, parameter_types};373839pub type BlockNumber = u32;404142pub type Signature = AnySignature;43444546pub type AccountId = <Signature as Verify>::Signer;47484950pub type AccountIndex = u32;515253pub type Balance = u128;545556pub type Index = u32;575859pub type Hash = primitives::H256;606162pub type DigestItem = generic::DigestItem<Hash>;636465mod template;666768697071pub mod opaque {72 use super::*;7374 pub use sr_primitives::OpaqueExtrinsic as UncheckedExtrinsic;7576 77 pub type Header = generic::Header<BlockNumber, BlakeTwo256>;78 79 pub type Block = generic::Block<Header, UncheckedExtrinsic>;80 81 pub type BlockId = generic::BlockId<Block>;8283 pub type SessionHandlers = (Grandpa, Babe);8485 impl_opaque_keys! {86 pub struct SessionKeys {87 #[id(key_types::GRANDPA)]88 pub grandpa: GrandpaId,89 #[id(key_types::BABE)]90 pub babe: BabeId,91 }92 }93}949596pub const VERSION: RuntimeVersion = RuntimeVersion {97 spec_name: create_runtime_str!("node-template"),98 impl_name: create_runtime_str!("node-template"),99 authoring_version: 3,100 spec_version: 4,101 impl_version: 4,102 apis: RUNTIME_API_VERSIONS,103};104105106107108109110111112113114115116117118119pub const MILLISECS_PER_BLOCK: u64 = 6000;120121pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;122123pub const EPOCH_DURATION_IN_BLOCKS: u32 = 10 * MINUTES;124125126pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);127pub const HOURS: BlockNumber = MINUTES * 60;128pub const DAYS: BlockNumber = HOURS * 24;129130131pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);132133134#[cfg(feature = "std")]135pub fn native_version() -> NativeVersion {136 NativeVersion {137 runtime_version: VERSION,138 can_author_with: Default::default(),139 }140}141142parameter_types! {143 pub const BlockHashCount: BlockNumber = 250;144 pub const MaximumBlockWeight: Weight = 1_000_000;145 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);146 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;147 pub const Version: RuntimeVersion = VERSION;148}149150impl system::Trait for Runtime {151 152 type AccountId = AccountId;153 154 type Call = Call;155 156 type Lookup = Indices;157 158 type Index = Index;159 160 type BlockNumber = BlockNumber;161 162 type Hash = Hash;163 164 type Hashing = BlakeTwo256;165 166 type Header = generic::Header<BlockNumber, BlakeTwo256>;167 168 type Event = Event;169 170 type WeightMultiplierUpdate = ();171 172 type Origin = Origin;173 174 type BlockHashCount = BlockHashCount;175 176 type MaximumBlockWeight = MaximumBlockWeight;177 178 type MaximumBlockLength = MaximumBlockLength;179 180 type AvailableBlockRatio = AvailableBlockRatio;181 type Version = Version;182}183184parameter_types! {185 pub const EpochDuration: u64 = EPOCH_DURATION_IN_BLOCKS as u64;186 pub const ExpectedBlockTime: u64 = MILLISECS_PER_BLOCK;187}188189impl babe::Trait for Runtime {190 type EpochDuration = EpochDuration;191 type ExpectedBlockTime = ExpectedBlockTime;192}193194impl grandpa::Trait for Runtime {195 type Event = Event;196}197198impl indices::Trait for Runtime {199 200 201 type AccountIndex = u32;202 203 type ResolveHint = indices::SimpleResolveHint<Self::AccountId, Self::AccountIndex>;204 205 type IsDeadAccount = Balances;206 207 type Event = Event;208}209210parameter_types! {211 pub const MinimumPeriod: u64 = 5000;212}213214impl timestamp::Trait for Runtime {215 216 type Moment = u64;217 type OnTimestampSet = Babe;218 type MinimumPeriod = MinimumPeriod;219}220221parameter_types! {222 pub const ExistentialDeposit: u128 = 500;223 pub const TransferFee: u128 = 0;224 pub const CreationFee: u128 = 0;225 pub const TransactionBaseFee: u128 = 0;226 pub const TransactionByteFee: u128 = 1;227}228229impl balances::Trait for Runtime {230 231 type Balance = Balance;232 233 type OnFreeBalanceZero = ();234 235 type OnNewAccount = Indices;236 237 type Event = Event;238239 type TransactionPayment = ();240 type DustRemoval = ();241 type TransferPayment = ();242 type ExistentialDeposit = ExistentialDeposit;243 type TransferFee = TransferFee;244 type CreationFee = CreationFee;245 type TransactionBaseFee = TransactionBaseFee;246 type TransactionByteFee = TransactionByteFee;247 type WeightToFee = ConvertInto;248}249250impl sudo::Trait for Runtime {251 type Event = Event;252 type Proposal = Call;253}254255256impl template::Trait for Runtime {257 type Event = Event;258}259260construct_runtime!(261 pub enum Runtime where262 Block = Block,263 NodeBlock = opaque::Block,264 UncheckedExtrinsic = UncheckedExtrinsic265 {266 System: system::{Module, Call, Storage, Config, Event},267 Timestamp: timestamp::{Module, Call, Storage, Inherent},268 Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)},269 Grandpa: grandpa::{Module, Call, Storage, Config, Event},270 Indices: indices::{default, Config<T>},271 Balances: balances,272 Sudo: sudo,273 274 TemplateModule: template::{Module, Call, Storage, Event<T>},275 }276);277278279pub type Address = <Indices as StaticLookup>::Source;280281pub type Header = generic::Header<BlockNumber, BlakeTwo256>;282283pub type Block = generic::Block<Header, UncheckedExtrinsic>;284285pub type SignedBlock = generic::SignedBlock<Block>;286287pub type BlockId = generic::BlockId<Block>;288289pub type SignedExtra = (290 system::CheckVersion<Runtime>,291 system::CheckGenesis<Runtime>,292 system::CheckEra<Runtime>,293 system::CheckNonce<Runtime>,294 system::CheckWeight<Runtime>,295 balances::TakeFees<Runtime>296);297298pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;299300pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;301302pub type Executive = executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;303304impl_runtime_apis! {305 impl client_api::Core<Block> for Runtime {306 fn version() -> RuntimeVersion {307 VERSION308 }309310 fn execute_block(block: Block) {311 Executive::execute_block(block)312 }313314 fn initialize_block(header: &<Block as BlockT>::Header) {315 Executive::initialize_block(header)316 }317 }318319 impl client_api::Metadata<Block> for Runtime {320 fn metadata() -> OpaqueMetadata {321 Runtime::metadata().into()322 }323 }324325 impl block_builder_api::BlockBuilder<Block> for Runtime {326 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyResult {327 Executive::apply_extrinsic(extrinsic)328 }329330 fn finalize_block() -> <Block as BlockT>::Header {331 Executive::finalize_block()332 }333334 fn inherent_extrinsics(data: InherentData) -> Vec<<Block as BlockT>::Extrinsic> {335 data.create_extrinsics()336 }337338 fn check_inherents(block: Block, data: InherentData) -> CheckInherentsResult {339 data.check_extrinsics(&block)340 }341342 fn random_seed() -> <Block as BlockT>::Hash {343 System::random_seed()344 }345 }346347 impl client_api::TaggedTransactionQueue<Block> for Runtime {348 fn validate_transaction(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity {349 Executive::validate_transaction(tx)350 }351 }352353 impl offchain_primitives::OffchainWorkerApi<Block> for Runtime {354 fn offchain_worker(number: NumberFor<Block>) {355 Executive::offchain_worker(number)356 }357 }358359 impl fg_primitives::GrandpaApi<Block> for Runtime {360 fn grandpa_pending_change(digest: &DigestFor<Block>)361 -> Option<ScheduledChange<NumberFor<Block>>>362 {363 Grandpa::pending_change(digest)364 }365366 fn grandpa_forced_change(digest: &DigestFor<Block>)367 -> Option<(NumberFor<Block>, ScheduledChange<NumberFor<Block>>)>368 {369 Grandpa::forced_change(digest)370 }371372 fn grandpa_authorities() -> Vec<(GrandpaId, GrandpaWeight)> {373 Grandpa::grandpa_authorities()374 }375 }376377 impl babe_primitives::BabeApi<Block> for Runtime {378 fn startup_data() -> babe_primitives::BabeConfiguration {379 380 381 382 383 384 babe_primitives::BabeConfiguration {385 median_required_blocks: 1000,386 slot_duration: Babe::slot_duration(),387 c: PRIMARY_PROBABILITY,388 }389 }390391 fn epoch() -> babe_primitives::Epoch {392 babe_primitives::Epoch {393 start_slot: Babe::epoch_start_slot(),394 authorities: Babe::authorities(),395 epoch_index: Babe::epoch_index(),396 randomness: Babe::randomness(),397 duration: EpochDuration::get(),398 secondary_slots: Babe::secondary_slots().0,399 }400 }401 }402403 impl substrate_session::SessionKeys<Block> for Runtime {404 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {405 let seed = seed.as_ref().map(|s| rstd::str::from_utf8(&s).expect("Seed is an utf8 string"));406 opaque::SessionKeys::generate(seed)407 }408 }409}