diff --git a/packages/std/Cargo.toml b/packages/std/Cargo.toml index 7ea7191bed..2183d4f937 100644 --- a/packages/std/Cargo.toml +++ b/packages/std/Cargo.toml @@ -39,6 +39,11 @@ cosmwasm_1_1 = [] # This feature makes `GovMsg::VoteWeighted` available for the contract to call, but requires # the host blockchain to run CosmWasm `1.2.0` or higher. cosmwasm_1_2 = [] +# This feature adds constructor functions for several query response types. The constructor +# functions are needed because these types are marked as `#[non_exhaustive]`. +# Only available for cw-sdk chains. For wasmd chains, these responses are created by +# deserialization, so constructor functions are not necessary. +cw_sdk = [] [dependencies] base64 = "0.13.0" diff --git a/packages/std/src/query/bank.rs b/packages/std/src/query/bank.rs index e53dbcc9b0..2a36a1b1ae 100644 --- a/packages/std/src/query/bank.rs +++ b/packages/std/src/query/bank.rs @@ -37,10 +37,18 @@ impl SupplyResponse { /// This is required because query response types should be #[non_exhaustive]. /// As a contract developer you should not need this constructor since /// query responses are constructed for you via deserialization. + #[cfg(not(feature = "cw_sdk"))] #[doc(hidden)] pub fn new(amount: Coin) -> Self { Self { amount } } + + /// Constructor for use in cw-sdk. + /// This is required because query response types should be #[non_exhaustive]. + #[cfg(feature = "cw_sdk")] + pub fn new(amount: Coin) -> Self { + Self { amount } + } } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] diff --git a/packages/std/src/query/wasm.rs b/packages/std/src/query/wasm.rs index fee0334635..ae829f1891 100644 --- a/packages/std/src/query/wasm.rs +++ b/packages/std/src/query/wasm.rs @@ -45,6 +45,7 @@ impl ContractInfoResponse { /// This is required because query response types should be #[non_exhaustive]. /// As a contract developer you should not need this constructor since /// query responses are constructed for you via deserialization. + #[cfg(not(feature = "cw_sdk"))] #[doc(hidden)] pub fn new(code_id: u64, creator: impl Into) -> Self { Self { @@ -55,4 +56,23 @@ impl ContractInfoResponse { ibc_port: None, } } + + /// Constructor for use in cw-sdk. + /// This is required because query response types should be #[non_exhaustive]. + #[cfg(feature = "cw_sdk")] + pub fn new( + code_id: u64, + creator: impl Into, + admin: Option>, + pinned: bool, + ibc_port: Option, + ) -> Self { + Self { + code_id, + creator: creator.into(), + admin: admin.map(|addr| addr.into()), + pinned, + ibc_port, + } + } }