Skip to content

Commit

Permalink
More after review corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
hashedone committed May 24, 2023
1 parent cf90c07 commit 2c936a2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## \[0.4.2] - Unreleased

- Added support of `#[msg(reply)]` defininfg handler for reply messages,
currently only in the form of
`fn reply(&self, _ctx: ReplyCtx, _msg: Reply) -> Result<Response, Err>`
- Added generation of reply entrypoint forwarding to the `#[msg(reply)]`
handler
- Added generation of reply implementation forwarding to `#[msg(reply)]`
handler

## \[0.4.1\] - 2023-05-23

- Lint fix
Expand Down
30 changes: 7 additions & 23 deletions sylvia-derive/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::parser::{
};
use crate::strip_generics::StripGenerics;
use crate::utils::{extract_return_type, filter_wheres, process_fields};
use crate::variant_descs::VariantDescs;
use crate::variant_descs::{AsVariantDescs, VariantDescs};
use convert_case::{Case, Casing};
use proc_macro2::{Span, TokenStream};
use proc_macro_error::emit_error;
Expand Down Expand Up @@ -1029,28 +1029,12 @@ impl EntryPoints {
)
.unwrap_or_else(|| parse_quote! { #sylvia ::cw_std::StdError });

let reply = source
.items
.iter()
.filter_map(|item| match item {
ImplItem::Method(method) => Some(method),
_ => None,
})
.find(|method| {
method.attrs.iter().any(|attr| {
if !attr.path.is_ident("msg") {
return false;
}

let attr = match MsgAttr::parse.parse2(attr.tokens.clone()) {
Ok(attr) => attr,
Err(_) => return false,
};

attr == MsgType::Reply
})
})
.map(|method| method.sig.ident.clone());
let generics: Vec<_> = source.generics.params.iter().collect();
let reply = MsgVariants::new(source.as_variants(), &generics)

Check warning on line 1033 in sylvia-derive/src/message.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/message.rs#L1032-L1033

Added lines #L1032 - L1033 were not covered by tests
.0
.into_iter()
.find(|variant| variant.msg_type == MsgType::Reply)
.map(|variant| variant.function_name.clone());

Check warning on line 1037 in sylvia-derive/src/message.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/message.rs#L1036-L1037

Added lines #L1036 - L1037 were not covered by tests

Self { name, error, reply }
}
Expand Down
2 changes: 1 addition & 1 deletion sylvia/tests/replies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod noop_contract {

use sylvia::cw_std::{Response, StdResult};

struct NoopContract;
pub struct NoopContract;

#[cfg(not(tarpaulin_include))]
#[contract]
Expand Down

0 comments on commit 2c936a2

Please sign in to comment.