Skip to content

Commit 740439d

Browse files
BigtoCchipshort
authored andcommitted
feat(query): Introduce non-breaking changes to handle nullable data stated in #2414
1 parent 784ebdc commit 740439d

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

packages/std/src/metadata.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,25 @@ pub struct DenomUnit {
2323
pub exponent: u32,
2424
pub aliases: Vec<String>,
2525
}
26+
27+
#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)]
28+
pub struct NullableDenomMetadata {
29+
pub description: String,
30+
// https://github.com/cosmos/cosmos-sdk/blob/main/api/cosmos/bank/v1beta1/bank.pulsar.go#L4539
31+
pub denom_units: Option<Vec<NullableDenomUnit>>,
32+
pub base: String,
33+
pub display: String,
34+
pub name: String,
35+
pub symbol: String,
36+
pub uri: String,
37+
pub uri_hash: String,
38+
}
39+
40+
/// Replicates the cosmos-sdk bank module DenomUnit type
41+
#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)]
42+
pub struct NullableDenomUnit {
43+
pub denom: String,
44+
pub exponent: u32,
45+
// https://github.com/cosmos/cosmos-sdk/blob/main/api/cosmos/bank/v1beta1/bank.pulsar.go#L4478
46+
pub aliases: Option<Vec<String>>,
47+
}

packages/std/src/query/bank.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::prelude::*;
77
#[cfg(feature = "cosmwasm_1_3")]
88
use crate::PageRequest;
99
use crate::{Binary, DenomMetadata};
10-
10+
use crate::metadata::NullableDenomMetadata;
1111
use super::query_response::QueryResponseType;
1212

1313
#[non_exhaustive]
@@ -83,6 +83,14 @@ pub struct DenomMetadataResponse {
8383
pub metadata: DenomMetadata,
8484
}
8585

86+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
87+
#[serde(rename_all = "snake_case")]
88+
#[non_exhaustive]
89+
pub struct NullableDenomMetadataResponse {
90+
/// The metadata for the queried denom.
91+
pub metadata: NullableDenomMetadata,
92+
}
93+
8694
impl_response_constructor!(DenomMetadataResponse, metadata: DenomMetadata);
8795

8896
impl QueryResponseType for DenomMetadataResponse {}

packages/std/src/traits.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ use crate::prelude::*;
1111
use crate::query::CodeInfoResponse;
1212
#[cfg(feature = "cosmwasm_1_1")]
1313
use crate::query::SupplyResponse;
14-
use crate::query::{
15-
AllBalanceResponse, BalanceResponse, BankQuery, CustomQuery, QueryRequest, WasmQuery,
16-
};
14+
use crate::query::{AllBalanceResponse, BalanceResponse, BankQuery, CustomQuery, NullableDenomMetadataResponse, QueryRequest, WasmQuery};
1715
#[cfg(feature = "staking")]
1816
use crate::query::{
1917
AllDelegationsResponse, AllValidatorsResponse, BondedDenomResponse, Delegation,
@@ -31,6 +29,7 @@ use crate::{Addr, CanonicalAddr};
3129
#[cfg(feature = "cosmwasm_1_3")]
3230
use crate::{DenomMetadata, PageRequest};
3331
use crate::{RecoverPubkeyError, StdError, StdResult, VerificationError};
32+
use crate::metadata::NullableDenomMetadata;
3433

3534
#[derive(Clone, Copy, Debug)]
3635
#[non_exhaustive]
@@ -468,6 +467,16 @@ impl<'a, C: CustomQuery> QuerierWrapper<'a, C> {
468467
Ok(res.metadata)
469468
}
470469

470+
#[cfg(feature = "cosmwasm_1_3")]
471+
pub fn query_nullable_denom_metadata(&self, denom: impl Into<String>) -> StdResult<NullableDenomMetadata> {
472+
let request = BankQuery::DenomMetadata {
473+
denom: denom.into(),
474+
}
475+
.into();
476+
let res: NullableDenomMetadataResponse = self.query(&request)?;
477+
Ok(res.metadata)
478+
}
479+
471480
#[cfg(feature = "cosmwasm_1_3")]
472481
pub fn query_all_denom_metadata(
473482
&self,

0 commit comments

Comments
 (0)