cosmwasm_std/
lib.rs

1#[cfg(not(feature = "std"))]
2core::compile_error!(
3    r#"Please enable `cosmwasm-std`'s `std` feature, as we might move existing functionality to that feature in the future.
4Builds without the std feature are currently not expected to work. If you need no_std support see #1484.
5"#
6);
7
8#[macro_use]
9extern crate alloc;
10
11// Exposed on all platforms
12
13mod __internal;
14mod addresses;
15mod assertions;
16mod binary;
17mod checksum;
18mod coin;
19mod coins;
20mod conversion;
21mod deps;
22mod encoding;
23mod errors;
24mod forward_ref;
25mod hex_binary;
26mod ibc;
27mod import_helpers;
28#[cfg(feature = "iterator")]
29mod iterator;
30mod math;
31mod metadata;
32mod msgpack;
33mod never;
34mod pagination;
35mod panic;
36mod query;
37mod results;
38mod sections;
39mod serde;
40mod stdack;
41mod storage;
42mod timestamp;
43mod traits;
44mod types;
45
46/// This module is to simplify no_std imports
47pub(crate) mod prelude;
48
49/// This modules is very advanced and will not be used directly by the vast majority of users.
50/// We want to offer it to ensure a stable storage key composition system but don't encourage
51/// contract devs to use it directly.
52pub mod storage_keys;
53
54pub use crate::addresses::{instantiate2_address, Addr, CanonicalAddr, Instantiate2AddressError};
55pub use crate::binary::Binary;
56pub use crate::checksum::{Checksum, ChecksumError};
57pub use crate::coin::{coin, coins, has_coins, Coin};
58pub use crate::coins::Coins;
59pub use crate::deps::{Deps, DepsMut, OwnedDeps};
60pub use crate::encoding::{from_base64, from_hex, to_base64, to_hex};
61pub use crate::errors::{
62    AggregationError, CheckedFromRatioError, CheckedMultiplyFractionError,
63    CheckedMultiplyRatioError, CoinFromStrError, CoinsError, ConversionOverflowError,
64    DivideByZeroError, DivisionError, OverflowError, OverflowOperation, PairingEqualityError,
65    RecoverPubkeyError, RoundDownOverflowError, RoundUpOverflowError, StdError, StdResult,
66    SystemError, VerificationError,
67};
68pub use crate::hex_binary::HexBinary;
69pub use crate::ibc::IbcChannelOpenResponse;
70pub use crate::ibc::{
71    Ibc3ChannelOpenResponse, IbcAckCallbackMsg, IbcAcknowledgement, IbcBasicResponse,
72    IbcCallbackRequest, IbcChannel, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg,
73    IbcDestinationCallbackMsg, IbcDstCallback, IbcEndpoint, IbcFee, IbcMsg, IbcOrder, IbcPacket,
74    IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse,
75    IbcSourceCallbackMsg, IbcSrcCallback, IbcTimeout, IbcTimeoutBlock, IbcTimeoutCallbackMsg,
76    TransferMsgBuilder,
77};
78#[cfg(feature = "iterator")]
79pub use crate::iterator::{Order, Record};
80pub use crate::math::{
81    Decimal, Decimal256, Decimal256RangeExceeded, DecimalRangeExceeded, Fraction, Int128, Int256,
82    Int512, Int64, Isqrt, SignedDecimal, SignedDecimal256, SignedDecimal256RangeExceeded,
83    SignedDecimalRangeExceeded, Uint128, Uint256, Uint512, Uint64,
84};
85pub use crate::metadata::{DenomMetadata, DenomUnit};
86pub use crate::msgpack::{from_msgpack, to_msgpack_binary, to_msgpack_vec};
87pub use crate::never::Never;
88pub use crate::pagination::PageRequest;
89pub use crate::query::{
90    AllBalanceResponse, AllDelegationsResponse, AllDenomMetadataResponse, AllValidatorsResponse,
91    BalanceResponse, BankQuery, BondedDenomResponse, ChannelResponse, CodeInfoResponse,
92    ContractInfoResponse, CustomQuery, DecCoin, Delegation, DelegationResponse,
93    DelegationRewardsResponse, DelegationTotalRewardsResponse, DelegatorReward,
94    DelegatorValidatorsResponse, DelegatorWithdrawAddressResponse, DenomMetadataResponse,
95    DistributionQuery, FeeEnabledChannelResponse, FullDelegation, GrpcQuery, IbcQuery,
96    ListChannelsResponse, PortIdResponse, QueryRequest, StakingQuery, SupplyResponse, Validator,
97    ValidatorResponse, WasmQuery,
98};
99#[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))]
100pub use crate::results::WeightedVoteOption;
101pub use crate::results::{
102    attr, wasm_execute, wasm_instantiate, AnyMsg, Attribute, BankMsg, ContractResult, CosmosMsg,
103    CustomMsg, Empty, Event, MsgResponse, QueryResponse, Reply, ReplyOn, Response, SubMsg,
104    SubMsgResponse, SubMsgResult, SystemResult, WasmMsg,
105};
106#[cfg(feature = "staking")]
107pub use crate::results::{DistributionMsg, StakingMsg};
108#[cfg(feature = "stargate")]
109pub use crate::results::{GovMsg, VoteOption};
110#[allow(deprecated)]
111pub use crate::serde::{
112    from_binary, from_json, from_slice, to_binary, to_json_binary, to_json_string, to_json_vec,
113    to_vec,
114};
115pub use crate::stdack::StdAck;
116pub use crate::storage::MemoryStorage;
117pub use crate::timestamp::Timestamp;
118pub use crate::traits::{Api, HashFunction, Querier, QuerierResult, QuerierWrapper, Storage};
119pub use crate::types::{BlockInfo, ContractInfo, Env, MessageInfo, MigrateInfo, TransactionInfo};
120
121#[cfg(feature = "abort")]
122mod _warning {
123    #[must_use = "cosmwasm-std feature `abort` is deprecated and will be removed in the next major release. You can just remove the feature as this functionality is now the default"]
124    struct CompileWarning;
125
126    #[allow(dead_code)]
127    fn trigger_warning() {
128        CompileWarning;
129    }
130}
131
132// Exposed in wasm build only
133#[cfg(target_arch = "wasm32")]
134mod exports;
135#[cfg(target_arch = "wasm32")]
136mod imports;
137#[cfg(target_arch = "wasm32")]
138mod memory; // Used by exports and imports only. This assumes pointers are 32 bit long, which makes it untestable on dev machines.
139
140#[cfg(all(feature = "cosmwasm_2_2", target_arch = "wasm32"))]
141pub use crate::exports::do_migrate_with_info;
142#[cfg(target_arch = "wasm32")]
143pub use crate::exports::{
144    do_execute, do_ibc_destination_callback, do_ibc_source_callback, do_instantiate, do_migrate,
145    do_query, do_reply, do_sudo,
146};
147#[cfg(all(feature = "stargate", target_arch = "wasm32"))]
148pub use crate::exports::{
149    do_ibc_channel_close, do_ibc_channel_connect, do_ibc_channel_open, do_ibc_packet_ack,
150    do_ibc_packet_receive, do_ibc_packet_timeout,
151};
152#[cfg(target_arch = "wasm32")]
153pub use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage};
154
155/// Exposed for testing only
156/// Both unit tests and integration tests are compiled to native code, so everything in here does not need to compile to Wasm.
157#[cfg(not(target_arch = "wasm32"))]
158pub mod testing;
159
160pub use cosmwasm_core::{BLS12_381_G1_GENERATOR, BLS12_381_G2_GENERATOR};
161
162/// This attribute macro generates the boilerplate required to call into the
163/// contract-specific logic from the entry-points to the Wasm module.
164///
165/// It should be added to the contract's init, handle, migrate and query implementations
166/// like this:
167/// ```
168/// # use cosmwasm_std::{
169/// #     Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo,
170/// #     Response, QueryResponse,
171/// # };
172/// #
173/// # type InstantiateMsg = ();
174/// # type ExecuteMsg = ();
175/// # type QueryMsg = ();
176///
177/// #[entry_point]
178/// pub fn instantiate(
179///     deps: DepsMut,
180///     env: Env,
181///     info: MessageInfo,
182///     msg: InstantiateMsg,
183/// ) -> Result<Response, StdError> {
184/// #   Ok(Default::default())
185/// }
186///
187/// #[entry_point]
188/// pub fn execute(
189///     deps: DepsMut,
190///     env: Env,
191///     info: MessageInfo,
192///     msg: ExecuteMsg,
193/// ) -> Result<Response, StdError> {
194/// #   Ok(Default::default())
195/// }
196///
197/// #[entry_point]
198/// pub fn query(
199///     deps: Deps,
200///     env: Env,
201///     msg: QueryMsg,
202/// ) -> Result<QueryResponse, StdError> {
203/// #   Ok(Default::default())
204/// }
205/// ```
206///
207/// where `InstantiateMsg`, `ExecuteMsg`, and `QueryMsg` are contract defined
208/// types that implement `DeserializeOwned + JsonSchema`.
209///
210/// ## Set the version of the state of your contract
211///
212/// The VM will use this as a hint whether it needs to run the migrate function of your contract or not.
213///
214/// ```
215/// # use cosmwasm_std::{
216/// #     DepsMut, entry_point, Env, MigrateInfo,
217/// #     Response, StdResult,
218/// # };
219/// #
220/// # type MigrateMsg = ();
221/// #[entry_point]
222/// #[migrate_version(2)]
223/// pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg, migrate_info: MigrateInfo) -> StdResult<Response> {
224///     todo!();
225/// }
226/// ```
227///
228/// It is also possible to assign the migrate version number to
229/// a given constant name:
230///
231/// ```
232/// # use cosmwasm_std::{
233/// #     DepsMut, entry_point, Env, MigrateInfo,
234/// #     Response, StdResult,
235/// # };
236/// #
237/// # type MigrateMsg = ();
238/// const CONTRACT_VERSION: u64 = 66;
239///
240/// #[entry_point]
241/// #[migrate_version(CONTRACT_VERSION)]
242/// pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg, migrate_info: MigrateInfo) -> StdResult<Response> {
243///     todo!();
244/// }
245/// ```
246pub use cosmwasm_derive::entry_point;