-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for validator-related queries in staking module
- Loading branch information
Showing
12 changed files
with
487 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::proto; | ||
|
||
/// CommissionRates defines the initial commission rates to be used for creating | ||
/// a validator. | ||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] | ||
pub struct CommissionRates { | ||
/// rate is the commission rate charged to delegators, as a fraction. | ||
pub rate: String, | ||
|
||
/// max_rate defines the maximum commission rate which validator can ever charge, as a fraction. | ||
pub max_rate: String, | ||
|
||
/// max_change_rate defines the maximum daily increase of the validator commission, as a fraction. | ||
pub max_change_rate: String, | ||
} | ||
|
||
impl From<proto::cosmos::staking::v1beta1::CommissionRates> for CommissionRates { | ||
fn from(proto: cosmos_sdk_proto::cosmos::staking::v1beta1::CommissionRates) -> Self { | ||
CommissionRates { | ||
rate: proto.rate, | ||
max_rate: proto.max_rate, | ||
max_change_rate: proto.max_change_rate, | ||
} | ||
} | ||
} | ||
|
||
impl From<CommissionRates> for proto::cosmos::staking::v1beta1::CommissionRates { | ||
fn from(commission_rates: CommissionRates) -> Self { | ||
proto::cosmos::staking::v1beta1::CommissionRates { | ||
rate: commission_rates.rate, | ||
max_rate: commission_rates.max_rate, | ||
max_change_rate: commission_rates.max_change_rate, | ||
} | ||
} | ||
} |
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,49 @@ | ||
use crate::staking::CommissionRates; | ||
use crate::{proto, ErrorReport, Result}; | ||
use cosmos_sdk_proto::Timestamp; | ||
use tendermint::Time; | ||
|
||
/// Commission defines commission parameters for a given validator. | ||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] | ||
pub struct Commission { | ||
/// commission_rates defines the initial commission rates to be used for creating a validator. | ||
pub commission_rates: Option<CommissionRates>, | ||
|
||
/// update_time is the last time the commission rate was changed. | ||
pub update_time: Option<Time>, | ||
} | ||
|
||
impl TryFrom<proto::cosmos::staking::v1beta1::Commission> for Commission { | ||
type Error = ErrorReport; | ||
|
||
fn try_from(proto: cosmos_sdk_proto::cosmos::staking::v1beta1::Commission) -> Result<Self> { | ||
Ok(Commission { | ||
commission_rates: proto.commission_rates.map(Into::into), | ||
update_time: proto | ||
.update_time | ||
.map(|jailed_until| { | ||
cosmos_sdk_proto::tendermint::google::protobuf::Timestamp { | ||
seconds: jailed_until.seconds, | ||
nanos: jailed_until.nanos, | ||
} | ||
.try_into() | ||
}) | ||
.transpose()?, | ||
}) | ||
} | ||
} | ||
|
||
impl From<Commission> for proto::cosmos::staking::v1beta1::Commission { | ||
fn from(commission: Commission) -> Self { | ||
proto::cosmos::staking::v1beta1::Commission { | ||
commission_rates: commission.commission_rates.map(Into::into), | ||
update_time: commission | ||
.update_time | ||
.map(cosmos_sdk_proto::tendermint::google::protobuf::Timestamp::from) | ||
.map(|t| Timestamp { | ||
seconds: t.seconds, | ||
nanos: t.nanos, | ||
}), | ||
} | ||
} | ||
} |
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 @@ | ||
use crate::proto; | ||
|
||
/// Description defines a validator description. | ||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] | ||
pub struct Description { | ||
/// moniker defines a human-readable name for the validator. | ||
pub moniker: String, | ||
|
||
/// identity defines an optional identity signature (ex. UPort or Keybase). | ||
pub identity: String, | ||
|
||
/// website defines an optional website link. | ||
pub website: String, | ||
|
||
/// security_contact defines an optional email for security contact. | ||
pub security_contact: String, | ||
|
||
/// details define other optional details. | ||
pub details: String, | ||
} | ||
|
||
impl From<proto::cosmos::staking::v1beta1::Description> for Description { | ||
fn from(proto: cosmos_sdk_proto::cosmos::staking::v1beta1::Description) -> Self { | ||
Description { | ||
moniker: proto.moniker, | ||
identity: proto.identity, | ||
website: proto.website, | ||
security_contact: proto.security_contact, | ||
details: proto.details, | ||
} | ||
} | ||
} | ||
|
||
impl From<Description> for proto::cosmos::staking::v1beta1::Description { | ||
fn from(description: Description) -> Self { | ||
proto::cosmos::staking::v1beta1::Description { | ||
moniker: description.moniker, | ||
identity: description.identity, | ||
website: description.website, | ||
security_contact: description.security_contact, | ||
details: description.details, | ||
} | ||
} | ||
} |
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,40 @@ | ||
use crate::staking::Validator; | ||
use crate::{proto, ErrorReport, Result}; | ||
use tendermint::block::Header; | ||
|
||
/// HistoricalInfo contains header and validator information for a given block. | ||
/// It is stored as part of staking module's state, which persists the `n` most | ||
/// recent HistoricalInfo | ||
/// (`n` is set by the staking module's `historical_entries` parameter). | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct HistoricalInfo { | ||
/// Header of the block | ||
pub header: Option<Header>, | ||
|
||
/// The validator set at the block | ||
pub valset: Vec<Validator>, | ||
} | ||
|
||
impl TryFrom<proto::cosmos::staking::v1beta1::HistoricalInfo> for HistoricalInfo { | ||
type Error = ErrorReport; | ||
|
||
fn try_from(proto: cosmos_sdk_proto::cosmos::staking::v1beta1::HistoricalInfo) -> Result<Self> { | ||
Ok(HistoricalInfo { | ||
header: proto.header.map(TryInto::try_into).transpose()?, | ||
valset: proto | ||
.valset | ||
.into_iter() | ||
.map(TryInto::try_into) | ||
.collect::<Result<_>>()?, | ||
}) | ||
} | ||
} | ||
|
||
impl From<HistoricalInfo> for proto::cosmos::staking::v1beta1::HistoricalInfo { | ||
fn from(historical_info: HistoricalInfo) -> Self { | ||
proto::cosmos::staking::v1beta1::HistoricalInfo { | ||
header: historical_info.header.map(Into::into), | ||
valset: historical_info.valset.into_iter().map(Into::into).collect(), | ||
} | ||
} | ||
} |
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,29 @@ | ||
use crate::proto; | ||
|
||
/// QueryHistoricalInfoRequest is request type for the Query/HistoricalInfo RPC | ||
/// method. | ||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] | ||
pub struct QueryHistoricalInfoRequest { | ||
/// height defines at which height to query the historical info. | ||
pub height: i64, | ||
} | ||
|
||
impl From<proto::cosmos::staking::v1beta1::QueryHistoricalInfoRequest> | ||
for QueryHistoricalInfoRequest | ||
{ | ||
fn from(proto: cosmos_sdk_proto::cosmos::staking::v1beta1::QueryHistoricalInfoRequest) -> Self { | ||
QueryHistoricalInfoRequest { | ||
height: proto.height, | ||
} | ||
} | ||
} | ||
|
||
impl From<QueryHistoricalInfoRequest> | ||
for proto::cosmos::staking::v1beta1::QueryHistoricalInfoRequest | ||
{ | ||
fn from(query_historical_info_request: QueryHistoricalInfoRequest) -> Self { | ||
proto::cosmos::staking::v1beta1::QueryHistoricalInfoRequest { | ||
height: query_historical_info_request.height, | ||
} | ||
} | ||
} |
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,34 @@ | ||
use crate::staking::HistoricalInfo; | ||
use crate::{proto, ErrorReport, Result}; | ||
|
||
/// QueryHistoricalInfoResponse is response type for the Query/HistoricalInfo RPC | ||
/// method. | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct QueryHistoricalInfoResponse { | ||
/// hist defines the historical info at the given height. | ||
pub hist: Option<HistoricalInfo>, | ||
} | ||
|
||
impl TryFrom<proto::cosmos::staking::v1beta1::QueryHistoricalInfoResponse> | ||
for QueryHistoricalInfoResponse | ||
{ | ||
type Error = ErrorReport; | ||
|
||
fn try_from( | ||
proto: cosmos_sdk_proto::cosmos::staking::v1beta1::QueryHistoricalInfoResponse, | ||
) -> Result<Self> { | ||
Ok(QueryHistoricalInfoResponse { | ||
hist: proto.hist.map(TryInto::try_into).transpose()?, | ||
}) | ||
} | ||
} | ||
|
||
impl From<QueryHistoricalInfoResponse> | ||
for proto::cosmos::staking::v1beta1::QueryHistoricalInfoResponse | ||
{ | ||
fn from(query_historical_info_response: QueryHistoricalInfoResponse) -> Self { | ||
proto::cosmos::staking::v1beta1::QueryHistoricalInfoResponse { | ||
hist: query_historical_info_response.hist.map(Into::into), | ||
} | ||
} | ||
} |
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,28 @@ | ||
use crate::{proto, AccountId, ErrorReport, Result}; | ||
|
||
/// QueryValidatorRequest is response type for the Query/Validator RPC method | ||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] | ||
pub struct QueryValidatorRequest { | ||
/// validator_addr defines the validator address to query for. | ||
pub validator_addr: AccountId, | ||
} | ||
|
||
impl TryFrom<proto::cosmos::staking::v1beta1::QueryValidatorRequest> for QueryValidatorRequest { | ||
type Error = ErrorReport; | ||
|
||
fn try_from( | ||
proto: cosmos_sdk_proto::cosmos::staking::v1beta1::QueryValidatorRequest, | ||
) -> Result<Self> { | ||
Ok(QueryValidatorRequest { | ||
validator_addr: proto.validator_addr.parse()?, | ||
}) | ||
} | ||
} | ||
|
||
impl From<QueryValidatorRequest> for proto::cosmos::staking::v1beta1::QueryValidatorRequest { | ||
fn from(query_validator_request: QueryValidatorRequest) -> Self { | ||
proto::cosmos::staking::v1beta1::QueryValidatorRequest { | ||
validator_addr: query_validator_request.validator_addr.to_string(), | ||
} | ||
} | ||
} |
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,29 @@ | ||
use crate::staking::Validator; | ||
use crate::{proto, ErrorReport, Result}; | ||
|
||
/// QueryValidatorResponse is response type for the Query/Validator RPC method | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct QueryValidatorResponse { | ||
/// validator defines the validator info. | ||
pub validator: Option<Validator>, | ||
} | ||
|
||
impl TryFrom<proto::cosmos::staking::v1beta1::QueryValidatorResponse> for QueryValidatorResponse { | ||
type Error = ErrorReport; | ||
|
||
fn try_from( | ||
proto: cosmos_sdk_proto::cosmos::staking::v1beta1::QueryValidatorResponse, | ||
) -> Result<Self> { | ||
Ok(QueryValidatorResponse { | ||
validator: proto.validator.map(TryInto::try_into).transpose()?, | ||
}) | ||
} | ||
} | ||
|
||
impl From<QueryValidatorResponse> for proto::cosmos::staking::v1beta1::QueryValidatorResponse { | ||
fn from(query_validator_response: QueryValidatorResponse) -> Self { | ||
proto::cosmos::staking::v1beta1::QueryValidatorResponse { | ||
validator: query_validator_response.validator.map(Into::into), | ||
} | ||
} | ||
} |
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,34 @@ | ||
use crate::base::query::PageRequest; | ||
use crate::{proto, ErrorReport, Result}; | ||
|
||
/// QueryValidatorsRequest is request type for Query/Validators RPC method. | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct QueryValidatorsRequest { | ||
/// status enables to query for validators matching a given status. | ||
pub status: String, | ||
|
||
/// pagination defines an optional pagination for the request. | ||
pub pagination: Option<PageRequest>, | ||
} | ||
|
||
impl TryFrom<proto::cosmos::staking::v1beta1::QueryValidatorsRequest> for QueryValidatorsRequest { | ||
type Error = ErrorReport; | ||
|
||
fn try_from( | ||
proto: cosmos_sdk_proto::cosmos::staking::v1beta1::QueryValidatorsRequest, | ||
) -> Result<Self> { | ||
Ok(QueryValidatorsRequest { | ||
status: proto.status, | ||
pagination: proto.pagination.map(Into::into), | ||
}) | ||
} | ||
} | ||
|
||
impl From<QueryValidatorsRequest> for proto::cosmos::staking::v1beta1::QueryValidatorsRequest { | ||
fn from(query_validators_request: QueryValidatorsRequest) -> Self { | ||
proto::cosmos::staking::v1beta1::QueryValidatorsRequest { | ||
status: query_validators_request.status, | ||
pagination: query_validators_request.pagination.map(Into::into), | ||
} | ||
} | ||
} |
Oops, something went wrong.