diff --git a/sylvia-derive/src/contract/mt.rs b/sylvia-derive/src/contract/mt.rs index eb5cb0fe..fa8e2b9f 100644 --- a/sylvia-derive/src/contract/mt.rs +++ b/sylvia-derive/src/contract/mt.rs @@ -540,7 +540,7 @@ impl<'a> MtHelpers<'a> { } else { let reply_name = _reply.name().to_case(Case::Snake); quote! { - self. #reply_name ((deps, env, 0, vec![], vec![]).into(), msg).map_err(Into::into) + self. #reply_name ((deps, env).into(), msg).map_err(Into::into) } } }) diff --git a/sylvia-derive/src/entry_points.rs b/sylvia-derive/src/entry_points.rs index 8fcaaf21..96c5a6ad 100644 --- a/sylvia-derive/src/entry_points.rs +++ b/sylvia-derive/src/entry_points.rs @@ -211,7 +211,7 @@ impl<'a> EntryPoints<'a> { sv::dispatch_reply(deps, env, msg, contract).map_err(Into::into) }, MsgType::Reply => quote! { - #contract_turbofish ::new(). #reply((deps, env, 0, vec![], vec![]).into(), msg).map_err(Into::into) + #contract_turbofish ::new(). #reply((deps, env).into(), msg).map_err(Into::into) }, _ => quote! { msg.dispatch(& #contract_turbofish ::new() , ( #values )).map_err(Into::into) diff --git a/sylvia-derive/src/lib.rs b/sylvia-derive/src/lib.rs index 678c3f38..af8aca13 100644 --- a/sylvia-derive/src/lib.rs +++ b/sylvia-derive/src/lib.rs @@ -263,7 +263,8 @@ fn interface_impl(_attr: TokenStream2, item: TokenStream2) -> TokenStream2 { /// /// ## Example usage /// ```rust -/// # use sylvia::types::{ExecCtx, InstantiateCtx, MigrateCtx, QueryCtx, ReplyCtx, SudoCtx}; +/// # use sylvia::types::{ExecCtx, InstantiateCtx, MigrateCtx, QueryCtx, SudoCtx}; +/// # use sylvia::replies::ReplyCtx; /// # use sylvia::cw_std::{Binary, Response, StdError, SubMsgResult}; /// # use cw_storage_plus::Item; /// # use thiserror::Error; @@ -326,7 +327,8 @@ fn interface_impl(_attr: TokenStream2, item: TokenStream2) -> TokenStream2 { /// This would generate output like: /// /// ```rust -/// # use sylvia::types::{ExecCtx, InstantiateCtx, MigrateCtx, QueryCtx, ReplyCtx, SudoCtx}; +/// # use sylvia::types::{ExecCtx, InstantiateCtx, MigrateCtx, QueryCtx, SudoCtx}; +/// # use sylvia::replies::ReplyCtx; /// # use sylvia::cw_std::{Binary, Response, StdError, SubMsgResult}; /// # use cw_storage_plus::Item; /// # use thiserror::Error; @@ -670,7 +672,8 @@ fn contract_impl(attr: TokenStream2, item: TokenStream2) -> TokenStream2 { /// /// ## Example usage /// ```rust -/// # use sylvia::types::{ExecCtx, InstantiateCtx, MigrateCtx, QueryCtx, ReplyCtx, SudoCtx}; +/// # use sylvia::types::{ExecCtx, InstantiateCtx, MigrateCtx, QueryCtx, SudoCtx}; +/// # use sylvia::replies::ReplyCtx; /// # use sylvia::cw_std::{Binary, Reply, Response, StdResult, SubMsgResult}; /// # /// pub struct SvContract; diff --git a/sylvia/src/lib.rs b/sylvia/src/lib.rs index df65090a..71ed418b 100644 --- a/sylvia/src/lib.rs +++ b/sylvia/src/lib.rs @@ -28,3 +28,44 @@ pub use { cosmwasm_schema as cw_schema, cosmwasm_std as cw_std, schemars, serde, serde_cw_value as serde_value, serde_json_wasm as serde_json, }; + +pub mod replies { + use cosmwasm_std::{DepsMut, Empty, Env, Event, MsgResponse}; + + /// Represantation of `reply` context received in entry point. + #[deprecated( + since = "1.3.0", + note = "This type is added temporarily to not break existing API. Since `2.0.0` it will replace the `sylvia::types::ReplyCtx` type." + )] + #[non_exhaustive] + pub struct ReplyCtx<'a, C: cosmwasm_std::CustomQuery = Empty> { + pub deps: DepsMut<'a, C>, + pub env: Env, + pub gas_used: u64, + pub events: Vec, + pub msg_responses: Vec, + } + + #[allow(deprecated)] + impl<'a, C: cosmwasm_std::CustomQuery> + From<(DepsMut<'a, C>, Env, u64, Vec, Vec)> for ReplyCtx<'a, C> + { + fn from( + (deps, env, gas_used, events, msg_responses): ( + DepsMut<'a, C>, + Env, + u64, + Vec, + Vec, + ), + ) -> Self { + Self { + deps, + env, + gas_used, + events, + msg_responses, + } + } + } +} diff --git a/sylvia/src/types.rs b/sylvia/src/types.rs index 7eec2af9..9ab660bc 100644 --- a/sylvia/src/types.rs +++ b/sylvia/src/types.rs @@ -1,8 +1,6 @@ //! Module providing utilities to build and use sylvia contracts. -use cosmwasm_std::{ - Binary, Coin, Deps, DepsMut, Empty, Env, Event, MessageInfo, MsgResponse, WasmMsg, -}; +use cosmwasm_std::{Binary, Coin, Deps, DepsMut, Empty, Env, MessageInfo, WasmMsg}; use derivative::Derivative; use schemars::JsonSchema; use serde::de::DeserializeOwned; @@ -462,12 +460,13 @@ impl<'a, Contract: ?Sized> AsRef for Remote<'a, Contract> { /// Represantation of `reply` context received in entry point. #[non_exhaustive] +#[deprecated( + since = "1.3.0", + note = "This type will be replaced with `sylvia::replies::ReplyCtx` in 2.0.0." +)] pub struct ReplyCtx<'a, C: cosmwasm_std::CustomQuery = Empty> { pub deps: DepsMut<'a, C>, pub env: Env, - pub gas_used: u64, - pub events: Vec, - pub msg_responses: Vec, } /// Represantation of `migrate` context received in entry point. @@ -542,25 +541,10 @@ impl<'a, C: cosmwasm_std::CustomQuery> From<(DepsMut<'a, C>, Env)> for MigrateCt } } -impl<'a, C: cosmwasm_std::CustomQuery> - From<(DepsMut<'a, C>, Env, u64, Vec, Vec)> for ReplyCtx<'a, C> -{ - fn from( - (deps, env, gas_used, events, msg_responses): ( - DepsMut<'a, C>, - Env, - u64, - Vec, - Vec, - ), - ) -> Self { - Self { - deps, - env, - gas_used, - events, - msg_responses, - } +#[allow(deprecated)] +impl<'a, C: cosmwasm_std::CustomQuery> From<(DepsMut<'a, C>, Env)> for ReplyCtx<'a, C> { + fn from((deps, env): (DepsMut<'a, C>, Env)) -> Self { + Self { deps, env } } } diff --git a/sylvia/tests/legacy_replies.rs b/sylvia/tests/legacy_replies.rs index bb5a513f..8f42d3f8 100644 --- a/sylvia/tests/legacy_replies.rs +++ b/sylvia/tests/legacy_replies.rs @@ -33,7 +33,9 @@ mod noop_contract { mod reply_contract { use cosmwasm_std::Reply; - use sylvia::types::{ExecCtx, InstantiateCtx, ReplyCtx}; + #[allow(deprecated)] + use sylvia::types::ReplyCtx; + use sylvia::types::{ExecCtx, InstantiateCtx}; use sylvia::{contract, entry_points}; use sylvia::cw_std::{to_json_binary, Response, StdResult, SubMsg, WasmMsg}; @@ -70,6 +72,7 @@ mod reply_contract { } #[sv::msg(reply)] + #[allow(deprecated)] fn reply(&self, _ctx: ReplyCtx, _reply: Reply) -> StdResult { let resp = Response::new().set_data(to_json_binary("data")?); Ok(resp) diff --git a/sylvia/tests/messages_generation.rs b/sylvia/tests/messages_generation.rs index a752ee6a..93b46f5a 100644 --- a/sylvia/tests/messages_generation.rs +++ b/sylvia/tests/messages_generation.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use std::fmt::Debug; use std::str::FromStr; diff --git a/sylvia/tests/reply_data.rs b/sylvia/tests/reply_data.rs index f336720c..06bf7c78 100644 --- a/sylvia/tests/reply_data.rs +++ b/sylvia/tests/reply_data.rs @@ -6,7 +6,9 @@ use noop_contract::sv::{Executor, NoopContractInstantiateBuilder}; use sv::SubMsgMethods; use sylvia::builder::instantiate::InstantiateBuilder; use sylvia::cw_std::{Addr, Binary, Response, StdError, SubMsg}; -use sylvia::types::{ExecCtx, InstantiateCtx, Remote, ReplyCtx}; +#[allow(deprecated)] +use sylvia::replies::ReplyCtx; +use sylvia::types::{ExecCtx, InstantiateCtx, Remote}; use sylvia::{contract, entry_points}; use thiserror::Error; @@ -114,6 +116,7 @@ impl Contract { } #[sv::msg(reply, reply_on=success)] + #[allow(deprecated)] fn remote_instantiated( &self, ctx: ReplyCtx, @@ -133,6 +136,7 @@ impl Contract { } #[sv::msg(reply, reply_on=success)] + #[allow(deprecated)] fn _optional_remote_instantiated( &self, _ctx: ReplyCtx, @@ -143,6 +147,7 @@ impl Contract { } #[sv::msg(reply, reply_on=success)] + #[allow(deprecated)] fn data_raw_opt( &self, _ctx: ReplyCtx, @@ -153,6 +158,7 @@ impl Contract { } #[sv::msg(reply, reply_on=success)] + #[allow(deprecated)] fn data_raw( &self, _ctx: ReplyCtx, @@ -163,6 +169,7 @@ impl Contract { } #[sv::msg(reply, reply_on=success)] + #[allow(deprecated)] fn data_opt( &self, _ctx: ReplyCtx, @@ -173,6 +180,7 @@ impl Contract { } #[sv::msg(reply, reply_on=success)] + #[allow(deprecated)] fn data( &self, _ctx: ReplyCtx, diff --git a/sylvia/tests/reply_dispatch.rs b/sylvia/tests/reply_dispatch.rs index 3de94123..89fd2184 100644 --- a/sylvia/tests/reply_dispatch.rs +++ b/sylvia/tests/reply_dispatch.rs @@ -8,7 +8,9 @@ use sv::{ }; use sylvia::builder::instantiate::InstantiateBuilder; use sylvia::cw_std::{Addr, Binary, Response, StdError, SubMsg}; -use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, InstantiateCtx, QueryCtx, Remote, ReplyCtx}; +#[allow(deprecated)] +use sylvia::replies::ReplyCtx; +use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, InstantiateCtx, QueryCtx, Remote}; use sylvia::{contract, entry_points}; use thiserror::Error; @@ -210,6 +212,7 @@ where } #[sv::msg(reply, reply_on=success)] + #[allow(deprecated)] fn remote_instantiated( &self, ctx: ReplyCtx, @@ -232,6 +235,7 @@ where } #[sv::msg(reply, handlers=[success, both], reply_on=success)] + #[allow(deprecated)] fn success( &self, ctx: ReplyCtx, @@ -244,6 +248,7 @@ where } #[sv::msg(reply, handlers=[error, both], reply_on=error)] + #[allow(deprecated)] fn error( &self, ctx: ReplyCtx, @@ -256,6 +261,7 @@ where } #[sv::msg(reply, reply_on=always)] + #[allow(deprecated)] fn always( &self, ctx: ReplyCtx, @@ -270,6 +276,7 @@ where } #[sv::msg(exec)] + #[allow(deprecated)] fn send_cosmos_messages(&self, ctx: ExecCtx) -> Result, ContractError> { let remote_addr = self.remote.load(ctx.deps.storage)?; let cosmos_msg = CosmosMsg::Bank(BankMsg::Send { diff --git a/sylvia/tests/reply_generation.rs b/sylvia/tests/reply_generation.rs index c57ab230..9bc34cef 100644 --- a/sylvia/tests/reply_generation.rs +++ b/sylvia/tests/reply_generation.rs @@ -1,7 +1,9 @@ use cosmwasm_std::{Binary, SubMsgResult}; use itertools::Itertools; use sylvia::cw_std::{Response, StdResult}; -use sylvia::types::{InstantiateCtx, ReplyCtx}; +#[allow(deprecated)] +use sylvia::replies::ReplyCtx; +use sylvia::types::InstantiateCtx; use sylvia::{contract, entry_points}; pub struct Contract; @@ -20,6 +22,7 @@ impl Contract { } #[sv::msg(reply)] + #[allow(deprecated)] fn clean( &self, _ctx: ReplyCtx, @@ -29,7 +32,7 @@ impl Contract { Ok(Response::new()) } - #[allow(dead_code)] + #[allow(dead_code, deprecated)] #[sv::msg(reply, handlers=[handler_one, handler_two])] fn custom_handlers( &self, @@ -40,7 +43,7 @@ impl Contract { Ok(Response::new()) } - #[allow(dead_code)] + #[allow(dead_code, deprecated)] #[sv::msg(reply, reply_on = success)] fn reply_on( &self, @@ -51,7 +54,7 @@ impl Contract { Ok(Response::new()) } - #[allow(dead_code)] + #[allow(dead_code, deprecated)] #[sv::msg(reply, reply_on = always)] fn reply_on_always( &self, @@ -62,7 +65,7 @@ impl Contract { Ok(Response::new()) } - #[allow(dead_code)] + #[allow(dead_code, deprecated)] #[sv::msg(reply, handlers=[reply_on], reply_on = error)] fn both_parameters( &self, diff --git a/sylvia/tests/ui/attributes/data/missing_attribute.rs b/sylvia/tests/ui/attributes/data/missing_attribute.rs index bed0fd3d..bc018545 100644 --- a/sylvia/tests/ui/attributes/data/missing_attribute.rs +++ b/sylvia/tests/ui/attributes/data/missing_attribute.rs @@ -1,4 +1,4 @@ -#![allow(unused_imports)] +#![allow(unused_imports, deprecated)] use sylvia::contract; use sylvia::cw_std::{Reply, Response, StdResult}; diff --git a/sylvia/tests/ui/attributes/msg/invalid_params.rs b/sylvia/tests/ui/attributes/msg/invalid_params.rs index 74fb6d4a..9751bb89 100644 --- a/sylvia/tests/ui/attributes/msg/invalid_params.rs +++ b/sylvia/tests/ui/attributes/msg/invalid_params.rs @@ -1,4 +1,4 @@ -#![allow(unused_imports)] +#![allow(unused_imports, deprecated)] use sylvia::contract; use sylvia::cw_std::{Reply, Response, StdResult}; use sylvia::types::{InstantiateCtx, ReplyCtx}; diff --git a/sylvia/tests/ui/attributes/msg/overlapping_reply_handlers.rs b/sylvia/tests/ui/attributes/msg/overlapping_reply_handlers.rs index 1eca1dd7..4a2b5a35 100644 --- a/sylvia/tests/ui/attributes/msg/overlapping_reply_handlers.rs +++ b/sylvia/tests/ui/attributes/msg/overlapping_reply_handlers.rs @@ -1,8 +1,9 @@ -#![allow(unused_imports)] +#![allow(unused_imports, deprecated)] use sylvia::contract; use sylvia::cw_std::{Reply, Response, StdResult}; -use sylvia::types::{InstantiateCtx, ReplyCtx}; +use sylvia::replies::ReplyCtx; +use sylvia::types::InstantiateCtx; pub struct Contract; diff --git a/sylvia/tests/ui/attributes/msg/overlapping_reply_handlers.stderr b/sylvia/tests/ui/attributes/msg/overlapping_reply_handlers.stderr index edb8c673..58b2a91b 100644 --- a/sylvia/tests/ui/attributes/msg/overlapping_reply_handlers.stderr +++ b/sylvia/tests/ui/attributes/msg/overlapping_reply_handlers.stderr @@ -2,16 +2,16 @@ error: Duplicated reply handler. = note: Previous definition of handler=`HANDLER_1_REPLY_ID` for reply_on=`always` defined on `fn reply_always()` - --> tests/ui/attributes/msg/overlapping_reply_handlers.rs:26:32 + --> tests/ui/attributes/msg/overlapping_reply_handlers.rs:27:32 | -26 | #[sv::msg(reply, handlers=[handler1], reply_on=success)] +27 | #[sv::msg(reply, handlers=[handler1], reply_on=success)] | ^^^^^^^^ error: Duplicated reply handler. = note: Previous definition of handler=`HANDLER_2_REPLY_ID` for reply_on=`error` defined on `fn some_reply()` - --> tests/ui/attributes/msg/overlapping_reply_handlers.rs:41:8 + --> tests/ui/attributes/msg/overlapping_reply_handlers.rs:42:8 | -41 | fn handler2(&self, _ctx: ReplyCtx, _reply: Reply) -> StdResult { +42 | fn handler2(&self, _ctx: ReplyCtx, _reply: Reply) -> StdResult { | ^^^^^^^^ diff --git a/sylvia/tests/ui/method_signature/reply.rs b/sylvia/tests/ui/method_signature/reply.rs index 9e718df5..16084744 100644 --- a/sylvia/tests/ui/method_signature/reply.rs +++ b/sylvia/tests/ui/method_signature/reply.rs @@ -1,6 +1,7 @@ -#![allow(unused_imports)] +#![allow(unused_imports, deprecated)] use sylvia::cw_std::{Binary, Response, StdResult}; -use sylvia::types::{InstantiateCtx, ReplyCtx}; +use sylvia::replies::ReplyCtx; +use sylvia::types::InstantiateCtx; pub mod mismatched_params { use super::*; diff --git a/sylvia/tests/ui/method_signature/reply.stderr b/sylvia/tests/ui/method_signature/reply.stderr index d75a4008..85f5538c 100644 --- a/sylvia/tests/ui/method_signature/reply.stderr +++ b/sylvia/tests/ui/method_signature/reply.stderr @@ -3,9 +3,9 @@ error: Mismatched parameter in reply handlers. = note: Parameters for the `on_instantiated` handler have to be the same. = note: Previous parameter defined for the `on_instantiated` handler. - --> tests/ui/method_signature/reply.rs:27:13 + --> tests/ui/method_signature/reply.rs:28:13 | -27 | param: String, +28 | param: String, | ^^^^^ error: Mismatched quantity of method parameters. @@ -13,7 +13,7 @@ error: Mismatched quantity of method parameters. = note: Both `on_instantiated` handlers should have the same number of parameters. = note: Previous definition of on_instantiated handler. - --> tests/ui/method_signature/reply.rs:62:12 + --> tests/ui/method_signature/reply.rs:63:12 | -62 | fn first_reply( +63 | fn first_reply( | ^^^^^^^^^^^