-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
752 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod pagination; | ||
|
||
pub use pagination::{PageRequest, PageResponse}; |
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,85 @@ | ||
use crate::proto; | ||
|
||
/// PageRequest is to be embedded in gRPC request messages for efficient | ||
/// pagination. | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct PageRequest { | ||
/// key is a value returned in PageResponse.next_key to begin | ||
/// querying the next page most efficiently. Only one of offset or key | ||
/// should be set. | ||
pub key: Vec<u8>, | ||
|
||
/// offset is a numeric offset that can be used when key is unavailable. | ||
/// It is less efficient than using key. Only one of offset or key should | ||
/// be set. | ||
pub offset: u64, | ||
/// limit is the total number of results to be returned in the result page. | ||
/// If left empty it will default to a value to be set by each app. | ||
pub limit: u64, | ||
/// count_total is set to true to indicate that the result set should include | ||
/// a count of the total number of items available for pagination in UIs. | ||
/// count_total is only respected when offset is used. It is ignored when key | ||
/// is set. | ||
pub count_total: bool, | ||
|
||
/// reverse is set to true if results are to be returned in the descending order. | ||
/// | ||
/// Since: cosmos-sdk 0.43 | ||
pub reverse: bool, | ||
} | ||
|
||
impl From<proto::cosmos::base::query::v1beta1::PageRequest> for PageRequest { | ||
fn from(proto: cosmos_sdk_proto::cosmos::base::query::v1beta1::PageRequest) -> Self { | ||
PageRequest { | ||
key: proto.key, | ||
offset: proto.offset, | ||
limit: proto.limit, | ||
count_total: proto.count_total, | ||
reverse: proto.reverse, | ||
} | ||
} | ||
} | ||
|
||
impl From<PageRequest> for proto::cosmos::base::query::v1beta1::PageRequest { | ||
fn from(page_request: PageRequest) -> Self { | ||
proto::cosmos::base::query::v1beta1::PageRequest { | ||
key: page_request.key, | ||
offset: page_request.offset, | ||
limit: page_request.limit, | ||
count_total: page_request.count_total, | ||
reverse: page_request.reverse, | ||
} | ||
} | ||
} | ||
|
||
/// PageResponse is to be embedded in gRPC response messages where the | ||
/// corresponding request message has used PageRequest. | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct PageResponse { | ||
/// next_key is the key to be passed to PageRequest.key to | ||
/// query the next page most efficiently. It will be empty if | ||
/// there are no more results. | ||
pub next_key: Vec<u8>, | ||
|
||
/// total is total number of results available if PageRequest.count_total | ||
/// was set, its value is undefined otherwise | ||
pub total: u64, | ||
} | ||
|
||
impl From<proto::cosmos::base::query::v1beta1::PageResponse> for PageResponse { | ||
fn from(proto: cosmos_sdk_proto::cosmos::base::query::v1beta1::PageResponse) -> Self { | ||
PageResponse { | ||
next_key: proto.next_key, | ||
total: proto.total, | ||
} | ||
} | ||
} | ||
|
||
impl From<PageResponse> for proto::cosmos::base::query::v1beta1::PageResponse { | ||
fn from(page_response: PageResponse) -> Self { | ||
proto::cosmos::base::query::v1beta1::PageResponse { | ||
next_key: page_response.next_key, | ||
total: page_response.total, | ||
} | ||
} | ||
} |
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::slashing::validator_signing_info::ValidatorSigningInfo; | ||
use crate::{proto, AccountId, ErrorReport, Result}; | ||
|
||
/// SigningInfo stores validator signing info of corresponding address. | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct SigningInfo { | ||
/// address is the validator address. | ||
pub address: AccountId, | ||
|
||
/// validator_signing_info represents the signing info of this validator. | ||
pub validator_signing_info: Option<ValidatorSigningInfo>, | ||
} | ||
|
||
impl TryFrom<proto::cosmos::slashing::v1beta1::SigningInfo> for SigningInfo { | ||
type Error = ErrorReport; | ||
|
||
fn try_from(proto: cosmos_sdk_proto::cosmos::slashing::v1beta1::SigningInfo) -> Result<Self> { | ||
Ok(SigningInfo { | ||
address: proto.address.parse()?, | ||
validator_signing_info: proto | ||
.validator_signing_info | ||
.map(TryInto::try_into) | ||
.transpose()?, | ||
}) | ||
} | ||
} | ||
|
||
impl From<SigningInfo> for cosmos_sdk_proto::cosmos::slashing::v1beta1::SigningInfo { | ||
fn from(signing_info: SigningInfo) -> Self { | ||
cosmos_sdk_proto::cosmos::slashing::v1beta1::SigningInfo { | ||
address: signing_info.address.to_string(), | ||
validator_signing_info: signing_info.validator_signing_info.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,33 @@ | ||
//! Slashing module support | ||
//! | ||
//! <https://docs.cosmos.network/v0.46/modules/slashing/> | ||
mod genesis_state; | ||
mod missed_block; | ||
mod msg_unjail; | ||
mod params; | ||
mod query_params_request; | ||
mod query_params_response; | ||
mod query_signing_info_request; | ||
mod query_signing_info_response; | ||
mod query_signing_infos_request; | ||
mod query_signing_infos_response; | ||
mod signing_info; | ||
mod validator_missed_blocks; | ||
mod validator_signing_info; | ||
|
||
pub use self::{ | ||
genesis_state::GenesisState, | ||
missed_block::MissedBlock, | ||
msg_unjail::{MsgUnjail, MsgUnjailResponse}, | ||
params::Params, | ||
query_params_request::QueryParamsRequest, | ||
query_params_response::QueryParamsResponse, | ||
query_signing_info_request::QuerySigningInfoRequest, | ||
query_signing_info_response::QuerySigningInfoResponse, | ||
query_signing_infos_request::QuerySigningInfosRequest, | ||
query_signing_infos_response::QuerySigningInfosResponse, | ||
signing_info::SigningInfo, | ||
validator_missed_blocks::ValidatorMissedBlocks, | ||
validator_signing_info::ValidatorSigningInfo, | ||
}; |
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,51 @@ | ||
use crate::slashing::{Params, SigningInfo, ValidatorMissedBlocks}; | ||
use crate::{proto, ErrorReport, Result}; | ||
|
||
/// GenesisState defines the slashing module's genesis state. | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct GenesisState { | ||
/// params defines all the paramaters of related to deposit. | ||
pub params: Option<Params>, | ||
|
||
/// signing_infos represents a map between validator addresses and their | ||
/// signing infos. | ||
pub signing_infos: Vec<SigningInfo>, | ||
|
||
/// missed_blocks represents a map between validator addresses and their | ||
/// missed blocks. | ||
pub missed_blocks: Vec<ValidatorMissedBlocks>, | ||
} | ||
|
||
impl TryFrom<proto::cosmos::slashing::v1beta1::GenesisState> for GenesisState { | ||
type Error = ErrorReport; | ||
|
||
fn try_from(proto: cosmos_sdk_proto::cosmos::slashing::v1beta1::GenesisState) -> Result<Self> { | ||
Ok(GenesisState { | ||
params: proto.params.map(TryInto::try_into).transpose()?, | ||
signing_infos: proto | ||
.signing_infos | ||
.into_iter() | ||
.map(TryInto::try_into) | ||
.collect::<Result<_>>()?, | ||
missed_blocks: proto.missed_blocks.into_iter().map(Into::into).collect(), | ||
}) | ||
} | ||
} | ||
|
||
impl From<GenesisState> for cosmos_sdk_proto::cosmos::slashing::v1beta1::GenesisState { | ||
fn from(genesis_state: GenesisState) -> Self { | ||
cosmos_sdk_proto::cosmos::slashing::v1beta1::GenesisState { | ||
params: genesis_state.params.map(Into::into), | ||
signing_infos: genesis_state | ||
.signing_infos | ||
.into_iter() | ||
.map(Into::into) | ||
.collect(), | ||
missed_blocks: genesis_state | ||
.missed_blocks | ||
.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; | ||
|
||
/// MissedBlock contains height and missed status as boolean. | ||
#[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
pub struct MissedBlock { | ||
/// index is the height at which the block was missed. | ||
pub index: i64, | ||
|
||
/// missed is the missed status. | ||
pub missed: bool, | ||
} | ||
|
||
impl From<proto::cosmos::slashing::v1beta1::MissedBlock> for MissedBlock { | ||
fn from(proto: cosmos_sdk_proto::cosmos::slashing::v1beta1::MissedBlock) -> MissedBlock { | ||
MissedBlock { | ||
index: proto.index, | ||
missed: proto.missed, | ||
} | ||
} | ||
} | ||
|
||
impl From<MissedBlock> for cosmos_sdk_proto::cosmos::slashing::v1beta1::MissedBlock { | ||
fn from(missed_block: MissedBlock) -> Self { | ||
cosmos_sdk_proto::cosmos::slashing::v1beta1::MissedBlock { | ||
index: missed_block.index, | ||
missed: missed_block.missed, | ||
} | ||
} | ||
} |
Oops, something went wrong.