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: /genesis RPC endpoint and related types
Adds support for parsing genesis files from RPC responses. Genesis files are generic over the underlying application, and by default use `serde_json::Value` to model arbitrary JSON data.
- Loading branch information
1 parent
030109d
commit 3051870
Showing
24 changed files
with
19,543 additions
and
68 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
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
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,32 @@ | ||
//! Block size parameters | ||
|
||
#[cfg(feature = "serde")] | ||
use { | ||
crate::serializers, | ||
serde::{Deserialize, Serialize}, | ||
}; | ||
|
||
/// Block size parameters | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct Size { | ||
/// Maximum number of bytes in a block | ||
#[cfg_attr( | ||
feature = "serde", | ||
serde( | ||
serialize_with = "serializers::serialize_u64", | ||
deserialize_with = "serializers::parse_u64" | ||
) | ||
)] | ||
pub max_bytes: u64, | ||
|
||
/// Maximum amount of gas which can be spent on a block | ||
#[cfg_attr( | ||
feature = "serde", | ||
serde( | ||
serialize_with = "serializers::serialize_u64", | ||
deserialize_with = "serializers::parse_u64" | ||
) | ||
)] | ||
pub max_gas: u64, | ||
} |
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 |
---|---|---|
|
@@ -2,10 +2,8 @@ | |
|
||
pub mod id; | ||
mod info; | ||
pub mod state; | ||
|
||
pub use self::{ | ||
id::{Id, ParseId}, | ||
info::*, | ||
state::ConsensusState, | ||
}; |
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
//! Tendermint consensus | ||
|
||
mod params; | ||
mod state; | ||
|
||
pub use self::{params::Params, state::State}; |
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,27 @@ | ||
//! Tendermint consensus parameters | ||
|
||
use crate::{block, evidence, public_key}; | ||
#[cfg(feature = "serde")] | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Tendermint consensus parameters | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct Params { | ||
/// Block size parameters | ||
pub block_size: block::Size, | ||
|
||
/// Evidence parameters | ||
pub evidence: evidence::Params, | ||
|
||
/// Validator parameters | ||
pub validator: ValidatorParams, | ||
} | ||
|
||
/// Validator consensus parameters | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct ValidatorParams { | ||
/// Allowed algorithms for validator signing | ||
pub pub_key_types: Vec<public_key::Algorithm>, | ||
} |
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,99 @@ | ||
//! Tendermint consensus state | ||
|
||
pub use crate::block; | ||
pub use std::cmp::Ordering; | ||
#[cfg(feature = "serde")] | ||
use { | ||
crate::serializers, | ||
serde::{Deserialize, Serialize}, | ||
}; | ||
|
||
/// Tendermint consensus state | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
#[derive(Clone, Debug, Default, Eq, PartialEq)] | ||
pub struct State { | ||
/// Current block height | ||
pub height: block::Height, | ||
|
||
/// Current consensus round | ||
#[cfg_attr( | ||
feature = "serde", | ||
serde( | ||
serialize_with = "serializers::serialize_i64", | ||
deserialize_with = "serializers::parse_i64" | ||
) | ||
)] | ||
pub round: i64, | ||
|
||
/// Current consensus step | ||
pub step: i8, | ||
|
||
/// Block ID being proposed (if available) | ||
pub block_id: Option<block::Id>, | ||
} | ||
|
||
impl Ord for State { | ||
fn cmp(&self, other: &State) -> Ordering { | ||
if self.height < other.height { | ||
Ordering::Less | ||
} else if self.height == other.height { | ||
if self.round < other.round { | ||
Ordering::Less | ||
} else if self.round == other.round { | ||
self.step.cmp(&other.step) | ||
} else { | ||
Ordering::Greater | ||
} | ||
} else { | ||
Ordering::Greater | ||
} | ||
} | ||
} | ||
|
||
impl PartialOrd for State { | ||
fn partial_cmp(&self, other: &State) -> Option<Ordering> { | ||
Some(self.cmp(other)) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::State; | ||
use crate::block; | ||
|
||
#[test] | ||
fn state_ord_test() { | ||
let new = State { | ||
height: block::Height::from(9001u64), | ||
round: 0, | ||
step: 0, | ||
block_id: None, | ||
}; | ||
|
||
let old = State { | ||
height: block::Height::from(1001u64), | ||
round: 1, | ||
step: 0, | ||
block_id: None, | ||
}; | ||
|
||
let older = State { | ||
height: block::Height::from(1001u64), | ||
round: 0, | ||
step: 0, | ||
block_id: None, | ||
}; | ||
|
||
let oldest = State { | ||
height: block::Height::default(), | ||
round: 0, | ||
step: 0, | ||
block_id: None, | ||
}; | ||
|
||
assert!(old < new); | ||
assert!(older < old); | ||
assert!(oldest < older); | ||
assert!(oldest < new); | ||
} | ||
} |
Oops, something went wrong.