//! The Substrate Node Template runtime. This can be compiled with `#[no_std]`, ready for Wasm. #![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), feature(alloc))] // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit="256"] #[cfg(feature = "std")] use serde_derive::{Serialize, Deserialize}; use parity_codec_derive::{Encode, Decode}; use rstd::prelude::*; #[cfg(feature = "std")] use primitives::bytes; use primitives::{Ed25519AuthorityId, OpaqueMetadata}; use runtime_primitives::{ ApplyResult, transaction_validity::TransactionValidity, Ed25519Signature, generic, traits::{self, BlakeTwo256, Block as BlockT, StaticLookup}, create_runtime_str }; use client::{ block_builder::api::{CheckInherentsResult, InherentData, self as block_builder_api}, runtime_api, impl_runtime_apis }; use version::RuntimeVersion; #[cfg(feature = "std")] use version::NativeVersion; // A few exports that help ease life for downstream crates. #[cfg(any(feature = "std", test))] pub use runtime_primitives::BuildStorage; pub use consensus::Call as ConsensusCall; pub use timestamp::Call as TimestampCall; pub use balances::Call as BalancesCall; pub use runtime_primitives::{Permill, Perbill}; pub use timestamp::BlockPeriod; pub use support::{StorageValue, construct_runtime}; /// Alias to Ed25519 pubkey that identifies an account on the chain. pub type AccountId = primitives::H256; /// A hash of some data used by the chain. pub type Hash = primitives::H256; /// Index of a block number in the chain. pub type BlockNumber = u64; /// Index of an account's extrinsic in the chain. pub type Nonce = u64; /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know /// the specifics of the runtime. They can then be made to be agnostic over specific formats /// of data like extrinsics, allowing for them to continue syncing the network through upgrades /// to even the core datastructures. pub mod opaque { use super::*; /// Opaque, encoded, unchecked extrinsic. #[derive(PartialEq, Eq, Clone, Default, Encode, Decode)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))] pub struct UncheckedExtrinsic(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec); impl traits::Extrinsic for UncheckedExtrinsic { fn is_signed(&self) -> Option { None } } /// Opaque block header type. pub type Header = generic::Header>; /// Opaque block type. pub type Block = generic::Block; /// Opaque block identifier type. pub type BlockId = generic::BlockId; /// Opaque session key type. pub type SessionKey = Ed25519AuthorityId; } /// This runtime version. pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("template-node"), impl_name: create_runtime_str!("template-node"), authoring_version: 3, spec_version: 3, impl_version: 0, apis: RUNTIME_API_VERSIONS, }; /// The version infromation used to identify this runtime when compiled natively. #[cfg(feature = "std")] pub fn native_version() -> NativeVersion { NativeVersion { runtime_version: VERSION, can_author_with: Default::default(), } } impl system::Trait for Runtime { /// The identifier used to distinguish between accounts. type AccountId = AccountId; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = Indices; /// The index type for storing how many extrinsics an account has signed. type Index = Nonce; /// The index type for blocks. type BlockNumber = BlockNumber; /// The type for hashing blocks and tries. type Hash = Hash; /// The hashing algorithm used. type Hashing = BlakeTwo256; /// The header digest type. type Digest = generic::Digest; /// The header type. type Header = generic::Header; /// The ubiquitous event type. type Event = Event; /// The ubiquitous log type. type Log = Log; /// The ubiquitous origin type. type Origin = Origin; } impl aura::Trait for Runtime { type HandleReport = (); } impl consensus::Trait for Runtime { /// The identifier we use to refer to authorities. type SessionKey = Ed25519AuthorityId; // The aura module handles offline-reports internally // rather than using an explicit report system. type InherentOfflineReport = (); /// The ubiquitous log type. type Log = Log; } impl indices::Trait for Runtime { /// The type for recording indexing into the account enumeration. If this ever overflows, there /// will be problems! type AccountIndex = u32; /// Use the standard means of resolving an index hint from an id. type ResolveHint = indices::SimpleResolveHint; /// Determine whether an account is dead. type IsDeadAccount = Balances; /// The uniquitous event type. type Event = Event; } impl timestamp::Trait for Runtime { /// A timestamp: seconds since the unix epoch. type Moment = u64; type OnTimestampSet = Aura; } impl balances::Trait for Runtime { /// The type for recording an account's balance. type Balance = u128; /// What to do if an account's free balance gets zeroed. type OnFreeBalanceZero = (); /// What to do if a new account is created. type OnNewAccount = Indices; /// Restrict whether an account can transfer funds. We don't place any further restrictions. type EnsureAccountLiquid = (); /// The uniquitous event type. type Event = Event; } impl sudo::Trait for Runtime { /// The uniquitous event type. type Event = Event; type Proposal = Call; } construct_runtime!( pub enum Runtime with Log(InternalLog: DigestItem) where Block = Block, NodeBlock = opaque::Block, UncheckedExtrinsic = UncheckedExtrinsic { System: system::{default, Log(ChangesTrieRoot)}, Timestamp: timestamp::{Module, Call, Storage, Config, Inherent}, Consensus: consensus::{Module, Call, Storage, Config, Log(AuthoritiesChange), Inherent}, Aura: aura::{Module}, Indices: indices, Balances: balances, Sudo: sudo, } ); /// The type used as a helper for interpreting the sender of transactions. type Context = system::ChainContext; /// The address format for describing accounts. type Address = ::Source; /// Block header type as expected by this runtime. pub type Header = generic::Header; /// Block type as expected by this runtime. pub type Block = generic::Block; /// BlockId type as expected by this runtime. pub type BlockId = generic::BlockId; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedMortalCompactExtrinsic; /// Extrinsic type that has already been checked. pub type CheckedExtrinsic = generic::CheckedExtrinsic; /// Executive: handles dispatch to the various modules. pub type Executive = executive::Executive; // Implement our runtime API endpoints. This is just a bunch of proxying. impl_runtime_apis! { impl runtime_api::Core for Runtime { fn version() -> RuntimeVersion { VERSION } fn authorities() -> Vec { Consensus::authorities() } fn execute_block(block: Block) { Executive::execute_block(block) } fn initialise_block(header: &::Header) { Executive::initialise_block(header) } } impl runtime_api::Metadata for Runtime { fn metadata() -> OpaqueMetadata { Runtime::metadata().into() } } impl block_builder_api::BlockBuilder for Runtime { fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyResult { Executive::apply_extrinsic(extrinsic) } fn finalise_block() -> ::Header { Executive::finalise_block() } fn inherent_extrinsics(data: InherentData) -> Vec<::Extrinsic> { data.create_extrinsics() } fn check_inherents(block: Block, data: InherentData) -> CheckInherentsResult { data.check_extrinsics(&block) } fn random_seed() -> ::Hash { System::random_seed() } } impl runtime_api::TaggedTransactionQueue for Runtime { fn validate_transaction(tx: ::Extrinsic) -> TransactionValidity { Executive::validate_transaction(tx) } } impl consensus_aura::AuraApi for Runtime { fn slot_duration() -> u64 { Aura::slot_duration() } } }