This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tendermint-rs: /validators RPC endpoint
- Loading branch information
1 parent
c55d442
commit 9b911df
Showing
13 changed files
with
751 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pub mod block; | |
pub mod genesis; | ||
pub mod net_info; | ||
pub mod status; | ||
pub mod validators; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//! `/validators` endpoint JSONRPC wrapper | ||
|
||
use crate::{block, rpc, validator}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// List validators for a specific block | ||
pub struct Request { | ||
height: block::Height, | ||
} | ||
|
||
impl Request { | ||
/// List validators for a specific block | ||
pub fn new(height: block::Height) -> Self { | ||
Self { height } | ||
} | ||
} | ||
|
||
impl rpc::Request for Request { | ||
type Response = Response; | ||
|
||
fn path(&self) -> rpc::request::Path { | ||
// TODO(tarcieri): use a `uri` crate to construct this? | ||
format!("/validators?height={}", self.height) | ||
.parse() | ||
.unwrap() | ||
} | ||
} | ||
|
||
/// Validator responses | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct Response { | ||
/// Block height | ||
pub block_height: block::Height, | ||
|
||
/// Validator list | ||
pub validators: Vec<validator::Info>, | ||
} | ||
|
||
impl rpc::Response for Response {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//! Tendermint validators | ||
|
||
use crate::{account, vote, PublicKey}; | ||
#[cfg(feature = "serde")] | ||
use serde::{de::Error as DeError, Deserialize, Deserializer, Serialize, Serializer}; | ||
|
||
/// Validator information | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
#[derive(Clone, Debug)] | ||
pub struct Info { | ||
/// Validator account address | ||
pub address: account::Id, | ||
|
||
/// Validator public key | ||
pub pub_key: PublicKey, | ||
|
||
/// Validator voting power | ||
pub voting_power: vote::Power, | ||
|
||
/// Validator proposer priority | ||
pub proposer_priority: Option<ProposerPriority>, | ||
} | ||
|
||
/// Proposer priority | ||
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] | ||
pub struct ProposerPriority(i64); | ||
|
||
impl ProposerPriority { | ||
/// Get the current voting power | ||
pub fn value(self) -> i64 { | ||
self.0 | ||
} | ||
} | ||
|
||
impl From<ProposerPriority> for i64 { | ||
fn from(priority: ProposerPriority) -> i64 { | ||
priority.value() | ||
} | ||
} | ||
|
||
#[cfg(feature = "serde")] | ||
impl<'de> Deserialize<'de> for ProposerPriority { | ||
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { | ||
Ok(ProposerPriority( | ||
String::deserialize(deserializer)? | ||
.parse() | ||
.map_err(|e| D::Error::custom(format!("{}", e)))?, | ||
)) | ||
} | ||
} | ||
|
||
#[cfg(feature = "serde")] | ||
impl Serialize for ProposerPriority { | ||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { | ||
self.0.to_string().serialize(serializer) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//! Votes | ||
|
||
#[cfg(feature = "serde")] | ||
pub use serde::{de::Error as DeError, Deserialize, Deserializer, Serialize, Serializer}; | ||
|
||
/// Voting power | ||
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] | ||
pub struct Power(u64); | ||
|
||
impl Power { | ||
/// Get the current voting power | ||
pub fn value(self) -> u64 { | ||
self.0 | ||
} | ||
|
||
/// Is the current voting power zero? | ||
pub fn is_zero(self) -> bool { | ||
self.0 == 0 | ||
} | ||
} | ||
|
||
impl From<Power> for u64 { | ||
fn from(power: Power) -> u64 { | ||
power.0 | ||
} | ||
} | ||
|
||
#[cfg(feature = "serde")] | ||
impl<'de> Deserialize<'de> for Power { | ||
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { | ||
Ok(Power( | ||
String::deserialize(deserializer)? | ||
.parse() | ||
.map_err(|e| D::Error::custom(format!("{}", e)))?, | ||
)) | ||
} | ||
} | ||
|
||
#[cfg(feature = "serde")] | ||
impl Serialize for Power { | ||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { | ||
self.0.to_string().serialize(serializer) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.