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: Better reply support (#418) #452

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open

feat: Better reply support (#418) #452

wants to merge 38 commits into from

Conversation

jawoznia
Copy link
Collaborator

@jawoznia jawoznia commented Nov 5, 2024

No description provided.

New optional parameters:
    - handlers - (handler1, handler2, ..)
    - reply_on - success|failure|always
Pass handlers bracketed instead of parenthesized
Remove redundancy between `MsgAttr` and `MsgType`
Since this change would be breaking it's hidden behind `sv_replies`
feature flag.
Remove `sv_replies` feature as it does not make the change non breaking.
Expect `(raw)` parameter in the `sv::payload` attribute.
Remove unnecessary `#[allow(deprecated)]` statements.
@jawoznia jawoznia linked an issue Nov 5, 2024 that may be closed by this pull request
12 tasks
Copy link

codecov bot commented Nov 5, 2024

Codecov Report

Attention: Patch coverage is 81.85185% with 147 lines in your changes missing coverage. Please review.

Project coverage is 72.37%. Comparing base (10e8eb9) to head (4f09075).

Files with missing lines Patch % Lines
sylvia-derive/src/contract/communication/reply.rs 90.41% 32 Missing ⚠️
sylvia/tests/reply_generation.rs 0.00% 14 Missing ⚠️
sylvia/src/builder/instantiate.rs 47.82% 12 Missing ⚠️
sylvia-derive/src/parser/attributes/msg.rs 78.43% 11 Missing ⚠️
sylvia/src/ctx.rs 35.29% 11 Missing ⚠️
sylvia-derive/src/parser/attributes/data.rs 62.96% 10 Missing ⚠️
sylvia-derive/src/entry_points.rs 0.00% 8 Missing ⚠️
sylvia-derive/src/parser/attributes/payload.rs 50.00% 8 Missing ⚠️
sylvia/tests/remote.rs 63.63% 8 Missing ⚠️
sylvia/tests/reply_dispatch.rs 91.35% 7 Missing ⚠️
... and 9 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #452      +/-   ##
==========================================
+ Coverage   70.08%   72.37%   +2.29%     
==========================================
  Files          53       63      +10     
  Lines        3085     3823     +738     
==========================================
+ Hits         2162     2767     +605     
- Misses        923     1056     +133     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@kulikthebird kulikthebird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replies are part of a mechanism that is not trivial for non-sylvia developers. Handling them in sylvia is a huge milestone for this crate and this should make it more useful for sylvia devs. That's a great work done and pretty complex issue solved here! Since the final PR combines all of the partial work checked already in other PRs, I'm not that worried about the details here. I left some clean-up related comments that we should consider before merging it to the main branch. Thank you for this implementation, well done!

sylvia/src/types.rs Outdated Show resolved Hide resolved
sylvia-derive/src/parser/attributes/data.rs Show resolved Hide resolved
sylvia/tests/ui/method_signature/reply.stderr Show resolved Hide resolved
sylvia/tests/reply_data.rs Show resolved Hide resolved
sylvia/tests/reply_data.rs Show resolved Hide resolved
.unwrap_err();
assert_eq!(
err,
StdError::generic_err("Invalid reply data: SW52YWxpZERhdGE=\nSerde error while deserializing Error parsing into type alloc::string::String: Invalid type").into()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that sylvia prints reply data. What would happen if the msg content size is for e.g. 1MB?

sylvia/tests/reply_dispatch.rs Show resolved Hide resolved
sylvia/tests/reply_data.rs Show resolved Hide resolved
@kulikthebird
Copy link
Contributor

Just one more question. What would happen if we implement such a reply:

#[sv::msg(reply, reply_on=success)]
    fn some_reply(
        &self,
        _ctx: ReplyCtx,
        #[sv::data] _data: ComplexData,
        #[sv::payload(raw)] _payload: Binary,
        some_custom_arg: String    // We provide sv::payload(raw) and a custom arg
    ) -> Result<Response, ContractError> {
        Ok(Response::new())
    }

@jawoznia
Copy link
Collaborator Author

jawoznia commented Nov 8, 2024

Just one more question. What would happen if we implement such a reply:

#[sv::msg(reply, reply_on=success)]
    fn some_reply(
        &self,
        _ctx: ReplyCtx,
        #[sv::data] _data: ComplexData,
        #[sv::payload(raw)] _payload: Binary,
        some_custom_arg: String    // We provide sv::payload(raw) and a custom arg
    ) -> Result<Response, ContractError> {
        Ok(Response::new())
    }

Good question. I haven't thought about that. I will check

This was potentially a breaking change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replies support
2 participants