DigestItem trait (v3) (#687)

* DigestItem v4

* tests

* wording
This commit is contained in:
Svyatoslav Nikolsky
2018-09-10 19:34:51 +03:00
committed by Gav Wood
parent 153439aeea
commit 0e1023ae42
18 changed files with 417 additions and 131 deletions
+2 -15
View File
@@ -40,7 +40,7 @@ use rstd::prelude::*;
use runtime_primitives::generic;
#[cfg(feature = "std")]
use primitives::bytes;
use runtime_primitives::traits::{BlakeTwo256, DigestItem};
use runtime_primitives::traits::BlakeTwo256;
/// An index to a block.
pub type BlockNumber = u64;
@@ -73,25 +73,12 @@ pub type Signature = runtime_primitives::Ed25519Signature;
pub type Timestamp = u64;
/// Header type.
pub type Header = generic::Header<BlockNumber, BlakeTwo256, Log>;
pub type Header = generic::Header<BlockNumber, BlakeTwo256, generic::DigestItem<()>>;
/// Block type.
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// Block ID.
pub type BlockId = generic::BlockId<Block>;
/// A log entry in the block.
#[derive(PartialEq, Eq, Clone, Default, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
pub struct Log(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec<u8>);
//TODO: remove this. Generic primitives should not require DigestItem
impl DigestItem for Log {
type AuthoritiesChange = ();
fn as_authorities_change(&self) -> Option<&()> {
unreachable!()
}
}
/// Opaque, encoded, unchecked extrinsic.
#[derive(PartialEq, Eq, Clone, Default, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+7 -6
View File
@@ -64,6 +64,7 @@ use demo_primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index
use runtime_primitives::generic;
use runtime_primitives::traits::{Convert, BlakeTwo256, DigestItem};
use version::RuntimeVersion;
use codec::{Encode, Decode, Input};
use council::motions as council_motions;
use substrate_primitives::u32_trait::{_2, _4};
@@ -202,8 +203,8 @@ impl_outer_event! {
}
impl_outer_log! {
pub enum Log for Runtime {
consensus
pub enum Log(InternalLog: DigestItem<SessionKey>) for Runtime {
consensus(AuthoritiesChange)
}
}
@@ -243,11 +244,11 @@ impl_outer_config! {
}
impl DigestItem for Log {
type AuthoritiesChange = consensus::AuthoritiesChange<SessionKey>;
type AuthorityId = SessionKey;
fn as_authorities_change(&self) -> Option<&Self::AuthoritiesChange> {
match *self {
Log::consensus(ref item) => item.as_authorities_change(),
fn as_authorities_change(&self) -> Option<&[Self::AuthorityId]> {
match self.0 {
InternalLog::consensus(ref item) => item.as_authorities_change(),
}
}
}