Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/contracts/generic_contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ pub struct GenericContract<
#[sv::messages(generic as Generic: custom(msg, query))]
#[sv::messages(custom_and_generic as CustomAndGeneric)]
#[sv::custom(msg=SvCustomMsg, query=SvCustomQuery)]
#[sv::features(replies)]
impl<
InstantiateT,
Exec1T,
Expand Down
1 change: 0 additions & 1 deletion examples/contracts/generics_forwarded/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ pub struct GenericsForwardedContract<
#[sv::messages(cw1 as Cw1: custom(msg, query))]
#[sv::messages(custom_and_generic as CustomAndGeneric)]
#[sv::custom(msg=CustomMsgT, query=CustomQueryT)]
#[sv::features(replies)]
impl<
InstantiateT,
Exec1T,
Expand Down
8 changes: 2 additions & 6 deletions sylvia-derive/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct ContractInput<'a> {
custom: Custom,
override_entry_points: Vec<OverrideEntryPoint>,
interfaces: Interfaces,
sv_features: SylviaFeatures,
_sv_features: SylviaFeatures,
}

impl<'a> ContractInput<'a> {
Expand All @@ -69,7 +69,7 @@ impl<'a> ContractInput<'a> {
custom,
override_entry_points,
interfaces,
sv_features,
_sv_features: sv_features,
}
}

Expand Down Expand Up @@ -189,10 +189,6 @@ impl<'a> ContractInput<'a> {
}

fn emit_reply(&self) -> TokenStream {
if !self.sv_features.replies {
return quote! {};
}

let variants = MsgVariants::new(self.item.as_variants(), MsgType::Reply, &[], &None);

Reply::new(self.item, &self.generics, &variants).emit()
Expand Down
18 changes: 3 additions & 15 deletions sylvia-derive/src/contract/mt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use syn::{parse_quote, GenericParam, ItemImpl, Type};

use crate::crate_module;
use crate::parser::attributes::features::SylviaFeatures;
use crate::parser::attributes::msg::MsgType;
use crate::parser::variant_descs::AsVariantDescs;
use crate::parser::{
Expand All @@ -24,7 +23,6 @@
where_clause: &'a Option<syn::WhereClause>,
custom: &'a Custom,
override_entry_points: Vec<OverrideEntryPoint>,
sv_features: SylviaFeatures,
instantiate_variant: MsgVariants<'a, GenericParam>,
exec_variants: MsgVariants<'a, GenericParam>,
query_variants: MsgVariants<'a, GenericParam>,
Expand Down Expand Up @@ -81,7 +79,6 @@
let parsed_attrs = ParsedSylviaAttributes::new(source.attrs.iter());
let error_type = parsed_attrs.error_attrs.unwrap_or_default().error;
let error_type = parse_quote! { #error_type };
let sv_features = parsed_attrs.sv_features;

let contract_name = &source.self_ty;

Expand All @@ -93,7 +90,6 @@
contract_name,
custom,
override_entry_points,
sv_features,
instantiate_variant,
exec_variants,
query_variants,
Expand Down Expand Up @@ -480,7 +476,6 @@
contract_name,
custom,
override_entry_points,
sv_features,
generic_params,
migrate_variants,
reply_variants,
Expand Down Expand Up @@ -532,16 +527,9 @@
quote! { #contract_ident }
};

if sv_features.replies {
quote! {
let contract = #contract_turbofish ::new();
dispatch_reply(deps, env, msg, contract).map_err(Into::into)
}
} else {
let reply_name = _reply.name().to_case(Case::Snake);
quote! {
self. #reply_name ((deps, env).into(), msg).map_err(Into::into)
}
quote! {
let contract = #contract_turbofish ::new();
dispatch_reply(deps, env, msg, contract).map_err(Into::into)

Check warning on line 532 in sylvia-derive/src/contract/mt.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/contract/mt.rs#L530-L532

Added lines #L530 - L532 were not covered by tests
}
})
.unwrap_or_else(|| {
Expand Down
16 changes: 4 additions & 12 deletions sylvia-derive/src/entry_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
generics: Vec<&'a GenericParam>,
where_clause: &'a Option<WhereClause>,
attrs: &'a EntryPointArgs,
sv_features: SylviaFeatures,
_sv_features: SylviaFeatures,
}

impl<'a> EntryPoints<'a> {
Expand Down Expand Up @@ -99,7 +99,7 @@
generics,
where_clause,
attrs,
sv_features,
_sv_features: sv_features,
}
}

Expand Down Expand Up @@ -172,12 +172,7 @@

fn emit_default_entry_point(&self, msg_ty: MsgType) -> TokenStream {
let Self {
name,
error,
attrs,
reply,
sv_features,
..
name, error, attrs, ..

Check warning on line 175 in sylvia-derive/src/entry_points.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/entry_points.rs#L175

Added line #L175 was not covered by tests
} = self;
let sylvia = crate_module();

Expand Down Expand Up @@ -206,13 +201,10 @@
_ => quote! { msg: < #contract as #sylvia ::types::ContractApi> :: #associated_name },
};
let dispatch = match msg_ty {
MsgType::Reply if sv_features.replies => quote! {
MsgType::Reply => quote! {

Check warning on line 204 in sylvia-derive/src/entry_points.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/entry_points.rs#L204

Added line #L204 was not covered by tests
let contract = #contract_turbofish ::new();
sv::dispatch_reply(deps, env, msg, contract).map_err(Into::into)
},
MsgType::Reply => quote! {
#contract_turbofish ::new(). #reply((deps, env).into(), msg).map_err(Into::into)
},
_ => quote! {
msg.dispatch(& #contract_turbofish ::new() , ( #values )).map_err(Into::into)
},
Expand Down
18 changes: 1 addition & 17 deletions sylvia-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ fn interface_impl(_attr: TokenStream2, item: TokenStream2) -> TokenStream2 {
///
/// ##[sylvia::contract]
/// ##[sv::error(ContractError)]
/// ##[sv::features(replies)]
/// impl SvContract {
/// pub const fn new() -> Self {
/// Self {
Expand Down Expand Up @@ -628,29 +627,15 @@ fn interface_impl(_attr: TokenStream2, item: TokenStream2) -> TokenStream2 {
/// Enables additional features for the contract. Allows user to use features that
/// are considered breaking before the major release.
///
/// Currently supported features are:
/// * `replies` - enables better dispatching of `reply` as well as its auto deserialization.
/// With this feature enabled, user can use additional parameters in the
/// `sv::msg` attribute like so:
/// `#[sv::msg(reply, handlers=[scenario1, scenario2], reply_on=Success)]`.
///
/// Based on this parameters reply ids will be generated and associated with
/// proper scenario specified by the `reply_on` parameter.
///
/// User can also specify custom `data` and `payload` types that will be auto
/// deserialized from the `cosmwasm_std::Binary` type.
/// No currently supported features.
///
/// ### `sv::payload(raw)`
///
/// Requires contract to be marked with the `sv::features(replies)`.
///
/// Used next to the reply method argument. It disables auto deserialization
/// of the payload argument.
///
/// ### `sv::data(...)`
///
/// Requires contract to be marked with the `sv::features(replies)`.
///
/// Used next to the reply method argument. Based on the passed parameters
/// it enables different behavior:
///
Expand Down Expand Up @@ -740,7 +725,6 @@ fn contract_impl(attr: TokenStream2, item: TokenStream2) -> TokenStream2 {
///
/// ##[sylvia::entry_points]
/// ##[sylvia::contract]
/// ##[sv::features(replies)]
/// impl SvContract {
/// pub const fn new() -> Self {
/// Self
Expand Down
28 changes: 8 additions & 20 deletions sylvia-derive/src/parser/attributes/features.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use proc_macro_error::emit_error;
use syn::parse::{Parse, ParseStream, Parser};
use syn::{Error, Ident, MetaList, Result, Token};
use syn::{Error, Ident, MetaList, Result};

/// Type wrapping data parsed from `sv::features` attribute.
#[derive(Debug, Default)]
pub struct SylviaFeatures {
/// Enables better dispatching and deserialization for replies.
pub replies: bool,
}
pub struct SylviaFeatures {}

impl SylviaFeatures {
pub fn new(attr: &MetaList) -> Result<Self> {
Expand All @@ -22,23 +19,14 @@

impl Parse for SylviaFeatures {
fn parse(input: ParseStream) -> Result<Self> {
let mut features = Self::default();
let features = Self::default();

Check warning on line 22 in sylvia-derive/src/parser/attributes/features.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/parser/attributes/features.rs#L22

Added line #L22 was not covered by tests

while !input.is_empty() {
if !input.is_empty() {

Check warning on line 24 in sylvia-derive/src/parser/attributes/features.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/parser/attributes/features.rs#L24

Added line #L24 was not covered by tests
let feature: Ident = input.parse()?;
match feature.to_string().as_str() {
"replies" => features.replies = true,
_ => {
return Err(Error::new(
feature.span(),
"Invalid feature.\n= note: Supported features for contract macro: [`replies`].\n",
))
}
}
if !input.peek(Token![,]) {
break;
}
let _: Token![,] = input.parse()?;
return Err(Error::new(
feature.span(),
"Invalid feature.\n= note: No features supported currently.\n",

Check warning on line 28 in sylvia-derive/src/parser/attributes/features.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/parser/attributes/features.rs#L26-L28

Added lines #L26 - L28 were not covered by tests
));
}

Ok(features)
Expand Down
1 change: 0 additions & 1 deletion sylvia/tests/messages_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ mod contract {
#[sv::msg_attr(instantiate, error("Instantiate"))]
#[sv::msg_attr(migrate, derive(PartialOrd, Error))]
#[sv::msg_attr(migrate, error("Migrate"))]
#[sv::features(replies)]
impl Contract {
#[allow(clippy::new_without_default)]
#[allow(dead_code)]
Expand Down
1 change: 0 additions & 1 deletion sylvia/tests/reply_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ pub struct Contract {
#[entry_points]
#[contract]
#[sv::error(ContractError)]
#[sv::features(replies)]
impl Contract {
pub fn new() -> Self {
Self {
Expand Down
1 change: 0 additions & 1 deletion sylvia/tests/reply_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ pub struct Contract<M, Q> {
#[contract]
#[sv::error(ContractError)]
#[sv::custom(msg=M, query=Q)]
#[sv::features(replies)]
impl<M, Q> Contract<M, Q>
where
M: CustomMsg + 'static,
Expand Down
1 change: 0 additions & 1 deletion sylvia/tests/reply_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub struct Contract;

#[entry_points]
#[contract]
#[sv::features(replies)]
impl Contract {
pub fn new() -> Self {
Self
Expand Down
2 changes: 0 additions & 2 deletions sylvia/tests/ui/attributes/data/invalid_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub mod invalid_data {
pub struct Contract;

#[contract]
#[sv::features(replies)]
impl Contract {
pub fn new() -> Self {
Self
Expand Down Expand Up @@ -39,7 +38,6 @@ pub mod instantiate_and_raw {
pub struct Contract;

#[contract]
#[sv::features(replies)]
impl Contract {
pub fn new() -> Self {
Self
Expand Down
8 changes: 4 additions & 4 deletions sylvia/tests/ui/attributes/data/invalid_params.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
error: Invalid data parameter.

= note: Expected one of [`raw`, `opt`, `instantiate`] comma separated.
--> tests/ui/attributes/data/invalid_params.rs:28:24
--> tests/ui/attributes/data/invalid_params.rs:27:24
|
28 | #[sv::data(invalid)] _data: Option<Binary>,
27 | #[sv::data(invalid)] _data: Option<Binary>,
| ^^^^^^^

error: The `instantiate` cannot be used in pair with `raw` parameter.

= note: Use any combination of [`raw`, `opt`] or [`instantiate`, `opt`] pairs.

--> tests/ui/attributes/data/invalid_params.rs:57:24
--> tests/ui/attributes/data/invalid_params.rs:55:24
|
57 | #[sv::data(instantiate, raw)] _data: Option<Binary>,
55 | #[sv::data(instantiate, raw)] _data: Option<Binary>,
| ^^^^^^^^^^^
2 changes: 0 additions & 2 deletions sylvia/tests/ui/attributes/data/invalid_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub mod attributes_swapped {
pub struct Contract {}

#[sylvia::contract]
#[sv::features(replies)]
impl Contract {
pub const fn new() -> Self {
Self {}
Expand Down Expand Up @@ -37,7 +36,6 @@ pub mod error_handler {
pub struct Contract {}

#[sylvia::contract]
#[sv::features(replies)]
impl Contract {
pub const fn new() -> Self {
Self {}
Expand Down
12 changes: 6 additions & 6 deletions sylvia/tests/ui/attributes/data/invalid_usage.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ error: Wrong usage of `#[sv::data]` attribute.

= note: The `#[sv::data]` attribute can only be used on the first parameter after the `ReplyCtx`.

--> tests/ui/attributes/data/invalid_usage.rs:27:35
--> tests/ui/attributes/data/invalid_usage.rs:26:35
|
27 | #[sv::data(opt, raw)] _data: Option<Binary>,
26 | #[sv::data(opt, raw)] _data: Option<Binary>,
| ^^^^^

error: Redundant payload parameter.

= note: Expected no parameters after the parameter marked with `#[sv::payload(raw)]`.

--> tests/ui/attributes/data/invalid_usage.rs:27:35
--> tests/ui/attributes/data/invalid_usage.rs:26:35
|
27 | #[sv::data(opt, raw)] _data: Option<Binary>,
26 | #[sv::data(opt, raw)] _data: Option<Binary>,
| ^^^^^

error: Wrong usage of `#[sv::data]` attribute.

= note: The `#[sv::data]` attribute can only be used in `success` scenario.
= note: Found usage in `error` scenario.

--> tests/ui/attributes/data/invalid_usage.rs:55:35
--> tests/ui/attributes/data/invalid_usage.rs:53:35
|
55 | #[sv::data(opt, raw)] _data: Option<Binary>,
53 | #[sv::data(opt, raw)] _data: Option<Binary>,
| ^^^^^
2 changes: 1 addition & 1 deletion sylvia/tests/ui/attributes/features/invalid_params.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: Invalid feature.
= note: Supported features for contract macro: [`replies`].
= note: No features supported currently.
--> tests/ui/attributes/features/invalid_params.rs:9:16
|
9 | #[sv::features(unknown_parameter)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use sylvia::cw_std::{Reply, Response, StdResult};
pub struct Contract;

#[contract]
#[sv::features(replies)]
impl Contract {
pub fn new() -> Self {
Self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:31:32
--> tests/ui/attributes/msg/overlapping_reply_handlers.rs:30:32
|
31 | #[sv::msg(reply, handlers=[handler1], reply_on=success)]
30 | #[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:51:8
--> tests/ui/attributes/msg/overlapping_reply_handlers.rs:50:8
|
51 | fn handler2(
50 | fn handler2(
| ^^^^^^^^
Loading