fadroma/
lib.rs

1//! # Note on network support
2//! Fadroma currently only supports Secret Network flavoured CosmWasm.
3//! As such, you **MUST** enable the `scrt` feature flag. Otherwise,
4//! you will get compilation errors - this is by design.
5
6#[cfg(not(feature = "scrt"))]
7std::compile_error!("Fadroma only currently supports Secret Network so the \"scrt\" feature must be enabled.");
8
9#[cfg(feature = "scrt")]
10pub use secret_cosmwasm_std as cosmwasm_std;
11pub use schemars;
12pub use serde;
13
14pub mod bin_serde;
15pub mod core;
16
17#[cfg(feature = "scrt")]
18pub mod scrt;
19
20pub mod tokens;
21pub use fadroma_dsl as dsl;
22pub mod killswitch;
23pub mod admin;
24#[cfg(feature = "crypto")]
25pub mod crypto;
26
27// Storage helpers
28pub mod storage;
29
30// Testing system
31#[cfg(all(feature = "ensemble", not(target_arch = "wasm32")))]
32pub mod ensemble;
33
34/// **Start here.** `use fadroma::prelude::*` to get the essentials for
35/// writing smart contracts with Fadroma.
36pub mod prelude {
37    /// Alias for `StdResult<()>`.
38    pub type UsuallyOk = cosmwasm_std::StdResult<()>;
39
40    /// Alias for `StdResult<Option<V>>`.
41    pub type Eventually<V> = cosmwasm_std::StdResult<Option<V>>;
42
43    pub use crate::core::*;
44
45    pub use crate::bin_serde::{FadromaSerialize, FadromaDeserialize};
46
47    pub use crate::cosmwasm_std::{self, *};
48    #[cfg(feature = "scrt")]
49    pub use crate::scrt::{ResponseExt, to_cosmos_msg, space_pad, BLOCK_SIZE};
50
51    pub use crate::tokens::*;
52
53    pub use schemars::{self, JsonSchema};
54
55    pub use crate::storage::{
56        self, Key, Namespace, CompositeKey, StaticKey, FixedSegmentSizeKey,
57        TypedKey, TypedKey2, TypedKey3, TypedKey4, SingleItem, ItemSpace
58    };
59
60    #[cfg(feature = "vk")]
61    pub use crate::scrt::vk::{ViewingKey, ViewingKeyHashed};
62
63    #[cfg(feature = "permit")]
64    pub use crate::scrt::permit::{Permission, Permit};
65}
66
67/// Define the `mod wasm` entrypoint for production builds,
68/// using the provided entry point functions.
69/// 
70/// Supports `init`, `execute` and `query` **or**
71/// `init`, `execute`, `query` and `reply`.
72/// 
73/// Note that Fadroma DSL already handles this for you and
74/// as such this macro is not needed when using it.
75/// 
76/// # Examples
77/// 
78/// ```
79/// # #[macro_use] extern crate fadroma;
80/// # use fadroma::cosmwasm_std::{Deps, DepsMut, Env, MessageInfo, StdResult, Response, Binary, to_binary};
81/// # #[derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
82/// # pub struct InitMsg;
83/// # #[derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
84/// # pub struct ExecuteMsg;
85/// # #[derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
86/// # pub struct QueryMsg;
87/// pub fn instantiate(
88///     _deps: DepsMut,
89///     _env: Env,
90///     _info: MessageInfo,
91///     _msg: InitMsg
92/// ) -> StdResult<Response> {
93///     Ok(Response::default())
94/// }
95///
96/// pub fn execute(
97///     _deps: DepsMut,
98///     _env: Env,
99///     _info: MessageInfo,
100///     _msg: ExecuteMsg
101/// ) -> StdResult<Response> {
102///     Ok(Response::default())
103/// }
104///
105/// pub fn query(
106///     _deps: Deps,
107///     _env: Env,
108///     _msg: QueryMsg
109/// ) -> StdResult<Binary> {
110///     to_binary(&true)
111/// }
112/// 
113/// entrypoint! {
114///     init: instantiate,
115///     execute: execute,
116///     query: query
117/// }
118/// ```
119#[macro_export]
120macro_rules! entrypoint {
121    (@init $($init:ident)::+) => {
122        #[no_mangle]
123        extern "C" fn instantiate(env_ptr: u32, info_ptr: u32, msg_ptr: u32) -> u32 {
124            $crate::cosmwasm_std::do_instantiate(&super::$($init)::+, env_ptr, info_ptr, msg_ptr)
125        }
126    };
127
128    (@execute $($execute:ident)::+) => {
129        #[no_mangle]
130        extern "C" fn execute(env_ptr: u32, info_ptr: u32, msg_ptr: u32) -> u32 {
131            $crate::cosmwasm_std::do_execute(&super::$($execute)::+, env_ptr, info_ptr, msg_ptr)
132        }
133    };
134
135    (@query $($query:ident)::+) => {
136        #[no_mangle]
137        extern "C" fn query(env_ptr: u32, msg_ptr: u32) -> u32 {
138            $crate::cosmwasm_std::do_query(&super::$($query)::+, env_ptr, msg_ptr)
139        }
140    };
141
142    (@reply $($reply:ident)::+) => {
143        #[no_mangle]
144        extern "C" fn reply(env_ptr: u32, msg_ptr: u32) -> u32 {
145            $crate::cosmwasm_std::do_reply(&super::$($reply)::+, env_ptr, msg_ptr)
146        }
147    };
148
149    (@wasm_mod $($contents:tt)*) => {
150        #[cfg(target_arch = "wasm32")]
151        mod wasm {
152            $($contents)*
153        }
154    };
155
156    (
157        init: $($init:ident)::+,
158        execute: $($execute:ident)::+,
159        query: $($query:ident)::+
160        $(, reply: $($reply:ident)::+)?
161    ) => {
162        $crate::entrypoint! {
163            @wasm_mod
164            $crate::entrypoint!(@init    $($init)::+);
165            $crate::entrypoint!(@execute $($execute)::+);
166            $crate::entrypoint!(@query   $($query)::+);
167            $($crate::entrypoint!(@reply $($reply)::+);)?
168        }
169    };
170}