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 ibc2;
28mod import_helpers;
29#[cfg(feature = "iterator")]
30mod iterator;
31mod math;
32mod metadata;
33mod msgpack;
34mod never;
35mod pagination;
36mod query;
37mod results;
38mod sections;
39mod serde;
40mod stdack;
41mod timestamp;
42mod traits;
43mod types;
44mod utils;
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::{
55    instantiate2_address, instantiate2_address_impl, Addr, CanonicalAddr, Instantiate2AddressError,
56};
57pub use crate::binary::Binary;
58pub use crate::checksum::{Checksum, ChecksumError};
59pub use crate::coin::{coin, coins, has_coins, Coin};
60pub use crate::coins::Coins;
61pub use crate::deps::{Deps, DepsMut, OwnedDeps};
62pub use crate::encoding::{from_base64, from_hex, to_base64, to_hex};
63pub use crate::errors::{
64    AggregationError, CheckedFromRatioError, CheckedMultiplyFractionError,
65    CheckedMultiplyRatioError, CoinFromStrError, CoinsError, ConversionOverflowError,
66    DivideByZeroError, DivisionError, ErrorKind as StdErrorKind, OverflowError, OverflowOperation,
67    PairingEqualityError, RecoverPubkeyError, RoundDownOverflowError, RoundUpOverflowError,
68    StdError, StdResult, StdResultExt, SystemError, VerificationError,
69};
70pub use crate::hex_binary::HexBinary;
71pub use crate::ibc::IbcChannelOpenResponse;
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    IbcTransferCallback, TransferMsgBuilder,
79};
80pub use crate::ibc2::{
81    Ibc2Msg, Ibc2PacketAckMsg, Ibc2PacketReceiveMsg, Ibc2PacketSendMsg, Ibc2PacketTimeoutMsg,
82    Ibc2Payload,
83};
84#[cfg(feature = "iterator")]
85pub use crate::iterator::{Order, Record};
86pub use crate::math::{
87    Decimal, Decimal256, Decimal256RangeExceeded, DecimalRangeExceeded, Fraction, Int128, Int256,
88    Int512, Int64, Isqrt, SignedDecimal, SignedDecimal256, SignedDecimal256RangeExceeded,
89    SignedDecimalRangeExceeded, Uint128, Uint256, Uint512, Uint64,
90};
91pub use crate::metadata::{DenomMetadata, DenomUnit};
92pub use crate::msgpack::{from_msgpack, to_msgpack_binary, to_msgpack_vec};
93pub use crate::never::Never;
94pub use crate::pagination::PageRequest;
95pub use crate::query::{
96    AllDelegationsResponse, AllDenomMetadataResponse, AllValidatorsResponse, BalanceResponse,
97    BankQuery, BondedDenomResponse, ChannelResponse, CodeInfoResponse, ContractInfoResponse,
98    CustomQuery, DecCoin, Delegation, DelegationResponse, DelegationRewardsResponse,
99    DelegationTotalRewardsResponse, DelegatorReward, DelegatorValidatorsResponse,
100    DelegatorWithdrawAddressResponse, DenomMetadataResponse, DistributionQuery, FullDelegation,
101    GrpcQuery, IbcQuery, PortIdResponse, QueryRequest, RawRangeEntry, RawRangeResponse,
102    StakingQuery, SupplyResponse, Validator, ValidatorResponse, WasmQuery,
103};
104
105#[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))]
106pub use crate::results::WeightedVoteOption;
107pub use crate::results::{
108    attr, wasm_execute, wasm_instantiate, AnyMsg, Attribute, BankMsg, ContractResult, CosmosMsg,
109    CustomMsg, Empty, Event, MsgResponse, QueryResponse, Reply, ReplyOn, Response, SubMsg,
110    SubMsgResponse, SubMsgResult, SystemResult, WasmMsg,
111};
112#[cfg(feature = "staking")]
113pub use crate::results::{DistributionMsg, StakingMsg};
114#[cfg(feature = "stargate")]
115pub use crate::results::{GovMsg, VoteOption};
116pub use crate::serde::{from_json, to_json_binary, to_json_string, to_json_vec};
117pub use crate::stdack::StdAck;
118pub use crate::timestamp::Timestamp;
119pub use crate::traits::{Api, HashFunction, Querier, QuerierResult, QuerierWrapper, Storage};
120pub use crate::types::{BlockInfo, ContractInfo, Env, MessageInfo, MigrateInfo, TransactionInfo};
121
122//
123// Exports
124//
125
126#[cfg(all(feature = "exports", target_arch = "wasm32"))]
127mod exports;
128
129#[cfg(all(feature = "exports", target_arch = "wasm32", feature = "cosmwasm_2_2"))]
130pub use crate::exports::do_migrate_with_info;
131#[cfg(all(feature = "exports", target_arch = "wasm32"))]
132pub use crate::exports::{
133    do_execute, do_ibc_destination_callback, do_ibc_source_callback, do_instantiate, do_migrate,
134    do_query, do_reply, do_sudo,
135};
136#[cfg(all(feature = "exports", target_arch = "wasm32", feature = "ibc2"))]
137pub use crate::exports::{
138    do_ibc2_packet_ack, do_ibc2_packet_receive, do_ibc2_packet_send, do_ibc2_packet_timeout,
139};
140#[cfg(all(feature = "exports", target_arch = "wasm32", feature = "stargate"))]
141pub use crate::exports::{
142    do_ibc_channel_close, do_ibc_channel_connect, do_ibc_channel_open, do_ibc_packet_ack,
143    do_ibc_packet_receive, do_ibc_packet_timeout,
144};
145
146/// Exposed for testing only
147/// Both unit tests and integration tests are compiled to native code, so everything in here does not need to compile to Wasm.
148#[cfg(not(target_arch = "wasm32"))]
149pub mod testing;
150
151pub use cosmwasm_core::{BLS12_381_G1_GENERATOR, BLS12_381_G2_GENERATOR};
152
153/// This attribute macro generates the boilerplate required to call into the
154/// contract-specific logic from the entry-points to the Wasm module.
155///
156/// It should be added to the contract's init, handle, migrate and query implementations
157/// like this:
158/// ```
159/// # use cosmwasm_std::{
160/// #     Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo,
161/// #     Response, QueryResponse,
162/// # };
163/// #
164/// # type InstantiateMsg = ();
165/// # type ExecuteMsg = ();
166/// # type QueryMsg = ();
167///
168/// #[entry_point]
169/// pub fn instantiate(
170///     deps: DepsMut,
171///     env: Env,
172///     info: MessageInfo,
173///     msg: InstantiateMsg,
174/// ) -> Result<Response, StdError> {
175/// #   Ok(Default::default())
176/// }
177///
178/// #[entry_point]
179/// pub fn execute(
180///     deps: DepsMut,
181///     env: Env,
182///     info: MessageInfo,
183///     msg: ExecuteMsg,
184/// ) -> Result<Response, StdError> {
185/// #   Ok(Default::default())
186/// }
187///
188/// #[entry_point]
189/// pub fn query(
190///     deps: Deps,
191///     env: Env,
192///     msg: QueryMsg,
193/// ) -> Result<QueryResponse, StdError> {
194/// #   Ok(Default::default())
195/// }
196/// ```
197///
198/// where `InstantiateMsg`, `ExecuteMsg`, and `QueryMsg` are contract defined
199/// types that implement `DeserializeOwned`.
200///
201/// ## Set the version of the state of your contract
202///
203/// The VM will use this as a hint whether it needs to run the migrate function of your contract or not.
204///
205/// ```
206/// # use cosmwasm_std::{
207/// #     DepsMut, entry_point, Env, MigrateInfo,
208/// #     Response, StdResult,
209/// # };
210/// #
211/// # type MigrateMsg = ();
212/// #[entry_point]
213/// #[migrate_version(2)]
214/// pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg, migrate_info: MigrateInfo) -> StdResult<Response> {
215///     todo!();
216/// }
217/// ```
218///
219/// It is also possible to assign the migrate version number to
220/// a given constant name:
221///
222/// ```
223/// # use cosmwasm_std::{
224/// #     DepsMut, entry_point, Env, MigrateInfo,
225/// #     Response, StdResult,
226/// # };
227/// #
228/// # type MigrateMsg = ();
229/// const CONTRACT_VERSION: u64 = 66;
230///
231/// #[entry_point]
232/// #[migrate_version(CONTRACT_VERSION)]
233/// pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg, migrate_info: MigrateInfo) -> StdResult<Response> {
234///     todo!();
235/// }
236/// ```
237pub use cosmwasm_derive::entry_point;