Initial validator trait. (#14)

* Initial validator trait.

* Add missing docs warning.

* Fix formatting.

* Fix validator output and serialization.

* Get rid of redundant ValidationCode type.
This commit is contained in:
Tomasz Drwięga
2017-11-12 16:48:35 +01:00
committed by Robert Habermeier
parent 9d083be47a
commit e9177294f6
12 changed files with 520 additions and 52 deletions
+14 -40
View File
@@ -16,50 +16,23 @@
//! Block and header type definitions.
use bytes;
use hash::H256;
use parachain;
/// Hash used to refer to a block hash.
pub type HeaderHash = H256;
/// Hash used to refer to proof of block header.
pub type ProofHash = H256;
/// Unique identifier of a parachain.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Serialize, Deserialize)]
pub struct ParachainId(u64);
impl From<ParachainId> for u64 {
fn from(x: ParachainId) -> Self { x.0 }
}
impl From<u64> for ParachainId {
fn from(x: u64) -> Self { ParachainId(x) }
}
/// A wrapper type for parachain block header raw bytes.
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ParachainBlockHeader(#[serde(with="bytes")] pub Vec<u8>);
/// A parachain block proposal.
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ParachainProposal {
/// The ID of the parachain this is a proposal for.
pub parachain: ParachainId,
/// Parachain block header bytes.
pub header: ParachainBlockHeader,
/// Hash of data necessary to prove validity of the header.
pub proof_hash: ProofHash,
}
/// A relay chain block header.
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Header {
/// Block parent's hash.
pub parent_hash: HeaderHash,
#[serde(rename="parentHash")]
pub parent_hash: HeaderHash,
/// State root after this transition.
pub state_root: H256,
#[serde(rename="stateRoot")]
pub state_root: H256,
/// Unix time at which this header was produced.
pub timestamp: u64,
pub timestamp: u64,
/// Block number.
pub number: u64,
}
@@ -71,7 +44,8 @@ pub struct Header {
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Body {
/// Parachain proposal blocks.
pub para_blocks: Vec<ParachainProposal>,
#[serde(rename="paraBlocks")]
pub para_blocks: Vec<parachain::Proposal>,
}
@@ -88,8 +62,8 @@ mod tests {
timestamp: 10,
number: 67,
}), r#"{
"parent_hash": "0x0000000000000000000000000000000000000000000000000000000000000005",
"state_root": "0x0000000000000000000000000000000000000000000000000000000000000003",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000005",
"stateRoot": "0x0000000000000000000000000000000000000000000000000000000000000003",
"timestamp": 10,
"number": 67
}"#);
@@ -99,18 +73,18 @@ mod tests {
fn test_body_serialization() {
assert_eq!(ser::to_string_pretty(&Body {
para_blocks: vec![
ParachainProposal {
parachain::Proposal {
parachain: 5.into(),
header: ParachainBlockHeader(vec![1, 2, 3, 4]),
header: parachain::Header(vec![1, 2, 3, 4]),
proof_hash: 5.into(),
}
],
}), r#"{
"para_blocks": [
"paraBlocks": [
{
"parachain": 5,
"header": "0x01020304",
"proof_hash": "0x0000000000000000000000000000000000000000000000000000000000000005"
"proofHash": "0x0000000000000000000000000000000000000000000000000000000000000005"
}
]
}"#);