derive codec for inherent data (#2714)

* derive codec for inherent data

* increase spec version
This commit is contained in:
thiolliere
2019-05-29 14:16:37 +02:00
committed by Gavin Wood
parent c7d1204ce5
commit 91a241ad5b
2 changed files with 2 additions and 29 deletions
+1 -28
View File
@@ -53,7 +53,7 @@ pub use runtime_primitives::RuntimeString;
pub type InherentIdentifier = [u8; 8];
/// Inherent data to include in a block.
#[derive(Clone, Default)]
#[derive(Clone, Default, Encode, Decode)]
pub struct InherentData {
/// All inherent data encoded with parity-codec and an identifier.
data: BTreeMap<InherentIdentifier, Vec<u8>>
@@ -123,33 +123,6 @@ impl InherentData {
}
}
impl codec::Encode for InherentData {
fn encode(&self) -> Vec<u8> {
let keys = self.data.keys().collect::<Vec<_>>();
let values = self.data.values().collect::<Vec<_>>();
let mut encoded = keys.encode();
encoded.extend(values.encode());
encoded
}
}
impl codec::Decode for InherentData {
fn decode<I: codec::Input>(value: &mut I) -> Option<Self> {
Vec::<InherentIdentifier>::decode(value)
.and_then(|i| Vec::<Vec<u8>>::decode(value).map(|v| (i, v)))
.and_then(|(i, v)| {
if i.len() == v.len() {
Some(Self {
data: i.into_iter().zip(v.into_iter()).collect()
})
} else {
None
}
})
}
}
/// The result of checking inherents.
///
/// It either returns okay for all checks, stores all occurred errors or just one fatal error.
+1 -1
View File
@@ -58,7 +58,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node"),
impl_name: create_runtime_str!("substrate-node"),
authoring_version: 10,
spec_version: 86,
spec_version: 87,
impl_version: 87,
apis: RUNTIME_API_VERSIONS,
};