DigestItem trait (v2) (#650)

* DigestItem trait

* removed autoimpl in impl_outer_log

* StubDigestItem -> ()
This commit is contained in:
Svyatoslav Nikolsky
2018-09-05 14:36:23 +03:00
committed by Gav Wood
parent 101f5ec393
commit be7cb74b06
21 changed files with 221 additions and 23 deletions
+21 -5
View File
@@ -53,10 +53,9 @@ extern crate substrate_runtime_timestamp as timestamp;
extern crate substrate_runtime_version as version;
extern crate demo_primitives;
use rstd::prelude::*;
use demo_primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, SessionKey, Signature};
use runtime_primitives::generic;
use runtime_primitives::traits::{Convert, BlakeTwo256};
use runtime_primitives::traits::{Convert, BlakeTwo256, DigestItem};
use version::RuntimeVersion;
#[cfg(any(feature = "std", test))]
@@ -90,9 +89,9 @@ impl system::Trait for Runtime {
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hashing = BlakeTwo256;
type Digest = generic::Digest<Vec<u8>>;
type Digest = generic::Digest<Log>;
type AccountId = AccountId;
type Header = generic::Header<BlockNumber, BlakeTwo256, Vec<u8>>;
type Header = generic::Header<BlockNumber, BlakeTwo256, Log>;
type Event = Event;
}
@@ -112,6 +111,7 @@ pub type Balances = balances::Module<Runtime>;
impl consensus::Trait for Runtime {
const NOTE_OFFLINE_POSITION: u32 = 1;
type Log = Log;
type SessionKey = SessionKey;
type OnOfflineValidator = Staking;
}
@@ -173,6 +173,22 @@ impl_outer_event! {
}
}
impl_outer_log! {
pub enum Log for Runtime {
consensus
}
}
impl DigestItem for Log {
type AuthoritiesChange = consensus::AuthoritiesChange<SessionKey>;
fn as_authorities_change(&self) -> Option<&Self::AuthoritiesChange> {
match *self {
Log::consensus(ref item) => item.as_authorities_change(),
}
}
}
impl_outer_dispatch! {
#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
@@ -203,7 +219,7 @@ impl_outer_dispatch! {
/// The address format for describing accounts.
pub type Address = balances::Address<Runtime>;
/// Block header type as expected by this runtime.
pub type Header = generic::Header<BlockNumber, BlakeTwo256, Vec<u8>>;
pub type Header = generic::Header<BlockNumber, BlakeTwo256, Log>;
/// Block type as expected by this runtime.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// BlockId type as expected by this runtime.