Skip to content

feat: Introduce macros for generating dispatching func, inputs and outputs#1

Closed
DennisInSky wants to merge 6 commits into
masterfrom
dd/introduce-handler-macros
Closed

feat: Introduce macros for generating dispatching func, inputs and outputs#1
DennisInSky wants to merge 6 commits into
masterfrom
dd/introduce-handler-macros

Conversation

@DennisInSky
Copy link
Copy Markdown
Contributor

Introduces command_handlers and query_handlers attributes for modules implementing some handlers. Any standalone function of the module regardless of the function visibility is considered to be a handler. Based on the functions signature, the macro generates 2 enums: one for input params, another for output ones, and a function which takes an input enum variant as a param, dispatches it to one of the defined handlers, and returns an output enum variant as a result with indication whether the call was successful or not.

@DennisInSky DennisInSky self-assigned this Nov 8, 2023
gsys::gr_panic(result.as_ptr(), result.len() as u32);
}
}
msg::reply(result, 0).expect("This needs to be handled in a consistent way: reply error");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why 0 gas ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is not gas, but value. As far as I get transferring value from a contract is not used

@NikVolf
Copy link
Copy Markdown
Member

NikVolf commented Nov 10, 2023

Async example right away would be nice

// That
fn do_that(
param: DoThatParam,
) -> Result<(String, u32), (String,) /* IDEA can't handle meta with single element tuple */>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do you need here single element tuple anyway?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is just as many possible type usages as I could imagine.

@DennisInSky
Copy link
Copy Markdown
Contributor Author

Async example right away would be nice

Do we want to generate async version of handle_commands all the time regardless of whether there are async handlers or not?

@DennisInSky DennisInSky requested a review from NikVolf November 16, 2023 12:40
Copy link
Copy Markdown

@shamilsan shamilsan left a comment

Choose a reason for hiding this comment

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

It looks good to me as a starting point.

Comment thread examples/this-that/wasm/src/lib.rs Outdated
Comment thread macros/core/src/lib.rs
Comment thread Cargo.toml Outdated
@DennisInSky
Copy link
Copy Markdown
Contributor Author

@NikVolf , @breathx any feedback, approves from you guys?

@DennisInSky
Copy link
Copy Markdown
Contributor Author

It will be merged in via a child branch

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.

3 participants