diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index e1d9a49793..7e77f3003b 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -2365,6 +2365,7 @@ dependencies = [ "srml-treasury 2.0.0", "substrate-client 2.0.0", "substrate-consensus-babe-primitives 2.0.0", + "substrate-consensus-common-primitives 2.0.0", "substrate-keyring 2.0.0", "substrate-offchain-primitives 2.0.0", "substrate-primitives 2.0.0", @@ -4385,6 +4386,16 @@ dependencies = [ "substrate-test-runtime-client 2.0.0", ] +[[package]] +name = "substrate-consensus-common-primitives" +version = "2.0.0" +dependencies = [ + "parity-codec 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-primitives 2.0.0", + "sr-std 2.0.0", + "substrate-client 2.0.0", +] + [[package]] name = "substrate-consensus-rhd" version = "2.0.0" diff --git a/substrate/core/consensus/common/primitives/Cargo.toml b/substrate/core/consensus/common/primitives/Cargo.toml new file mode 100644 index 0000000000..154863eed5 --- /dev/null +++ b/substrate/core/consensus/common/primitives/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "substrate-consensus-common-primitives" +version = "2.0.0" +authors = ["Parity Technologies "] +description = "Common consensus primitives" +edition = "2018" + +[dependencies] +parity-codec = { version = "4.1.1", default-features = false } +client = { package = "substrate-client", path = "../../../client", default-features = false } +sr-primitives = { package = "sr-primitives", path = "../../../sr-primitives", default-features = false } +rstd = { package = "sr-std", path = "../../../sr-std", default-features = false } + +[features] +default = ["std"] +std = [ + "rstd/std", + "client/std", + "parity-codec/std", + "sr-primitives/std" +] diff --git a/substrate/core/consensus/common/primitives/src/lib.rs b/substrate/core/consensus/common/primitives/src/lib.rs new file mode 100644 index 0000000000..47c4371721 --- /dev/null +++ b/substrate/core/consensus/common/primitives/src/lib.rs @@ -0,0 +1,31 @@ +// Copyright 2019 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate 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. + +// Substrate 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 Substrate. If not, see . + +//! Common consensus primitives. + +#![cfg_attr(not(feature = "std"), no_std)] + +use parity_codec::Codec; +use client::decl_runtime_apis; +use rstd::vec::Vec; + +decl_runtime_apis! { + /// Common consensus runtime api. + pub trait ConsensusApi { + /// Returns the set of authorities of the currently active consensus mechanism. + fn authorities() -> Vec; + } +} diff --git a/substrate/node/runtime/Cargo.toml b/substrate/node/runtime/Cargo.toml index eca7c9ebb7..9c52125fe8 100644 --- a/substrate/node/runtime/Cargo.toml +++ b/substrate/node/runtime/Cargo.toml @@ -19,6 +19,7 @@ support = { package = "srml-support", path = "../../srml/support", default-featu authorship = { package = "srml-authorship", path = "../../srml/authorship", default-features = false } babe = { package = "srml-babe", path = "../../srml/babe", default-features = false } babe-primitives = { package = "substrate-consensus-babe-primitives", path = "../../core/consensus/babe/primitives", default-features = false } +consensus-primitives = { package = "substrate-consensus-common-primitives", path = "../../core/consensus/common/primitives", default-features = false } balances = { package = "srml-balances", path = "../../srml/balances", default-features = false } contracts = { package = "srml-contracts", path = "../../srml/contracts", default-features = false } collective = { package = "srml-collective", path = "../../srml/collective", default-features = false } @@ -57,6 +58,7 @@ std = [ "authorship/std", "babe/std", "babe-primitives/std", + "consensus-primitives/std", "balances/std", "contracts/std", "collective/std", diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs index e657feebe9..f89b121afa 100644 --- a/substrate/node/runtime/src/lib.rs +++ b/substrate/node/runtime/src/lib.rs @@ -538,4 +538,10 @@ impl_runtime_apis! { } } } + + impl consensus_primitives::ConsensusApi for Runtime { + fn authorities() -> Vec { + Babe::authorities().into_iter().map(|(a, _)| a).collect() + } + } }