Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ and this project adheres to
- cosmwasm-std: Remove export of `ExternalApi`, `ExternalQuerier` and
`ExternalStorage` as those are only needed by export implementations in
cosmwasm-std. ([#2467])
- cosmwasm-std: Add a new `exports` feature which needs to be enabled for the
primary cosmwasm_std dependency of a contract.

## Fixed

Expand Down
1 change: 1 addition & 0 deletions contracts/cyberpunk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ overflow-checks = true
cosmwasm-schema = { path = "../../packages/schema" }
cosmwasm-std = { path = "../../packages/std", default-features = false, features = [
"cosmwasm_1_3",
"exports",
"std",
] }
rust-argon2 = "2.1"
Expand Down
1 change: 1 addition & 0 deletions contracts/hackatom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ overflow-checks = true
cosmwasm-schema = { path = "../../packages/schema" }
cosmwasm-std = { path = "../../packages/std", default-features = false, features = [
"cosmwasm_2_2",
"exports",
"std",
] }
schemars = "0.8.12"
Expand Down
1 change: 1 addition & 0 deletions contracts/reflect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ overflow-checks = true
cosmwasm-schema = { path = "../../packages/schema" }
cosmwasm-std = { path = "../../packages/std", default-features = false, features = [
"cosmwasm_2_2",
"exports",
"staking",
"stargate",
"std",
Expand Down
1 change: 1 addition & 0 deletions contracts/replier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ overflow-checks = true
cosmwasm-schema = { path = "../../packages/schema" }
cosmwasm-std = { path = "../../packages/std", default-features = false, features = [
"cosmwasm_1_4",
"exports",
"iterator",
"std",
] }
Expand Down
1 change: 1 addition & 0 deletions contracts/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ overflow-checks = true
[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
cosmwasm-std = { path = "../../packages/std", default-features = false, features = [
"exports",
"staking",
"std",
] }
Expand Down
28 changes: 14 additions & 14 deletions docs/USING_COSMWASM_STD.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ in the dependency tree. Otherwise conflicting C exports are created.

The library comes with the following features:

| Feature | Enabled by default | Description |
| ------------ | ------------------ | ------------------------------------------------------------------------------------ |
| iterator | x | Storage iterators |
| abort | x | DEPRECATED A panic handler that aborts the contract execution with a helpful message |
| stargate | | Cosmos SDK 0.40+ features and IBC |
| staking | | Access to the staking module |
| cosmwasm_1_1 | | Features that require CosmWasm 1.1+ on the chain |
| cosmwasm_1_2 | | Features that require CosmWasm 1.2+ on the chain |
| cosmwasm_1_3 | | Features that require CosmWasm 1.3+ on the chain |
| cosmwasm_1_4 | | Features that require CosmWasm 1.4+ on the chain |
| Feature | Enabled by default | Description |
| ------------ | ------------------ | -------------------------------------------------------------------------------- |
| exports | x | Adds exports and imports needed for basic communication between contract and VM. |
| iterator | x | Storage iterators |
| stargate | | Cosmos SDK 0.40+ features and IBC |
| staking | | Access to the staking module |
| cosmwasm_1_1 | | Features that require CosmWasm 1.1+ on the chain |
| cosmwasm_1_2 | | Features that require CosmWasm 1.2+ on the chain |
| cosmwasm_1_3 | | Features that require CosmWasm 1.3+ on the chain |
| cosmwasm_1_4 | | Features that require CosmWasm 1.4+ on the chain |

## The cosmwasm-std dependency for contract developers

Expand Down Expand Up @@ -78,13 +78,13 @@ might move certain existing functionality to that feature in the future.

Also libraries should define a loose version range that allows the contract
developer to control which cosmwasm-std version they want to use in the final
project. E.g. if your library does not work with 1.0.0 due to a bug fixed in
1.0.1, your min version is 1.0.1 and not the latest stable.
project. E.g. if your library does not work with 3.0.0 due to a bug fixed in
3.0.1, your min version is 3.0.1 and not the latest stable.

A typical dependency then looks like this:

```toml
# We really need `stargate` here as this is an IBC related library. `abort` and `iterator` are not needed.
# We really need `stargate` here as this is an IBC related library. `exports` and `iterator` are not needed.
# `std` should always stay enabled.
cosmwasm-std = { version = "1.0.1", default-features = false, features = ["std", "stargate"] }
cosmwasm-std = { version = "3.0.1", default-features = false, features = ["std", "stargate"] }
```
5 changes: 4 additions & 1 deletion packages/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ readme = "README.md"
features = ["cosmwasm_2_2", "staking", "stargate", "ibc2"]

[features]
default = ["iterator", "std"]
default = ["exports", "iterator", "std"]
# Enable if this cosmwasm-std is the primary version of cosmwas-std used in the contract. This
# adds exports and imports needed for basic communication between contract and VM.
exports = []
std = []
# iterator allows us to iterate over all DB items in a given range
# optional as some merkle stores (like tries) don't support this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use core::{marker::PhantomData, ptr};

use serde::de::DeserializeOwned;

use super::imports::{ExternalApi, ExternalQuerier, ExternalStorage};
use super::memory::{Owned, Region};
use super::panic::install_panic_handler;
use crate::deps::OwnedDeps;
#[cfg(any(feature = "stargate", feature = "ibc2"))]
use crate::ibc::IbcReceiveResponse;
Expand All @@ -24,9 +27,6 @@ use crate::ibc::{
use crate::ibc::{IbcChannelOpenMsg, IbcChannelOpenResponse};
#[cfg(feature = "ibc2")]
use crate::ibc2::{Ibc2PacketReceiveMsg, Ibc2PacketTimeoutMsg};
use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage};
use crate::memory::{Owned, Region};
use crate::panic::install_panic_handler;
use crate::query::CustomQuery;
use crate::results::{ContractResult, QueryResponse, Reply, Response};
use crate::serde::{from_json, to_json_vec};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
use alloc::vec::Vec;
use core::ptr;

#[cfg(feature = "iterator")]
use super::memory::get_optional_region_address;
use super::memory::{Owned, Region};
use crate::import_helpers::{from_high_half, from_low_half};
use crate::memory::{Owned, Region};
#[cfg(feature = "iterator")]
use crate::iterator::{Order, Record};
use crate::results::SystemResult;
#[cfg(feature = "iterator")]
use crate::sections::decode_sections2;
use crate::sections::encode_sections;
use crate::serde::from_json;
use crate::traits::{Api, Querier, QuerierResult, Storage};
#[cfg(feature = "iterator")]
use crate::{
iterator::{Order, Record},
memory::get_optional_region_address,
};
use crate::{Addr, CanonicalAddr};
#[cfg(feature = "cosmwasm_2_1")]
use crate::{AggregationError, HashFunction, PairingEqualityError};
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions packages/std/src/exports/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
mod exports;
mod imports;
mod memory; // Used by exports and imports only. This assumes pointers are 32 bit long, which makes it untestable on dev machines.
mod panic;

#[cfg(feature = "cosmwasm_2_2")]
pub use exports::do_migrate_with_info;
pub use exports::{
do_execute, do_ibc_destination_callback, do_ibc_source_callback, do_instantiate, do_migrate,
do_query, do_reply, do_sudo,
};
#[cfg(feature = "ibc2")]
pub use exports::{do_ibc2_packet_receive, do_ibc2_packet_timeout};
#[cfg(feature = "stargate")]
pub use exports::{
do_ibc_channel_close, do_ibc_channel_connect, do_ibc_channel_open, do_ibc_packet_ack,
do_ibc_packet_receive, do_ibc_packet_timeout,
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
///
/// This overrides any previous panic handler. See <https://doc.rust-lang.org/std/panic/fn.set_hook.html>
/// for details.
#[cfg(target_arch = "wasm32")]
pub fn install_panic_handler() {
use super::imports::handle_panic;
std::panic::set_hook(Box::new(|info| {
Expand Down
20 changes: 9 additions & 11 deletions packages/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ mod metadata;
mod msgpack;
mod never;
mod pagination;
mod panic;
mod query;
mod results;
mod sections;
Expand Down Expand Up @@ -115,24 +114,23 @@ pub use crate::timestamp::Timestamp;
pub use crate::traits::{Api, HashFunction, Querier, QuerierResult, QuerierWrapper, Storage};
pub use crate::types::{BlockInfo, ContractInfo, Env, MessageInfo, MigrateInfo, TransactionInfo};

// Exposed in wasm build only
#[cfg(target_arch = "wasm32")]
//
// Exports
//

#[cfg(all(feature = "exports", target_arch = "wasm32"))]
mod exports;
#[cfg(target_arch = "wasm32")]
mod imports;
#[cfg(target_arch = "wasm32")]
mod memory; // Used by exports and imports only. This assumes pointers are 32 bit long, which makes it untestable on dev machines.

#[cfg(all(feature = "cosmwasm_2_2", target_arch = "wasm32"))]
#[cfg(all(feature = "exports", target_arch = "wasm32", feature = "cosmwasm_2_2"))]
pub use crate::exports::do_migrate_with_info;
#[cfg(target_arch = "wasm32")]
#[cfg(all(feature = "exports", target_arch = "wasm32"))]
pub use crate::exports::{
do_execute, do_ibc_destination_callback, do_ibc_source_callback, do_instantiate, do_migrate,
do_query, do_reply, do_sudo,
};
#[cfg(all(feature = "ibc2", target_arch = "wasm32"))]
#[cfg(all(feature = "exports", target_arch = "wasm32", feature = "ibc2"))]
pub use crate::exports::{do_ibc2_packet_receive, do_ibc2_packet_timeout};
#[cfg(all(feature = "stargate", target_arch = "wasm32"))]
#[cfg(all(feature = "exports", target_arch = "wasm32", feature = "stargate"))]
pub use crate::exports::{
do_ibc_channel_close, do_ibc_channel_connect, do_ibc_channel_open, do_ibc_packet_ack,
do_ibc_packet_receive, do_ibc_packet_timeout,
Expand Down