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 never;
33mod pagination;
34mod panic;
35mod query;
36mod results;
37mod sections;
38mod serde;
39mod stdack;
40mod storage;
41mod timestamp;
42mod traits;
43mod types;
44
45/// This module is to simplify no_std imports
46pub(crate) mod prelude;
47
48/// This modules is very advanced and will not be used directly by the vast majority of users.
49/// We want to offer it to ensure a stable storage key composition system but don't encourage
50/// contract devs to use it directly.
51pub mod storage_keys;
52
53pub use crate::addresses::{instantiate2_address, Addr, CanonicalAddr, Instantiate2AddressError};
54pub use crate::binary::Binary;
55pub use crate::checksum::{Checksum, ChecksumError};
56pub use crate::coin::{coin, coins, has_coins, Coin};
57pub use crate::coins::Coins;
58pub use crate::deps::{Deps, DepsMut, OwnedDeps};
59pub use crate::encoding::{from_base64, from_hex, to_base64, to_hex};
60pub use crate::errors::{
61    AggregationError, CheckedFromRatioError, CheckedMultiplyFractionError,
62    CheckedMultiplyRatioError, CoinFromStrError, CoinsError, ConversionOverflowError,
63    DivideByZeroError, DivisionError, OverflowError, OverflowOperation, PairingEqualityError,
64    RecoverPubkeyError, RoundDownOverflowError, RoundUpOverflowError, StdError, StdResult,
65    SystemError, VerificationError,
66};
67pub use crate::hex_binary::HexBinary;
68pub use crate::ibc::IbcChannelOpenResponse;
69pub use crate::ibc::{
70    Ibc3ChannelOpenResponse, IbcAckCallbackMsg, IbcAcknowledgement, IbcBasicResponse,
71    IbcCallbackRequest, IbcChannel, IbcChannelCloseMsg, IbcChannelConnectMsg, IbcChannelOpenMsg,
72    IbcDestinationCallbackMsg, IbcDstCallback, IbcEndpoint, IbcMsg, IbcOrder, IbcPacket,
73    IbcPacketAckMsg, IbcPacketReceiveMsg, IbcPacketTimeoutMsg, IbcReceiveResponse,
74    IbcSourceCallbackMsg, IbcSrcCallback, IbcTimeout, IbcTimeoutBlock, IbcTimeoutCallbackMsg,
75    TransferMsgBuilder,
76};
77#[cfg(feature = "iterator")]
78pub use crate::iterator::{Order, Record};
79pub use crate::math::{
80    Decimal, Decimal256, Decimal256RangeExceeded, DecimalRangeExceeded, Fraction, Int128, Int256,
81    Int512, Int64, Isqrt, SignedDecimal, SignedDecimal256, SignedDecimal256RangeExceeded,
82    SignedDecimalRangeExceeded, Uint128, Uint256, Uint512, Uint64,
83};
84pub use crate::metadata::{DenomMetadata, DenomUnit};
85pub use crate::never::Never;
86pub use crate::pagination::PageRequest;
87pub use crate::query::{
88    AllBalanceResponse, AllDelegationsResponse, AllDenomMetadataResponse, AllValidatorsResponse,
89    BalanceResponse, BankQuery, BondedDenomResponse, ChannelResponse, CodeInfoResponse,
90    ContractInfoResponse, CustomQuery, DecCoin, Delegation, DelegationResponse,
91    DelegationRewardsResponse, DelegationTotalRewardsResponse, DelegatorReward,
92    DelegatorValidatorsResponse, DelegatorWithdrawAddressResponse, DenomMetadataResponse,
93    DistributionQuery, FullDelegation, GrpcQuery, IbcQuery, ListChannelsResponse, PortIdResponse,
94    QueryRequest, StakingQuery, SupplyResponse, Validator, ValidatorResponse, WasmQuery,
95};
96#[cfg(all(feature = "stargate", feature = "cosmwasm_1_2"))]
97pub use crate::results::WeightedVoteOption;
98pub use crate::results::{
99    attr, wasm_execute, wasm_instantiate, AnyMsg, Attribute, BankMsg, ContractResult, CosmosMsg,
100    CustomMsg, Empty, Event, MsgResponse, QueryResponse, Reply, ReplyOn, Response, SubMsg,
101    SubMsgResponse, SubMsgResult, SystemResult, WasmMsg,
102};
103#[cfg(feature = "staking")]
104pub use crate::results::{DistributionMsg, StakingMsg};
105#[cfg(feature = "stargate")]
106pub use crate::results::{GovMsg, VoteOption};
107#[allow(deprecated)]
108pub use crate::serde::{
109    from_binary, from_json, from_slice, to_binary, to_json_binary, to_json_string, to_json_vec,
110    to_vec,
111};
112pub use crate::stdack::StdAck;
113pub use crate::storage::MemoryStorage;
114pub use crate::timestamp::Timestamp;
115pub use crate::traits::{Api, HashFunction, Querier, QuerierResult, QuerierWrapper, Storage};
116pub use crate::types::{BlockInfo, ContractInfo, Env, MessageInfo, TransactionInfo};
117
118// Exposed in wasm build only
119
120#[cfg(target_arch = "wasm32")]
121mod exports;
122#[cfg(target_arch = "wasm32")]
123mod imports;
124#[cfg(target_arch = "wasm32")]
125mod memory; // Used by exports and imports only. This assumes pointers are 32 bit long, which makes it untestable on dev machines.
126
127#[cfg(target_arch = "wasm32")]
128pub use crate::exports::{
129    do_execute, do_ibc_destination_callback, do_ibc_source_callback, do_instantiate, do_migrate,
130    do_query, do_reply, do_sudo,
131};
132#[cfg(all(feature = "stargate", target_arch = "wasm32"))]
133pub use crate::exports::{
134    do_ibc_channel_close, do_ibc_channel_connect, do_ibc_channel_open, do_ibc_packet_ack,
135    do_ibc_packet_receive, do_ibc_packet_timeout,
136};
137#[cfg(target_arch = "wasm32")]
138pub use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage};
139
140/// Exposed for testing only
141/// Both unit tests and integration tests are compiled to native code, so everything in here does not need to compile to Wasm.
142#[cfg(not(target_arch = "wasm32"))]
143pub mod testing;
144
145pub use cosmwasm_core::{BLS12_381_G1_GENERATOR, BLS12_381_G2_GENERATOR};
146
147/// This attribute macro generates the boilerplate required to call into the
148/// contract-specific logic from the entry-points to the Wasm module.
149///
150/// It should be added to the contract's init, handle, migrate and query implementations
151/// like this:
152/// ```
153/// # use cosmwasm_std::{
154/// #     Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo,
155/// #     Response, QueryResponse,
156/// # };
157/// #
158/// # type InstantiateMsg = ();
159/// # type ExecuteMsg = ();
160/// # type QueryMsg = ();
161///
162/// #[entry_point]
163/// pub fn instantiate(
164///     deps: DepsMut,
165///     env: Env,
166///     info: MessageInfo,
167///     msg: InstantiateMsg,
168/// ) -> Result<Response, StdError> {
169/// #   Ok(Default::default())
170/// }
171///
172/// #[entry_point]
173/// pub fn execute(
174///     deps: DepsMut,
175///     env: Env,
176///     info: MessageInfo,
177///     msg: ExecuteMsg,
178/// ) -> Result<Response, StdError> {
179/// #   Ok(Default::default())
180/// }
181///
182/// #[entry_point]
183/// pub fn query(
184///     deps: Deps,
185///     env: Env,
186///     msg: QueryMsg,
187/// ) -> Result<QueryResponse, StdError> {
188/// #   Ok(Default::default())
189/// }
190/// ```
191///
192/// where `InstantiateMsg`, `ExecuteMsg`, and `QueryMsg` are contract defined
193/// types that implement `DeserializeOwned + JsonSchema`.
194pub use cosmwasm_derive::entry_point;