From 2d0d4682ad610e3af2abf55c4061be7e9f3a8159 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 11 Dec 2016 23:36:38 +0100 Subject: [PATCH] Add first Updater RPC. --- rpc/src/v1/impls/parity.rs | 8 ++++- rpc/src/v1/traits/parity.rs | 6 +++- rpc/src/v1/types/consensus_status.rs | 46 ++++++++++++++++++++++++++++ rpc/src/v1/types/mod.rs.in | 2 ++ 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 rpc/src/v1/types/consensus_status.rs diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index af44f6cb8..db616da24 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -38,7 +38,7 @@ use v1::types::{ Bytes, U256, H160, H256, H512, Peers, Transaction, RpcSettings, Histogram, TransactionStats, LocalTransactionStatus, - BlockNumber, + BlockNumber, ConsensusCapability }; use v1::helpers::{errors, SigningQueue, SignerService, NetworkSettings}; use v1::helpers::dispatch::DEFAULT_MAC; @@ -360,4 +360,10 @@ impl Parity for ParityClient where (format!("0x{}", a.hex()), m) }).collect()) } + + fn consensus_capability(&self) -> Result { + try!(self.active()); + let updater = take_weak!(self.updater); + Ok(updater.capability().into()) + } } diff --git a/rpc/src/v1/traits/parity.rs b/rpc/src/v1/traits/parity.rs index ba6514168..32d2a041c 100644 --- a/rpc/src/v1/traits/parity.rs +++ b/rpc/src/v1/traits/parity.rs @@ -23,7 +23,7 @@ use v1::types::{ H160, H256, H512, U256, Bytes, Peers, Transaction, RpcSettings, Histogram, TransactionStats, LocalTransactionStatus, - BlockNumber + BlockNumber, ConsensusCapability }; build_rpc_trait! { @@ -155,5 +155,9 @@ build_rpc_trait! { /// Returns accounts information. #[rpc(name = "parity_accounts")] fn accounts(&self) -> Result>, Error>; + + /// Returns information on current consensus capability. + #[rpc(name = "parity_consensusCapability")] + fn consensus_capability(&self) -> Result; } } diff --git a/rpc/src/v1/types/consensus_status.rs b/rpc/src/v1/types/consensus_status.rs new file mode 100644 index 000000000..f919fcd58 --- /dev/null +++ b/rpc/src/v1/types/consensus_status.rs @@ -0,0 +1,46 @@ +// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity 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. + +// Parity 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 Parity. If not, see . + +use updater::CapState; + +/// Capability info +#[derive(Debug, Serialize, PartialEq)] +pub enum ConsensusCapability { + /// Unknown. + #[serde(rename="unknown")] + Unknown, + /// Capable of consensus indefinitely. + #[serde(rename="capable")] + Capable, + /// Capable of consensus up until a definite block. + #[serde(rename="capableUntil")] + CapableUntil(u64), + /// Incapable of consensus since a particular block. + #[serde(rename="incapableSince")] + IncapableSince(u64), +} + +impl Into for CapState { + fn into(self) -> ConsensusCapability { + match self { + CapState::Unknown => ConsensusCapability::Unknown, + CapState::Capable => ConsensusCapability::Capable, + CapState::CapableUntil(n) => ConsensusCapability::CapableUntil(n), + CapState::IncapableSince(n) => ConsensusCapability::IncapableSince(n), + } + } +} + diff --git a/rpc/src/v1/types/mod.rs.in b/rpc/src/v1/types/mod.rs.in index c5509bd57..a7acfe5c6 100644 --- a/rpc/src/v1/types/mod.rs.in +++ b/rpc/src/v1/types/mod.rs.in @@ -34,6 +34,7 @@ mod trace_filter; mod uint; mod work; mod histogram; +mod consensus_status; pub use self::bytes::Bytes; pub use self::block::{RichBlock, Block, BlockTransactions}; @@ -55,3 +56,4 @@ pub use self::trace_filter::TraceFilter; pub use self::uint::{U128, U256}; pub use self::work::Work; pub use self::histogram::Histogram; +pub use self::consensus_status::ConsensusCapability; \ No newline at end of file