Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove sv_replies feature as it does not prevent semver breaking #444

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ version = "0.5.0"
edition = "2021"

[workspace.dependencies]
sylvia = { path = "../sylvia", features = ["sv_replies"] }
sylvia = { path = "../sylvia" }
cw-storage-plus = "2.0.0"
cw-utils = "2.0.0"
cw2 = "2.0.0"
Expand Down
2 changes: 0 additions & 2 deletions sylvia-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ readme = "../README.md"
[features]
mt = []
cosmwasm_1_2 = []
sv_replies = []

[lib]
proc-macro = true
Expand Down Expand Up @@ -43,7 +42,6 @@ sylvia = { path = "../sylvia", features = [
"cosmwasm_1_2",
"cosmwasm_1_3",
"cosmwasm_1_4",
"sv_replies",
] }
serde = { workspace = true }
cosmwasm-schema = { workspace = true }
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 @@ -186,13 +186,9 @@ impl<'a> ContractInput<'a> {
}

fn emit_reply(&self) -> TokenStream {
if cfg!(feature = "sv_replies") {
let variants = MsgVariants::new(self.item.as_variants(), MsgType::Reply, &[], &None);
let variants = MsgVariants::new(self.item.as_variants(), MsgType::Reply, &[], &None);

Reply::new(self.item, &self.generics, &variants).emit()
} else {
quote! {}
}
Reply::new(self.item, &self.generics, &variants).emit()
}

fn emit_instantiate_builder_trait(&self) -> TokenStream {
Expand Down
13 changes: 3 additions & 10 deletions sylvia-derive/src/contract/mt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,16 +529,9 @@
quote! { #contract_ident }
};

if cfg!(feature = "sv_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 534 in sylvia-derive/src/contract/mt.rs

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L532 - L534 were not covered by tests
}
})
.unwrap_or_else(|| {
Expand Down
26 changes: 10 additions & 16 deletions sylvia-derive/src/entry_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use proc_macro_error::emit_error;
use quote::quote;
use syn::fold::Fold;
use syn::{parse_quote, GenericParam, Ident, ItemImpl, Type, WhereClause};
use syn::{parse_quote, GenericParam, ItemImpl, Type, WhereClause};

use crate::crate_module;
use crate::fold::StripGenerics;
Expand Down Expand Up @@ -63,7 +63,7 @@
source: &'a ItemImpl,
name: Type,
error: Type,
reply: Option<Ident>,
is_reply: bool,
override_entry_points: Vec<OverrideEntryPoint>,
generics: Vec<&'a GenericParam>,
where_clause: &'a Option<WhereClause>,
Expand All @@ -81,17 +81,18 @@
let generics: Vec<_> = source.generics.params.iter().collect();
let where_clause = &source.generics.where_clause;

let reply =
let is_reply =

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

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/entry_points.rs#L84

Added line #L84 was not covered by tests
MsgVariants::<GenericParam>::new(source.as_variants(), MsgType::Reply, &[], &None)
.variants()
.map(|variant| variant.function_name().clone())
.next();
.next()
.is_some();

Self {
source,
name,
error,
reply,
is_reply,
override_entry_points,
generics,
where_clause,
Expand All @@ -102,7 +103,7 @@
pub fn emit(&self) -> TokenStream {
let Self {
source,
reply,
is_reply,

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

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/entry_points.rs#L106

Added line #L106 was not covered by tests
override_entry_points,
generics,
where_clause,
Expand Down Expand Up @@ -146,7 +147,7 @@
.get_entry_point(MsgType::Reply)
.map(|_| quote! {})
.unwrap_or_else(|| {
if reply.is_some() {
if *is_reply {

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

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/entry_points.rs#L150

Added line #L150 was not covered by tests
self.emit_default_entry_point(MsgType::Reply)
} else {
quote! {}
Expand All @@ -168,11 +169,7 @@

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

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

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/entry_points.rs#L172

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

Expand Down Expand Up @@ -201,13 +198,10 @@
_ => quote! { msg: < #contract as #sylvia ::types::ContractApi> :: #associated_name },
};
let dispatch = match msg_ty {
MsgType::Reply if cfg!(feature = "sv_replies") => quote! {
MsgType::Reply => quote! {

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

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/entry_points.rs#L201

Added line #L201 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
2 changes: 0 additions & 2 deletions sylvia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ cosmwasm_2_0 = [
"cw-multi-test/cosmwasm_2_0",
"cosmwasm_1_4",
]
# Enables better replies
sv_replies = ["sylvia-derive/sv_replies"]

[dependencies]
sylvia-derive = { workspace = true }
Expand Down
22 changes: 3 additions & 19 deletions sylvia/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Module providing utilities to build and use sylvia contracts.

use cosmwasm_std::{Binary, Coin, Deps, DepsMut, Empty, Env, MessageInfo, WasmMsg};
#[cfg(feature = "sv_replies")]
use cosmwasm_std::{Event, MsgResponse};
use cosmwasm_std::{
Binary, Coin, Deps, DepsMut, Empty, Env, Event, MessageInfo, MsgResponse, WasmMsg,
};
use derivative::Derivative;
use schemars::JsonSchema;
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -461,7 +461,6 @@ impl<'a, Contract: ?Sized> AsRef<cosmwasm_std::Addr> for Remote<'a, Contract> {
}

/// Represantation of `reply` context received in entry point.
#[cfg(feature = "sv_replies")]
pub struct ReplyCtx<'a, C: cosmwasm_std::CustomQuery = Empty> {
pub deps: DepsMut<'a, C>,
pub env: Env,
Expand All @@ -470,13 +469,6 @@ pub struct ReplyCtx<'a, C: cosmwasm_std::CustomQuery = Empty> {
pub msg_responses: Vec<MsgResponse>,
}

/// Represantation of `reply` context received in entry point.
#[cfg(not(feature = "sv_replies"))]
pub struct ReplyCtx<'a, C: cosmwasm_std::CustomQuery = Empty> {
pub deps: DepsMut<'a, C>,
pub env: Env,
}

/// Represantation of `migrate` context received in entry point.
pub struct MigrateCtx<'a, C: cosmwasm_std::CustomQuery = Empty> {
pub deps: DepsMut<'a, C>,
Expand Down Expand Up @@ -544,7 +536,6 @@ impl<'a, C: cosmwasm_std::CustomQuery> From<(DepsMut<'a, C>, Env)> for MigrateCt
}
}

#[cfg(feature = "sv_replies")]
impl<'a, C: cosmwasm_std::CustomQuery>
From<(DepsMut<'a, C>, Env, u64, Vec<Event>, Vec<MsgResponse>)> for ReplyCtx<'a, C>
{
Expand All @@ -567,13 +558,6 @@ impl<'a, C: cosmwasm_std::CustomQuery>
}
}

#[cfg(not(feature = "sv_replies"))]
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 }
}
}

impl<'a, C: cosmwasm_std::CustomQuery> From<(DepsMut<'a, C>, Env, MessageInfo)> for ExecCtx<'a, C> {
fn from((deps, env, info): (DepsMut<'a, C>, Env, MessageInfo)) -> Self {
Self { deps, env, info }
Expand Down
125 changes: 0 additions & 125 deletions sylvia/tests/legacy_replies.rs

This file was deleted.

10 changes: 7 additions & 3 deletions sylvia/tests/messages_generation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg(not(feature = "sv_replies"))]
use std::fmt::Debug;
use std::str::FromStr;

Expand Down Expand Up @@ -68,7 +67,7 @@
mod contract {
use cosmwasm_std::{Binary, SubMsgResult};
use sylvia::contract;
use sylvia::cw_std::{Addr, Reply, Response, StdResult};
use sylvia::cw_std::{Addr, Response, StdResult};
use sylvia::types::{ExecCtx, InstantiateCtx, MigrateCtx, QueryCtx, ReplyCtx, SudoCtx};
use sylvia_derive::entry_points;
use thiserror::Error;
Expand Down Expand Up @@ -149,7 +148,12 @@
}

#[sv::msg(reply)]
fn my_reply(&self, _ctx: ReplyCtx<MyQuery>, _reply: Reply) -> StdResult<Response> {
fn my_reply(

Check warning on line 151 in sylvia/tests/messages_generation.rs

View check run for this annotation

Codecov / codecov/patch

sylvia/tests/messages_generation.rs#L151

Added line #L151 was not covered by tests
&self,
_ctx: ReplyCtx<MyQuery>,
_result: SubMsgResult,
#[sv::payload] _payload: Binary,
) -> StdResult<Response> {
Ok(Response::new())
}

Expand Down
2 changes: 0 additions & 2 deletions sylvia/tests/reply.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(feature = "sv_replies")]

use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_json_binary, BankMsg, CosmosMsg, Empty, SubMsgResult};
use cw_storage_plus::Item;
Expand Down
Loading
Loading