cosmwasm_std/
lib.rs

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