Skip to content

Commit ce00cf8

Browse files
authored
added support for slashing module (#452)
1 parent 08353cb commit ce00cf8

20 files changed

+717
-1
lines changed

cosmos-sdk-proto/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub mod traits;
1515
mod type_names;
1616

1717
pub use prost;
18-
pub use prost_types::Any;
18+
pub use prost_types::{Any, Timestamp};
1919
pub use tendermint_proto as tendermint;
2020

2121
/// The version (commit hash) of the Cosmos SDK used when generating this library.

cosmos-sdk-proto/src/type_names.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,77 @@ impl_name!(
169169
"AllowedMsgAllowance"
170170
);
171171

172+
impl_name!(
173+
cosmos::slashing::v1beta1::GenesisState,
174+
"cosmos.slashing.v1beta1",
175+
"MissedBlocks"
176+
);
177+
impl_name!(
178+
cosmos::slashing::v1beta1::MissedBlock,
179+
"cosmos.slashing.v1beta1",
180+
"MissedBlock"
181+
);
182+
impl_name!(
183+
cosmos::slashing::v1beta1::MsgUnjail,
184+
"cosmos.slashing.v1beta1",
185+
"MsgUnjail"
186+
);
187+
impl_name!(
188+
cosmos::slashing::v1beta1::MsgUnjailResponse,
189+
"cosmos.slashing.v1beta1",
190+
"MsgUnjailResponse"
191+
);
192+
impl_name!(
193+
cosmos::slashing::v1beta1::Params,
194+
"cosmos.slashing.v1beta1",
195+
"Params"
196+
);
197+
impl_name!(
198+
cosmos::slashing::v1beta1::QueryParamsRequest,
199+
"cosmos.slashing.v1beta1",
200+
"QueryParamsRequest"
201+
);
202+
impl_name!(
203+
cosmos::slashing::v1beta1::QueryParamsResponse,
204+
"cosmos.slashing.v1beta1",
205+
"QueryParamsResponse"
206+
);
207+
impl_name!(
208+
cosmos::slashing::v1beta1::QuerySigningInfoRequest,
209+
"cosmos.slashing.v1beta1",
210+
"QuerySigningInfoRequest"
211+
);
212+
impl_name!(
213+
cosmos::slashing::v1beta1::QuerySigningInfoResponse,
214+
"cosmos.slashing.v1beta1",
215+
"QuerySigningInfoResponse"
216+
);
217+
impl_name!(
218+
cosmos::slashing::v1beta1::QuerySigningInfosRequest,
219+
"cosmos.slashing.v1beta1",
220+
"QuerySigningInfosRequest"
221+
);
222+
impl_name!(
223+
cosmos::slashing::v1beta1::QuerySigningInfosResponse,
224+
"cosmos.slashing.v1beta1",
225+
"QuerySigningInfosResponse"
226+
);
227+
impl_name!(
228+
cosmos::slashing::v1beta1::SigningInfo,
229+
"cosmos.slashing.v1beta1",
230+
"SigningInfo"
231+
);
232+
impl_name!(
233+
cosmos::slashing::v1beta1::ValidatorMissedBlocks,
234+
"cosmos.slashing.v1beta1",
235+
"ValidatorMissedBlocks"
236+
);
237+
impl_name!(
238+
cosmos::slashing::v1beta1::ValidatorSigningInfo,
239+
"cosmos.slashing.v1beta1",
240+
"ValidatorSigningInfo"
241+
);
242+
172243
impl_name!(
173244
cosmos::staking::v1beta1::MsgEditValidatorResponse,
174245
"cosmos.staking.v1beta1",

cosmrs/src/base.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ mod account_id;
44
mod coin;
55
mod denom;
66

7+
pub mod query;
8+
79
pub use self::{account_id::AccountId, coin::Coin, denom::Denom};
810

911
/// Amounts.

cosmrs/src/base/query.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod pagination;
2+
3+
pub use pagination::{PageRequest, PageResponse};
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
use crate::proto;
2+
3+
/// PageRequest is to be embedded in gRPC request messages for efficient
4+
/// pagination.
5+
#[derive(Clone, Debug, Eq, PartialEq)]
6+
pub struct PageRequest {
7+
/// key is a value returned in PageResponse.next_key to begin
8+
/// querying the next page most efficiently. Only one of offset or key
9+
/// should be set.
10+
pub key: Vec<u8>,
11+
12+
/// offset is a numeric offset that can be used when key is unavailable.
13+
/// It is less efficient than using key. Only one of offset or key should
14+
/// be set.
15+
pub offset: u64,
16+
/// limit is the total number of results to be returned in the result page.
17+
/// If left empty it will default to a value to be set by each app.
18+
pub limit: u64,
19+
/// count_total is set to true to indicate that the result set should include
20+
/// a count of the total number of items available for pagination in UIs.
21+
/// count_total is only respected when offset is used. It is ignored when key
22+
/// is set.
23+
pub count_total: bool,
24+
25+
/// reverse is set to true if results are to be returned in the descending order.
26+
///
27+
/// Since: cosmos-sdk 0.43
28+
pub reverse: bool,
29+
}
30+
31+
impl From<proto::cosmos::base::query::v1beta1::PageRequest> for PageRequest {
32+
fn from(proto: cosmos_sdk_proto::cosmos::base::query::v1beta1::PageRequest) -> Self {
33+
PageRequest {
34+
key: proto.key,
35+
offset: proto.offset,
36+
limit: proto.limit,
37+
count_total: proto.count_total,
38+
reverse: proto.reverse,
39+
}
40+
}
41+
}
42+
43+
impl From<PageRequest> for proto::cosmos::base::query::v1beta1::PageRequest {
44+
fn from(page_request: PageRequest) -> Self {
45+
proto::cosmos::base::query::v1beta1::PageRequest {
46+
key: page_request.key,
47+
offset: page_request.offset,
48+
limit: page_request.limit,
49+
count_total: page_request.count_total,
50+
reverse: page_request.reverse,
51+
}
52+
}
53+
}
54+
55+
/// PageResponse is to be embedded in gRPC response messages where the
56+
/// corresponding request message has used PageRequest.
57+
#[derive(Clone, Debug, Eq, PartialEq)]
58+
pub struct PageResponse {
59+
/// next_key is the key to be passed to PageRequest.key to
60+
/// query the next page most efficiently. It will be empty if
61+
/// there are no more results.
62+
pub next_key: Vec<u8>,
63+
64+
/// total is total number of results available if PageRequest.count_total
65+
/// was set, its value is undefined otherwise
66+
pub total: u64,
67+
}
68+
69+
impl From<proto::cosmos::base::query::v1beta1::PageResponse> for PageResponse {
70+
fn from(proto: cosmos_sdk_proto::cosmos::base::query::v1beta1::PageResponse) -> Self {
71+
PageResponse {
72+
next_key: proto.next_key,
73+
total: proto.total,
74+
}
75+
}
76+
}
77+
78+
impl From<PageResponse> for proto::cosmos::base::query::v1beta1::PageResponse {
79+
fn from(page_response: PageResponse) -> Self {
80+
proto::cosmos::base::query::v1beta1::PageResponse {
81+
next_key: page_response.next_key,
82+
total: page_response.total,
83+
}
84+
}
85+
}

cosmrs/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub mod bank;
3232
pub mod crypto;
3333
pub mod distribution;
3434
pub mod feegrant;
35+
pub mod slashing;
3536
pub mod staking;
3637
pub mod tx;
3738
pub mod vesting;

cosmrs/src/slashing.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! Slashing module support
2+
//!
3+
//! <https://docs.cosmos.network/v0.46/modules/slashing/>
4+
5+
mod genesis_state;
6+
mod missed_block;
7+
mod msg_unjail;
8+
mod params;
9+
mod query_params_request;
10+
mod query_params_response;
11+
mod query_signing_info_request;
12+
mod query_signing_info_response;
13+
mod query_signing_infos_request;
14+
mod query_signing_infos_response;
15+
mod signing_info;
16+
mod validator_missed_blocks;
17+
mod validator_signing_info;
18+
19+
pub use self::{
20+
genesis_state::GenesisState,
21+
missed_block::MissedBlock,
22+
msg_unjail::{MsgUnjail, MsgUnjailResponse},
23+
params::Params,
24+
query_params_request::QueryParamsRequest,
25+
query_params_response::QueryParamsResponse,
26+
query_signing_info_request::QuerySigningInfoRequest,
27+
query_signing_info_response::QuerySigningInfoResponse,
28+
query_signing_infos_request::QuerySigningInfosRequest,
29+
query_signing_infos_response::QuerySigningInfosResponse,
30+
signing_info::SigningInfo,
31+
validator_missed_blocks::ValidatorMissedBlocks,
32+
validator_signing_info::ValidatorSigningInfo,
33+
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use crate::slashing::{Params, SigningInfo, ValidatorMissedBlocks};
2+
use crate::{proto, ErrorReport, Result};
3+
4+
/// GenesisState defines the slashing module's genesis state.
5+
#[derive(Clone, Debug, Eq, PartialEq)]
6+
pub struct GenesisState {
7+
/// params defines all the paramaters of related to deposit.
8+
pub params: Option<Params>,
9+
10+
/// signing_infos represents a map between validator addresses and their
11+
/// signing infos.
12+
pub signing_infos: Vec<SigningInfo>,
13+
14+
/// missed_blocks represents a map between validator addresses and their
15+
/// missed blocks.
16+
pub missed_blocks: Vec<ValidatorMissedBlocks>,
17+
}
18+
19+
impl TryFrom<proto::cosmos::slashing::v1beta1::GenesisState> for GenesisState {
20+
type Error = ErrorReport;
21+
22+
fn try_from(proto: cosmos_sdk_proto::cosmos::slashing::v1beta1::GenesisState) -> Result<Self> {
23+
Ok(GenesisState {
24+
params: proto.params.map(TryInto::try_into).transpose()?,
25+
signing_infos: proto
26+
.signing_infos
27+
.into_iter()
28+
.map(TryInto::try_into)
29+
.collect::<Result<_>>()?,
30+
missed_blocks: proto.missed_blocks.into_iter().map(Into::into).collect(),
31+
})
32+
}
33+
}
34+
35+
impl From<GenesisState> for cosmos_sdk_proto::cosmos::slashing::v1beta1::GenesisState {
36+
fn from(genesis_state: GenesisState) -> Self {
37+
cosmos_sdk_proto::cosmos::slashing::v1beta1::GenesisState {
38+
params: genesis_state.params.map(Into::into),
39+
signing_infos: genesis_state
40+
.signing_infos
41+
.into_iter()
42+
.map(Into::into)
43+
.collect(),
44+
missed_blocks: genesis_state
45+
.missed_blocks
46+
.into_iter()
47+
.map(Into::into)
48+
.collect(),
49+
}
50+
}
51+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use crate::proto;
2+
3+
/// MissedBlock contains height and missed status as boolean.
4+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5+
pub struct MissedBlock {
6+
/// index is the height at which the block was missed.
7+
pub index: i64,
8+
9+
/// missed is the missed status.
10+
pub missed: bool,
11+
}
12+
13+
impl From<proto::cosmos::slashing::v1beta1::MissedBlock> for MissedBlock {
14+
fn from(proto: cosmos_sdk_proto::cosmos::slashing::v1beta1::MissedBlock) -> MissedBlock {
15+
MissedBlock {
16+
index: proto.index,
17+
missed: proto.missed,
18+
}
19+
}
20+
}
21+
22+
impl From<MissedBlock> for cosmos_sdk_proto::cosmos::slashing::v1beta1::MissedBlock {
23+
fn from(missed_block: MissedBlock) -> Self {
24+
cosmos_sdk_proto::cosmos::slashing::v1beta1::MissedBlock {
25+
index: missed_block.index,
26+
missed: missed_block.missed,
27+
}
28+
}
29+
}

cosmrs/src/slashing/msg_unjail.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use crate::{proto, tx::Msg, AccountId, ErrorReport, Result};
2+
3+
/// MsgUnjail defines the Msg/Unjail request type
4+
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
5+
pub struct MsgUnjail {
6+
/// Address of the validator to unjail.
7+
pub validator_addr: AccountId,
8+
}
9+
10+
impl Msg for MsgUnjail {
11+
type Proto = proto::cosmos::slashing::v1beta1::MsgUnjail;
12+
}
13+
14+
impl TryFrom<proto::cosmos::slashing::v1beta1::MsgUnjail> for MsgUnjail {
15+
type Error = ErrorReport;
16+
17+
fn try_from(proto: cosmos_sdk_proto::cosmos::slashing::v1beta1::MsgUnjail) -> Result<Self> {
18+
Ok(MsgUnjail {
19+
validator_addr: proto.validator_addr.parse()?,
20+
})
21+
}
22+
}
23+
24+
impl From<MsgUnjail> for cosmos_sdk_proto::cosmos::slashing::v1beta1::MsgUnjail {
25+
fn from(msg_unjail: MsgUnjail) -> Self {
26+
cosmos_sdk_proto::cosmos::slashing::v1beta1::MsgUnjail {
27+
validator_addr: msg_unjail.validator_addr.to_string(),
28+
}
29+
}
30+
}
31+
32+
/// MsgUnjailResponse defines the Msg/Unjail response type
33+
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)]
34+
pub struct MsgUnjailResponse {}
35+
36+
impl Msg for MsgUnjailResponse {
37+
type Proto = proto::cosmos::slashing::v1beta1::MsgUnjailResponse;
38+
}
39+
40+
impl TryFrom<proto::cosmos::slashing::v1beta1::MsgUnjailResponse> for MsgUnjailResponse {
41+
type Error = ErrorReport;
42+
43+
fn try_from(
44+
_proto: cosmos_sdk_proto::cosmos::slashing::v1beta1::MsgUnjailResponse,
45+
) -> Result<Self> {
46+
Ok(MsgUnjailResponse {})
47+
}
48+
}
49+
50+
impl From<MsgUnjailResponse> for cosmos_sdk_proto::cosmos::slashing::v1beta1::MsgUnjailResponse {
51+
fn from(_: MsgUnjailResponse) -> Self {
52+
cosmos_sdk_proto::cosmos::slashing::v1beta1::MsgUnjailResponse {}
53+
}
54+
}

0 commit comments

Comments
 (0)