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

exit_early #114

Open
wants to merge 1 commit into
base: testnet-2
Choose a base branch
from
Open

exit_early #114

wants to merge 1 commit into from

Conversation

mikebenfield
Copy link

@mikebenfield mikebenfield commented Mar 12, 2024

Parent PR: OffchainLabs/stylus#208
Associated PR: OffchainLabs/stylus-sdk-c#18
Stylus update PR: OffchainLabs/stylus#210

Closes STY-39

stylus-sdk/src/hostio.rs Outdated Show resolved Hide resolved
Comment on lines 60 to 83
/// Exits program execution early with the given status code.
/// If `0`, the program returns successfully with any data supplied by `write_result`.
/// Otherwise, the program reverts and treats any `write_result` data as revert data.
#[inline]
pub fn exit_early(status: u32) {
unsafe { hostio::exit_early(status) }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of exposing this as-is to users, let's add a revert! macro that expands to a console!, write_result and early_exit(). Also let's go through the SDK and find places where we can replace panics with it.

We'll also want an affordance for the success case, which should ideally take an arguement for the return data.

Copy link
Author

@mikebenfield mikebenfield Mar 12, 2024

Choose a reason for hiding this comment

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

I added this macro. Note that exit_early does need to still be public so that it can be called by the expanded macro. I also added a similar succeed macro.

Currently the macro does not call write_result - it seemed awkward to me that the macro would receive both a result slice for revert data and a message to print. The user can first call output. However, if you do prefer the macro handle both (presumably just called as revert!(slice_data, "Some console message"), let me know and I'll make that 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.

3 participants