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 module 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;
70#[allow(deprecated)]
71pub use crate::ibc::IbcFee;
72pub use crate::ibc::{
73    Ibc3ChannelOpenResponse, IbcAckCallbackMsg, IbcAcknowledgement, IbcBasicResponse,
74    IbcCallbackRequest, IbcChannel, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg,
75    IbcDestinationCallbackMsg, IbcDstCallback, IbcEndpoint, IbcMsg, IbcOrder, IbcPacket,
76    IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse,
77    IbcSourceCallbackMsg, IbcSrcCallback, IbcTimeout, IbcTimeoutBlock, IbcTimeoutCallbackMsg,
78    TransferMsgBuilder,
79};
80#[cfg(feature = "iterator")]
81pub use crate::iterator::{Order, Record};
82pub use crate::math::{
83    Decimal, Decimal256, Decimal256RangeExceeded, DecimalRangeExceeded, Fraction, Int128, Int256,
84    Int512, Int64, Isqrt, SignedDecimal, SignedDecimal256, SignedDecimal256RangeExceeded,
85    SignedDecimalRangeExceeded, Uint128, Uint256, Uint512, Uint64,
86};
87pub use crate::metadata::{DenomMetadata, DenomUnit};
88pub use crate::msgpack::{from_msgpack, to_msgpack_binary, to_msgpack_vec};
89pub use crate::never::Never;
90pub use crate::pagination::PageRequest;
91#[allow(deprecated)]
92pub use crate::query::FeeEnabledChannelResponse;
93pub use crate::query::{
94    AllBalanceResponse, AllDelegationsResponse, AllDenomMetadataResponse, AllValidatorsResponse,
95    BalanceResponse, BankQuery, BondedDenomResponse, ChannelResponse, CodeInfoResponse,
96    ContractInfoResponse, CustomQuery, DecCoin, Delegation, DelegationResponse,
97    DelegationRewardsResponse, DelegationTotalRewardsResponse, DelegatorReward,
98    DelegatorValidatorsResponse, DelegatorWithdrawAddressResponse, DenomMetadataResponse,
99    DistributionQuery, FullDelegation, GrpcQuery, IbcQuery, ListChannelsResponse, PortIdResponse,
100    QueryRequest, StakingQuery, SupplyResponse, Validator, ValidatorResponse, WasmQuery,
101};
102#[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))]
103pub use crate::results::WeightedVoteOption;
104pub use crate::results::{
105    attr, wasm_execute, wasm_instantiate, AnyMsg, Attribute, BankMsg, ContractResult, CosmosMsg,
106    CustomMsg, Empty, Event, MsgResponse, QueryResponse, Reply, ReplyOn, Response, SubMsg,
107    SubMsgResponse, SubMsgResult, SystemResult, WasmMsg,
108};
109#[cfg(feature = "staking")]
110pub use crate::results::{DistributionMsg, StakingMsg};
111#[cfg(feature = "stargate")]
112pub use crate::results::{GovMsg, VoteOption};
113#[allow(deprecated)]
114pub use crate::serde::{
115    from_binary, from_json, from_slice, to_binary, to_json_binary, to_json_string, to_json_vec,
116    to_vec,
117};
118pub use crate::stdack::StdAck;
119pub use crate::storage::MemoryStorage;
120pub use crate::timestamp::Timestamp;
121pub use crate::traits::{Api, HashFunction, Querier, QuerierResult, QuerierWrapper, Storage};
122pub use crate::types::{BlockInfo, ContractInfo, Env, MessageInfo, MigrateInfo, TransactionInfo};
123
124#[cfg(feature = "abort")]
125mod _warning {
126    #[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"]
127    struct CompileWarning;
128
129    #[allow(dead_code)]
130    fn trigger_warning() {
131        let _ = CompileWarning;
132    }
133}
134
135// Exposed in wasm build only
136#[cfg(target_arch = "wasm32")]
137mod exports;
138#[cfg(target_arch = "wasm32")]
139mod imports;
140#[cfg(target_arch = "wasm32")]
141mod memory; // Used by exports and imports only. This assumes pointers are 32 bit long, which makes it untestable on dev machines.
142
143#[cfg(all(feature = "cosmwasm_2_2", target_arch = "wasm32"))]
144pub use crate::exports::do_migrate_with_info;
145#[cfg(target_arch = "wasm32")]
146pub use crate::exports::{
147    do_execute, do_ibc_destination_callback, do_ibc_source_callback, do_instantiate, do_migrate,
148    do_query, do_reply, do_sudo,
149};
150#[cfg(all(feature = "stargate", target_arch = "wasm32"))]
151pub use crate::exports::{
152    do_ibc_channel_close, do_ibc_channel_connect, do_ibc_channel_open, do_ibc_packet_ack,
153    do_ibc_packet_receive, do_ibc_packet_timeout,
154};
155#[cfg(target_arch = "wasm32")]
156pub use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage};
157
158/// Exposed for testing only
159/// Both unit tests and integration tests are compiled to native code, so everything in here does not need to compile to Wasm.
160#[cfg(not(target_arch = "wasm32"))]
161pub mod testing;
162
163pub use cosmwasm_core::{BLS12_381_G1_GENERATOR, BLS12_381_G2_GENERATOR};
164
165/// This attribute macro generates the boilerplate required to call into the
166/// contract-specific logic from the entry-points to the Wasm module.
167///
168/// It should be added to the contract's init, handle, migrate and query implementations
169/// like this:
170/// ```
171/// # use cosmwasm_std::{
172/// #     Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo,
173/// #     Response, QueryResponse,
174/// # };
175/// #
176/// # type InstantiateMsg = ();
177/// # type ExecuteMsg = ();
178/// # type QueryMsg = ();
179///
180/// #[entry_point]
181/// pub fn instantiate(
182///     deps: DepsMut,
183///     env: Env,
184///     info: MessageInfo,
185///     msg: InstantiateMsg,
186/// ) -> Result<Response, StdError> {
187/// #   Ok(Default::default())
188/// }
189///
190/// #[entry_point]
191/// pub fn execute(
192///     deps: DepsMut,
193///     env: Env,
194///     info: MessageInfo,
195///     msg: ExecuteMsg,
196/// ) -> Result<Response, StdError> {
197/// #   Ok(Default::default())
198/// }
199///
200/// #[entry_point]
201/// pub fn query(
202///     deps: Deps,
203///     env: Env,
204///     msg: QueryMsg,
205/// ) -> Result<QueryResponse, StdError> {
206/// #   Ok(Default::default())
207/// }
208/// ```
209///
210/// where `InstantiateMsg`, `ExecuteMsg`, and `QueryMsg` are contract defined
211/// types that implement `DeserializeOwned + JsonSchema`.
212///
213/// ## Set the version of the state of your contract
214///
215/// The VM will use this as a hint whether it needs to run the migrate function of your contract or not.
216///
217/// ```
218/// # use cosmwasm_std::{
219/// #     DepsMut, entry_point, Env, MigrateInfo,
220/// #     Response, StdResult,
221/// # };
222/// #
223/// # type MigrateMsg = ();
224/// #[entry_point]
225/// #[migrate_version(2)]
226/// pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg, migrate_info: MigrateInfo) -> StdResult<Response> {
227///     todo!();
228/// }
229/// ```
230///
231/// It is also possible to assign the migrate version number to
232/// a given constant name:
233///
234/// ```
235/// # use cosmwasm_std::{
236/// #     DepsMut, entry_point, Env, MigrateInfo,
237/// #     Response, StdResult,
238/// # };
239/// #
240/// # type MigrateMsg = ();
241/// const CONTRACT_VERSION: u64 = 66;
242///
243/// #[entry_point]
244/// #[migrate_version(CONTRACT_VERSION)]
245/// pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg, migrate_info: MigrateInfo) -> StdResult<Response> {
246///     todo!();
247/// }
248/// ```
249pub use cosmwasm_derive::entry_point;