From 74ec849f7e442546aa17498854595287d063fd72 Mon Sep 17 00:00:00 2001 From: Robert Habermeier <rphmeier@gmail.com> Date: Fri, 10 Nov 2017 15:03:40 +0100 Subject: [PATCH] Block primitive (#11) * initial primitives * add block primitives --- substrate/primitives/src/block.rs | 70 +++++++++++++++++++++++++++++++ substrate/primitives/src/lib.rs | 6 ++- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 substrate/primitives/src/block.rs diff --git a/substrate/primitives/src/block.rs b/substrate/primitives/src/block.rs new file mode 100644 index 00000000000..9b3c7beb0d7 --- /dev/null +++ b/substrate/primitives/src/block.rs @@ -0,0 +1,70 @@ +// Copyright 2017 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. + +//! Block and header type definitions. + +use hash::H256; + +/// 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)] +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 parachain block proposal. +#[derive(Debug, PartialEq, Eq)] +pub struct ParachainProposal { + /// The ID of the parachain this is a proposal for. + pub parachain: ParachainId, + /// Parachain block header bytes. + pub header: Vec<u8>, + /// Hash of data necessary to prove validity of the header. + pub proof_hash: ProofHash, +} + +/// A relay chain block header. +#[derive(Debug, PartialEq, Eq)] +pub struct Header { + /// Block parent's hash. + pub parent_hash: HeaderHash, + /// State root after this transition. + pub state_root: H256, + /// Unix time at which this header was produced. + pub timestamp: u64, + /// Block number. + pub number: u64, +} + +/// A relay chain block body. +/// +/// Included candidates should be sorted by parachain ID, and without duplicate +/// IDs. +#[derive(Debug, PartialEq, Eq)] +pub struct Body { + /// Parachain proposal blocks. + pub para_blocks: Vec<ParachainProposal>, +} diff --git a/substrate/primitives/src/lib.rs b/substrate/primitives/src/lib.rs index 74093e65239..d16ba72467b 100644 --- a/substrate/primitives/src/lib.rs +++ b/substrate/primitives/src/lib.rs @@ -28,8 +28,12 @@ extern crate fixed_hash; #[macro_use] extern crate uint as uint_crate; -pub mod uint; +pub mod block; pub mod hash; +pub mod uint; + +/// Alias to 160-bit hash when used in the context of an account address. +pub type Address = hash::H160; #[cfg(test)] mod tests { -- GitLab