From cf2590089647be78597b73826ff49794d07aabcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Tue, 5 Dec 2023 17:00:07 +0000 Subject: [PATCH] added support for validator-related queries in staking module --- cosmrs/src/staking.rs | 22 +++- cosmrs/src/staking/commision_rates.rs | 35 ++++++ cosmrs/src/staking/commission.rs | 49 +++++++++ cosmrs/src/staking/description.rs | 44 ++++++++ cosmrs/src/staking/historical_info.rs | 40 +++++++ .../staking/query_historical_info_request.rs | 29 +++++ .../staking/query_historical_info_response.rs | 34 ++++++ cosmrs/src/staking/query_validator_request.rs | 28 +++++ .../src/staking/query_validator_response.rs | 29 +++++ .../src/staking/query_validators_request.rs | 34 ++++++ .../src/staking/query_validators_response.rs | 43 ++++++++ cosmrs/src/staking/validator.rs | 102 ++++++++++++++++++ 12 files changed, 487 insertions(+), 2 deletions(-) create mode 100644 cosmrs/src/staking/commision_rates.rs create mode 100644 cosmrs/src/staking/commission.rs create mode 100644 cosmrs/src/staking/description.rs create mode 100644 cosmrs/src/staking/historical_info.rs create mode 100644 cosmrs/src/staking/query_historical_info_request.rs create mode 100644 cosmrs/src/staking/query_historical_info_response.rs create mode 100644 cosmrs/src/staking/query_validator_request.rs create mode 100644 cosmrs/src/staking/query_validator_response.rs create mode 100644 cosmrs/src/staking/query_validators_request.rs create mode 100644 cosmrs/src/staking/query_validators_response.rs create mode 100644 cosmrs/src/staking/validator.rs diff --git a/cosmrs/src/staking.rs b/cosmrs/src/staking.rs index 00f91a3b..80ae5dd0 100644 --- a/cosmrs/src/staking.rs +++ b/cosmrs/src/staking.rs @@ -2,11 +2,29 @@ //! //! +mod commision_rates; +mod commission; +mod description; +mod historical_info; mod msg_begin_redelegate; mod msg_delegate; mod msg_undelegate; +mod query_historical_info_request; +mod query_historical_info_response; +mod query_validator_request; +mod query_validator_response; +mod query_validators_request; +mod query_validators_response; +mod validator; pub use self::{ - msg_begin_redelegate::MsgBeginRedelegate, msg_delegate::MsgDelegate, - msg_undelegate::MsgUndelegate, + commision_rates::CommissionRates, commission::Commission, description::Description, + historical_info::HistoricalInfo, msg_begin_redelegate::MsgBeginRedelegate, + msg_delegate::MsgDelegate, msg_undelegate::MsgUndelegate, + query_historical_info_request::QueryHistoricalInfoRequest, + query_historical_info_response::QueryHistoricalInfoResponse, + query_validator_request::QueryValidatorRequest, + query_validator_response::QueryValidatorResponse, + query_validators_request::QueryValidatorsRequest, + query_validators_response::QueryValidatorsResponse, validator::Validator, }; diff --git a/cosmrs/src/staking/commision_rates.rs b/cosmrs/src/staking/commision_rates.rs new file mode 100644 index 00000000..ec8a3ce6 --- /dev/null +++ b/cosmrs/src/staking/commision_rates.rs @@ -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 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 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, + } + } +} diff --git a/cosmrs/src/staking/commission.rs b/cosmrs/src/staking/commission.rs new file mode 100644 index 00000000..67471f2c --- /dev/null +++ b/cosmrs/src/staking/commission.rs @@ -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, + + /// update_time is the last time the commission rate was changed. + pub update_time: Option