Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add constructor functions for use by cw-sdk #1558

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions packages/std/src/query/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
20 changes: 20 additions & 0 deletions packages/std/src/query/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> Self {
Self {
Expand All @@ -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<String>,
admin: Option<impl Into<String>>,
pinned: bool,
ibc_port: Option<String>,
) -> Self {
Self {
code_id,
creator: creator.into(),
admin: admin.map(|addr| addr.into()),
pinned,
ibc_port,
}
}
}