Skip to content

Commit a9bb725

Browse files
committed
Merge branch 'main' into aw/only-schema
2 parents f931bfb + b3e4a07 commit a9bb725

File tree

8 files changed

+58
-15
lines changed

8 files changed

+58
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ and this project adheres to
9898
compiled with Rust 1.82 or newer to be stored. ([#2473])
9999
- cosmwasm-std: Removed IBC fees ([#2479])
100100
- cosmwasm-schema: Remove unused result types from trait definition (#[2495])
101+
- cosmwasm-std: Split up `Validator` type into `Validator` and
102+
`ValidatorMetadata` to allow adding more fields to `ValidatorResponse` in the
103+
future. ([#2501])
101104

102105
## Fixed
103106

@@ -146,6 +149,7 @@ and this project adheres to
146149
[#2480]: https://github.com/CosmWasm/cosmwasm/pull/2480
147150
[#2484]: https://github.com/CosmWasm/cosmwasm/pull/2484
148151
[#2495]: https://github.com/CosmWasm/cosmwasm/pull/2495
152+
[#2501]: https://github.com/CosmWasm/cosmwasm/pull/2501
149153

150154
## [2.2.0] - 2024-12-17
151155

SECURITY.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Security Policy
22

3-
This repository is maintained by Confio as part of the CosmWasm stack. Please
4-
see https://github.com/CosmWasm/advisories/blob/main/SECURITY.md for our
5-
security policy.
3+
This repository is part of the CosmWasm stack. Please see
4+
https://github.com/CosmWasm/advisories/blob/main/SECURITY.md for its security
5+
policy.

contracts/reflect/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ And [Importing](./Importing.md) contains information about pulling in other
7272
contracts or crates that have been published.
7373

7474
Please replace this README file with information about your specific project.
75-
You can keep the `Developing.md` and `Publishing.md` files as useful referenced,
75+
You can keep the `Developing.md` and `Publishing.md` files as useful references,
7676
but please set some proper description in the README.

packages/go-gen/tests/cosmwasm_std__AllValidatorsResponse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// AllValidatorsResponse is the expected response to AllValidatorsQuery
22
type AllValidatorsResponse struct {
3-
Validators Array[Validator] `json:"validators"`
3+
Validators Array[ValidatorMetadata] `json:"validators"`
44
}
55

6-
type Validator struct {
6+
type ValidatorMetadata struct {
77
Address string `json:"address"`
88
// decimal string, eg "0.02"
99
Commission string `json:"commission"`

packages/std/src/query/staking.rs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ impl FullDelegation {
166166
)]
167167
#[non_exhaustive]
168168
pub struct AllValidatorsResponse {
169-
pub validators: Vec<Validator>,
169+
pub validators: Vec<ValidatorMetadata>,
170170
}
171171

172172
impl QueryResponseType for AllValidatorsResponse {}
173173

174-
impl_hidden_constructor!(AllValidatorsResponse, validators: Vec<Validator>);
174+
impl_hidden_constructor!(AllValidatorsResponse, validators: Vec<ValidatorMetadata>);
175175

176176
/// The data format returned from StakingRequest::Validator query
177177
#[derive(
@@ -191,7 +191,7 @@ impl_hidden_constructor!(ValidatorResponse, validator: Option<Validator>);
191191
Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, cw_schema::Schemaifier,
192192
)]
193193
#[non_exhaustive]
194-
pub struct Validator {
194+
pub struct ValidatorMetadata {
195195
/// The operator address of the validator (e.g. cosmosvaloper1...).
196196
/// See https://github.com/cosmos/cosmos-sdk/blob/v0.47.4/proto/cosmos/staking/v1beta1/staking.proto#L95-L96
197197
/// for more information.
@@ -206,13 +206,30 @@ pub struct Validator {
206206
}
207207

208208
impl_hidden_constructor!(
209-
Validator,
209+
ValidatorMetadata,
210210
address: String,
211211
commission: Decimal,
212212
max_commission: Decimal,
213213
max_change_rate: Decimal
214214
);
215215

216+
/// Instances are created in the querier.
217+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
218+
#[non_exhaustive]
219+
pub struct Validator {
220+
/// The operator address of the validator (e.g. cosmosvaloper1...).
221+
/// See https://github.com/cosmos/cosmos-sdk/blob/v0.47.4/proto/cosmos/staking/v1beta1/staking.proto#L95-L96
222+
/// for more information.
223+
///
224+
/// This uses `String` instead of `Addr` since the bech32 address prefix is different from
225+
/// the ones that regular user accounts use.
226+
pub address: String,
227+
pub commission: Decimal,
228+
pub max_commission: Decimal,
229+
/// The maximum daily increase of the commission
230+
pub max_change_rate: Decimal,
231+
}
232+
216233
impl Validator {
217234
/// Creates a new validator.
218235
///
@@ -232,3 +249,24 @@ impl Validator {
232249
}
233250
}
234251
}
252+
253+
impl_hidden_constructor!(
254+
Validator,
255+
address: String,
256+
commission: Decimal,
257+
max_commission: Decimal,
258+
max_change_rate: Decimal
259+
);
260+
261+
// Validator should contain all data that ValidatorMetadata has + maybe some additional data
262+
// that is expensive to query, so we can convert ValidatorMetadata to Validator easily.
263+
impl From<Validator> for ValidatorMetadata {
264+
fn from(validator: Validator) -> Self {
265+
ValidatorMetadata {
266+
address: validator.address,
267+
commission: validator.commission,
268+
max_commission: validator.max_commission,
269+
max_change_rate: validator.max_change_rate,
270+
}
271+
}
272+
}

packages/std/src/testing/mock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ impl StakingQuerier {
12041204
}
12051205
StakingQuery::AllValidators {} => {
12061206
let res = AllValidatorsResponse {
1207-
validators: self.validators.clone(),
1207+
validators: self.validators.iter().cloned().map(Into::into).collect(),
12081208
};
12091209
to_json_binary(&res).into()
12101210
}
@@ -2508,7 +2508,7 @@ mod tests {
25082508
.unwrap()
25092509
.unwrap();
25102510
let vals: AllValidatorsResponse = from_json(raw).unwrap();
2511-
assert_eq!(vals.validators, vec![val1, val2]);
2511+
assert_eq!(vals.validators, vec![val1.into(), val2.into()]);
25122512
}
25132513

25142514
#[cfg(feature = "staking")]

packages/std/src/traits.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use crate::query::SupplyResponse;
1414
#[cfg(feature = "staking")]
1515
use crate::query::{
1616
AllDelegationsResponse, AllValidatorsResponse, BondedDenomResponse, Delegation,
17-
DelegationResponse, FullDelegation, StakingQuery, Validator, ValidatorResponse,
17+
DelegationResponse, FullDelegation, StakingQuery, Validator, ValidatorMetadata,
18+
ValidatorResponse,
1819
};
1920
#[cfg(feature = "cosmwasm_1_3")]
2021
use crate::query::{
@@ -593,7 +594,7 @@ impl<'a, C: CustomQuery> QuerierWrapper<'a, C> {
593594
}
594595

595596
#[cfg(feature = "staking")]
596-
pub fn query_all_validators(&self) -> StdResult<Vec<Validator>> {
597+
pub fn query_all_validators(&self) -> StdResult<Vec<ValidatorMetadata>> {
597598
let request = StakingQuery::AllValidators {}.into();
598599
let res: AllValidatorsResponse = self.query(&request)?;
599600
Ok(res.validators)

packages/vm/src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ where
347347

348348
/// Pins a Module that was previously stored via [`Cache::store_code`].
349349
///
350-
/// The module is lookup first in the file system cache. If not found,
350+
/// The module is looked up first in the file system cache. If not found,
351351
/// the code is loaded from the file system, compiled, and stored into the
352352
/// pinned cache.
353353
///

0 commit comments

Comments
 (0)