@@ -14,6 +14,8 @@ pub type QueryResult = ApiResult<QueryResponse>;
1414#[ serde( rename_all = "snake_case" ) ]
1515pub enum QueryRequest {
1616 Bank ( BankQuery ) ,
17+ #[ cfg( feature = "staking" ) ]
18+ Staking ( StakingRequest ) ,
1719 Wasm ( WasmQuery ) ,
1820}
1921
@@ -61,3 +63,66 @@ pub struct AllBalanceResponse {
6163 // Returns all non-zero coins held by this account.
6264 pub amount : Vec < Coin > ,
6365}
66+
67+ #[ cfg( feature = "staking" ) ]
68+ pub use staking:: { Delegation , DelegationsResponse , StakingRequest , Validator , ValidatorsResponse } ;
69+
70+ #[ cfg( feature = "staking" ) ]
71+ mod staking {
72+ use schemars:: JsonSchema ;
73+ use serde:: { Deserialize , Serialize } ;
74+
75+ use crate :: coins:: Coin ;
76+ use crate :: types:: HumanAddr ;
77+
78+ #[ derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema ) ]
79+ #[ serde( rename_all = "snake_case" ) ]
80+ pub enum StakingRequest {
81+ Validators { } ,
82+ // Delegations will return all delegations by the delegator,
83+ // or just those to the given validator (if set)
84+ Delegations {
85+ delegator : HumanAddr ,
86+ validator : Option < HumanAddr > ,
87+ } ,
88+ }
89+
90+ #[ cfg( feature = "staking" ) ]
91+ #[ derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema ) ]
92+ /// ValidatorsResponse is data format returned from StakingRequest::Validators query
93+ pub struct ValidatorsResponse {
94+ pub validators : Vec < Validator > ,
95+ }
96+
97+ #[ cfg( feature = "staking" ) ]
98+ #[ derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema ) ]
99+ pub struct Validator {
100+ pub address : HumanAddr ,
101+ // rates are denominated in 10^-6 - 1_000_000 (max) = 100%, 10_000 = 1%
102+ // TODO: capture this in some Dec type?
103+ pub commission : u64 ,
104+ pub max_commission : u64 ,
105+ // what units are these (in terms of time)?
106+ pub max_change_rate : u64 ,
107+ }
108+
109+ #[ cfg( feature = "staking" ) ]
110+ #[ derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema ) ]
111+ #[ serde( rename_all = "snake_case" ) ]
112+ /// DelegationsResponse is data format returned from StakingRequest::Delegations query
113+ pub struct DelegationsResponse {
114+ pub delegations : Vec < Delegation > ,
115+ }
116+
117+ #[ cfg( feature = "staking" ) ]
118+ #[ derive( Serialize , Deserialize , Clone , Debug , PartialEq , JsonSchema ) ]
119+ pub struct Delegation {
120+ pub delegator : HumanAddr ,
121+ pub validator : HumanAddr ,
122+ pub amount : Coin ,
123+ pub can_redelegate : bool ,
124+ // Review this: this is how much we can withdraw
125+ pub accumulated_rewards : Coin ,
126+ // TODO: do we want to expose more info?
127+ }
128+ }
0 commit comments