Skip to content

Commit 2fa131a

Browse files
committed
Hide staking query types behind feature flag
1 parent 082b508 commit 2fa131a

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

CHANGELOG.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,11 @@ and this project adheres to
165165
`HumanAddr` to `String` ([#802]).
166166
- cosmwasm-std: `Api::addr_humanize` now returns `Addr` instead of `HumanAddr`
167167
([#802]).
168-
- cosmwasm-std: Hide `StakingMsg` and `CosmosMsg::Staking` behind the `staking`
169-
feature flag to make those only available in contracts built for PoS chains.
168+
- cosmwasm-std: Hide `StakingMsg`, `CosmosMsg::Staking`,
169+
`AllDelegationsResponse`, `BondedDenomResponse`, `Delegation`,
170+
`FullDelegation`, `StakingQuery`, `Validator`, `ValidatorsResponse` and
171+
`testing::StakingQuerier` behind the `staking` feature flag to make those only
172+
available in contracts built for PoS chains.
170173
- cosmwasm-std: Remove `StakingMsg::Withdraw` in favour of
171174
`DistributionMsg::SetWithdrawAddress` and
172175
`DistributionMsg::WithdrawDelegatorReward` ([#848]).

packages/std/src/lib.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ pub use crate::ibc::{
4242
pub use crate::iterator::{Order, Pair, KV};
4343
pub use crate::math::{Decimal, Fraction, Uint128};
4444
pub use crate::query::{
45-
AllBalanceResponse, AllDelegationsResponse, BalanceResponse, BankQuery, BondedDenomResponse,
46-
CustomQuery, Delegation, FullDelegation, QueryRequest, StakingQuery, Validator,
47-
ValidatorsResponse, WasmQuery,
45+
AllBalanceResponse, BalanceResponse, BankQuery, CustomQuery, QueryRequest, WasmQuery,
46+
};
47+
#[cfg(feature = "staking")]
48+
pub use crate::query::{
49+
AllDelegationsResponse, BondedDenomResponse, Delegation, FullDelegation, StakingQuery,
50+
Validator, ValidatorsResponse,
4851
};
4952
pub use crate::results::{
5053
attr, wasm_execute, wasm_instantiate, Attribute, BankMsg, ContractResult, CosmosMsg, Empty,
@@ -88,10 +91,12 @@ pub use crate::ibc_exports::{
8891
mod mock;
8992
#[cfg(not(target_arch = "wasm32"))]
9093
pub mod testing {
94+
#[cfg(feature = "staking")]
95+
pub use crate::mock::StakingQuerier;
9196
pub use crate::mock::{
9297
digit_sum, mock_dependencies, mock_dependencies_with_balances, mock_env, mock_info,
9398
riffle_shuffle, BankQuerier, MockApi, MockQuerier, MockQuerierCustomHandlerResult,
94-
MockStorage, StakingQuerier, MOCK_CONTRACT_ADDR,
99+
MockStorage, MOCK_CONTRACT_ADDR,
95100
};
96101
#[cfg(feature = "stargate")]
97102
pub use crate::mock::{mock_ibc_channel, mock_ibc_packet_ack, mock_ibc_packet_recv};

packages/std/src/mock.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ use crate::errors::{RecoverPubkeyError, StdError, StdResult, SystemError, Verifi
1111
#[cfg(feature = "stargate")]
1212
use crate::ibc::{IbcChannel, IbcEndpoint, IbcOrder, IbcPacket, IbcTimeoutBlock};
1313
use crate::query::{
14-
AllBalanceResponse, AllDelegationsResponse, BalanceResponse, BankQuery, BondedDenomResponse,
15-
CustomQuery, DelegationResponse, FullDelegation, QueryRequest, StakingQuery, Validator,
16-
ValidatorsResponse, WasmQuery,
14+
AllBalanceResponse, BalanceResponse, BankQuery, CustomQuery, QueryRequest, WasmQuery,
15+
};
16+
#[cfg(feature = "staking")]
17+
use crate::query::{
18+
AllDelegationsResponse, BondedDenomResponse, DelegationResponse, FullDelegation, StakingQuery,
19+
Validator, ValidatorsResponse,
1720
};
1821
use crate::results::{ContractResult, Empty, SystemResult};
1922
use crate::serde::{from_slice, to_binary};
@@ -280,6 +283,7 @@ pub type MockQuerierCustomHandlerResult = SystemResult<ContractResult<Binary>>;
280283
/// TODO: also allow querying contracts
281284
pub struct MockQuerier<C: DeserializeOwned = Empty> {
282285
bank: BankQuerier,
286+
#[cfg(feature = "staking")]
283287
staking: StakingQuerier,
284288
// placeholder to add support later
285289
wasm: NoWasmQuerier,
@@ -294,6 +298,7 @@ impl<C: DeserializeOwned> MockQuerier<C> {
294298
pub fn new(balances: &[(&str, &[Coin])]) -> Self {
295299
MockQuerier {
296300
bank: BankQuerier::new(balances),
301+
#[cfg(feature = "staking")]
297302
staking: StakingQuerier::default(),
298303
wasm: NoWasmQuerier {},
299304
// strange argument notation suggested as a workaround here: https://github.com/rust-lang/rust/issues/41078#issuecomment-294296365
@@ -353,6 +358,7 @@ impl<C: CustomQuery + DeserializeOwned> MockQuerier<C> {
353358
match &request {
354359
QueryRequest::Bank(bank_query) => self.bank.query(bank_query),
355360
QueryRequest::Custom(custom_query) => (*self.custom_handler)(custom_query),
361+
#[cfg(feature = "staking")]
356362
QueryRequest::Staking(staking_query) => self.staking.query(staking_query),
357363
QueryRequest::Wasm(msg) => self.wasm.query(msg),
358364
#[cfg(feature = "stargate")]
@@ -427,13 +433,15 @@ impl BankQuerier {
427433
}
428434
}
429435

436+
#[cfg(feature = "staking")]
430437
#[derive(Clone, Default)]
431438
pub struct StakingQuerier {
432439
denom: String,
433440
validators: Vec<Validator>,
434441
delegations: Vec<FullDelegation>,
435442
}
436443

444+
#[cfg(feature = "staking")]
437445
impl StakingQuerier {
438446
pub fn new(denom: &str, validators: &[Validator], delegations: &[FullDelegation]) -> Self {
439447
StakingQuerier {
@@ -513,8 +521,9 @@ pub fn digit_sum(input: &[u8]) -> usize {
513521
#[cfg(test)]
514522
mod tests {
515523
use super::*;
516-
use crate::query::Delegation;
517-
use crate::{coin, coins, from_binary, Decimal};
524+
use crate::{coin, coins, from_binary};
525+
#[cfg(feature = "staking")]
526+
use crate::{Decimal, Delegation};
518527
use hex_literal::hex;
519528

520529
const SECP256K1_MSG_HASH_HEX: &str =
@@ -863,6 +872,7 @@ mod tests {
863872
assert_eq!(res.amount, coin(0, "ELF"));
864873
}
865874

875+
#[cfg(feature = "staking")]
866876
#[test]
867877
fn staking_querier_validators() {
868878
let val1 = Validator {
@@ -889,6 +899,7 @@ mod tests {
889899
assert_eq!(vals.validators, vec![val1, val2]);
890900
}
891901

902+
#[cfg(feature = "staking")]
892903
// gets delegators from query or panic
893904
fn get_all_delegators<U: Into<String>>(
894905
staking: &StakingQuerier,
@@ -904,6 +915,7 @@ mod tests {
904915
dels.delegations
905916
}
906917

918+
#[cfg(feature = "staking")]
907919
// gets full delegators from query or panic
908920
fn get_delegator<U: Into<String>, V: Into<String>>(
909921
staking: &StakingQuerier,
@@ -921,6 +933,7 @@ mod tests {
921933
dels.delegation
922934
}
923935

936+
#[cfg(feature = "staking")]
924937
#[test]
925938
fn staking_querier_delegations() {
926939
let val1 = String::from("validator-one");

packages/std/src/query/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mod stargate;
1313
mod wasm;
1414

1515
pub use bank::{AllBalanceResponse, BalanceResponse, BankQuery};
16+
#[cfg(feature = "staking")]
1617
pub use staking::{
1718
AllDelegationsResponse, BondedDenomResponse, Delegation, DelegationResponse, FullDelegation,
1819
StakingQuery, Validator, ValidatorsResponse,
@@ -27,6 +28,7 @@ pub use wasm::WasmQuery;
2728
pub enum QueryRequest<C: CustomQuery> {
2829
Bank(BankQuery),
2930
Custom(C),
31+
#[cfg(feature = "staking")]
3032
Staking(StakingQuery),
3133
/// A Stargate query encoded the same way as abci_query, with path and protobuf encoded Data.
3234
/// The format is defined in [ADR-21](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-021-protobuf-query-encoding.md)

packages/std/src/query/staking.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(feature = "staking")]
2+
13
use schemars::JsonSchema;
24
use serde::{Deserialize, Serialize};
35

0 commit comments

Comments
 (0)