From 29cc7b6f45b3336a23305b6c41e6da4a92f6a38d Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Fri, 6 Sep 2024 17:11:10 +0200 Subject: [PATCH] Document entry_point in cosmwasm-std instead of derive Closes #2186 (cherry picked from commit e230048f13e25982371ca1c3c7f97c0e87aa08c6) # Conflicts: # Cargo.lock # packages/derive/Cargo.toml # packages/derive/src/lib.rs # packages/std/src/lib.rs --- Cargo.lock | 6 +++ packages/derive/Cargo.toml | 6 +++ packages/derive/src/lib.rs | 4 ++ packages/std/src/lib.rs | 89 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 0e3cb27180..4a403c5fde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -446,8 +446,14 @@ dependencies = [ name = "cosmwasm-derive" version = "2.0.7" dependencies = [ +<<<<<<< HEAD "cosmwasm-std", "syn 1.0.109", +======= + "proc-macro2", + "quote", + "syn 2.0.66", +>>>>>>> e230048f1 (Document entry_point in cosmwasm-std instead of derive) ] [[package]] diff --git a/packages/derive/Cargo.toml b/packages/derive/Cargo.toml index f0722ec99c..3f69dddc2d 100644 --- a/packages/derive/Cargo.toml +++ b/packages/derive/Cargo.toml @@ -15,6 +15,7 @@ proc-macro = true default = [] [dependencies] +<<<<<<< HEAD syn = { version = "1.0", features = ["full"] } [dev-dependencies] @@ -23,3 +24,8 @@ syn = { version = "1.0", features = ["full"] } # "(a package can have an indirect dev-dependency on itself)" # https://users.rust-lang.org/t/does-cargo-support-cyclic-dependencies/35666/3 cosmwasm-std = { path = "../std" } +======= +proc-macro2 = "1.0.79" +quote = "1.0.35" +syn = { version = "2", features = ["full"] } +>>>>>>> e230048f1 (Document entry_point in cosmwasm-std instead of derive) diff --git a/packages/derive/src/lib.rs b/packages/derive/src/lib.rs index 1a0f516f1f..c35dc73e61 100644 --- a/packages/derive/src/lib.rs +++ b/packages/derive/src/lib.rs @@ -4,6 +4,7 @@ extern crate syn; use proc_macro::TokenStream; use std::str::FromStr; +<<<<<<< HEAD /// This attribute macro generates the boilerplate required to call into the /// contract-specific logic from the entry-points to the Wasm module. /// @@ -51,6 +52,9 @@ use std::str::FromStr; /// /// where `InstantiateMsg`, `ExecuteMsg`, and `QueryMsg` are contract defined /// types that implement `DeserializeOwned + JsonSchema`. +======= +// function documented in cosmwasm-std +>>>>>>> e230048f1 (Document entry_point in cosmwasm-std instead of derive) #[proc_macro_attribute] pub fn entry_point(_attr: TokenStream, mut item: TokenStream) -> TokenStream { let cloned = item.clone(); diff --git a/packages/std/src/lib.rs b/packages/std/src/lib.rs index 75ab78e1e2..4f5b06d214 100644 --- a/packages/std/src/lib.rs +++ b/packages/std/src/lib.rs @@ -132,6 +132,95 @@ pub use crate::imports::{ExternalApi, ExternalQuerier, ExternalStorage}; #[cfg(not(target_arch = "wasm32"))] pub mod testing; +<<<<<<< HEAD // Re-exports +======= +pub use cosmwasm_core::{BLS12_381_G1_GENERATOR, BLS12_381_G2_GENERATOR}; + +/// This attribute macro generates the boilerplate required to call into the +/// contract-specific logic from the entry-points to the Wasm module. +/// +/// It should be added to the contract's init, handle, migrate and query implementations +/// like this: +/// ``` +/// # use cosmwasm_std::{ +/// # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, +/// # Response, QueryResponse, +/// # }; +/// # +/// # type InstantiateMsg = (); +/// # type ExecuteMsg = (); +/// # type QueryMsg = (); +/// +/// #[entry_point] +/// pub fn instantiate( +/// deps: DepsMut, +/// env: Env, +/// info: MessageInfo, +/// msg: InstantiateMsg, +/// ) -> Result { +/// # Ok(Default::default()) +/// } +/// +/// #[entry_point] +/// pub fn execute( +/// deps: DepsMut, +/// env: Env, +/// info: MessageInfo, +/// msg: ExecuteMsg, +/// ) -> Result { +/// # Ok(Default::default()) +/// } +/// +/// #[entry_point] +/// pub fn query( +/// deps: Deps, +/// env: Env, +/// msg: QueryMsg, +/// ) -> Result { +/// # Ok(Default::default()) +/// } +/// ``` +/// +/// where `InstantiateMsg`, `ExecuteMsg`, and `QueryMsg` are contract defined +/// types that implement `DeserializeOwned + JsonSchema`. +/// +/// ## Set the version of the state of your contract +/// +/// The VM will use this as a hint whether it needs to run the migrate function of your contract or not. +/// +/// ``` +/// # use cosmwasm_std::{ +/// # DepsMut, entry_point, Env, MigrateInfo, +/// # Response, StdResult, +/// # }; +/// # +/// # type MigrateMsg = (); +/// #[entry_point] +/// #[migrate_version(2)] +/// pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg, migrate_info: MigrateInfo) -> StdResult { +/// todo!(); +/// } +/// ``` +/// +/// It is also possible to assign the migrate version number to +/// a given constant name: +/// +/// ``` +/// # use cosmwasm_std::{ +/// # DepsMut, entry_point, Env, MigrateInfo, +/// # Response, StdResult, +/// # }; +/// # +/// # type MigrateMsg = (); +/// const CONTRACT_VERSION: u64 = 66; +/// +/// #[entry_point] +/// #[migrate_version(CONTRACT_VERSION)] +/// pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg, migrate_info: MigrateInfo) -> StdResult { +/// todo!(); +/// } +/// ``` +>>>>>>> e230048f1 (Document entry_point in cosmwasm-std instead of derive) pub use cosmwasm_derive::entry_point;