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, 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;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 = SLOT_DURATION / 2;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;238 type TransactionPayment = ();239 type DustRemoval = ();240 type TransferPayment = ();241 type ExistentialDeposit = ExistentialDeposit;242 type TransferFee = TransferFee;243 type CreationFee = CreationFee;244 type TransactionBaseFee = TransactionBaseFee;245 type TransactionByteFee = TransactionByteFee;246 type WeightToFee = ConvertInto;247}248249impl sudo::Trait for Runtime {250 type Event = Event;251 type Proposal = Call;252}253254255impl template::Trait for Runtime {256 type Event = Event;257}258259construct_runtime!(260 pub enum Runtime where261 Block = Block,262 NodeBlock = opaque::Block,263 UncheckedExtrinsic = UncheckedExtrinsic264 {265 System: system::{Module, Call, Storage, Config, Event},266 Timestamp: timestamp::{Module, Call, Storage, Inherent},267 Babe: babe::{Module, Call, Storage, Config, Inherent(Timestamp)},268 Grandpa: grandpa::{Module, Call, Storage, Config, Event},269 Indices: indices::{default, Config<T>},270 Balances: balances::{default, Error},271 Sudo: sudo,272 273 TemplateModule: template::{Module, Call, Storage, Event<T>},274 }275);276277278pub type Address = <Indices as StaticLookup>::Source;279280pub type Header = generic::Header<BlockNumber, BlakeTwo256>;281282pub type Block = generic::Block<Header, UncheckedExtrinsic>;283284pub type SignedBlock = generic::SignedBlock<Block>;285286pub type BlockId = generic::BlockId<Block>;287288pub type SignedExtra = (289 system::CheckVersion<Runtime>,290 system::CheckGenesis<Runtime>,291 system::CheckEra<Runtime>,292 system::CheckNonce<Runtime>,293 system::CheckWeight<Runtime>,294 balances::TakeFees<Runtime>295);296297pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;298299pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;300301pub type Executive = executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;302303impl_runtime_apis! {304 impl client_api::Core<Block> for Runtime {305 fn version() -> RuntimeVersion {306 VERSION307 }308309 fn execute_block(block: Block) {310 Executive::execute_block(block)311 }312313 fn initialize_block(header: &<Block as BlockT>::Header) {314 Executive::initialize_block(header)315 }316 }317318 impl client_api::Metadata<Block> for Runtime {319 fn metadata() -> OpaqueMetadata {320 Runtime::metadata().into()321 }322 }323324 impl block_builder_api::BlockBuilder<Block> for Runtime {325 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyResult {326 Executive::apply_extrinsic(extrinsic)327 }328329 fn finalize_block() -> <Block as BlockT>::Header {330 Executive::finalize_block()331 }332333 fn inherent_extrinsics(data: InherentData) -> Vec<<Block as BlockT>::Extrinsic> {334 data.create_extrinsics()335 }336337 fn check_inherents(block: Block, data: InherentData) -> CheckInherentsResult {338 data.check_extrinsics(&block)339 }340341 fn random_seed() -> <Block as BlockT>::Hash {342 System::random_seed()343 }344 }345346 impl client_api::TaggedTransactionQueue<Block> for Runtime {347 fn validate_transaction(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity {348 Executive::validate_transaction(tx)349 }350 }351352 impl offchain_primitives::OffchainWorkerApi<Block> for Runtime {353 fn offchain_worker(number: NumberFor<Block>) {354 Executive::offchain_worker(number)355 }356 }357358 impl fg_primitives::GrandpaApi<Block> for Runtime {359 fn grandpa_authorities() -> Vec<(GrandpaId, GrandpaWeight)> {360 Grandpa::grandpa_authorities()361 }362 }363364 impl babe_primitives::BabeApi<Block> for Runtime {365 fn configuration() -> babe_primitives::BabeConfiguration {366 367 368 369 370 371 babe_primitives::BabeConfiguration {372 slot_duration: Babe::slot_duration(),373 epoch_length: EpochDuration::get(),374 c: PRIMARY_PROBABILITY,375 genesis_authorities: Babe::authorities(),376 randomness: Babe::randomness(),377 secondary_slots: true,378 }379 }380 }381382 impl substrate_session::SessionKeys<Block> for Runtime {383 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {384 let seed = seed.as_ref().map(|s| rstd::str::from_utf8(&s).expect("Seed is an utf8 string"));385 opaque::SessionKeys::generate(seed)386 }387 }388}