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