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
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
33 changes: 29 additions & 4 deletions stylus-sdk/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,41 @@ pub fn pay_for_memory_grow(pages: u16) {
unsafe { hostio::pay_for_memory_grow(pages) }
}

/// Print the message to the console and revert, with revert data supplied by a call to `output`.
#[macro_export]
macro_rules! revert {
($($x:tt)*) => {
::stylus_sdk::console!($($x)*);
unsafe { ::stylus_sdk::evm::exit_early(1) };
}
}

/// Print the message to the console and exit successfully, with data supplied
/// by a call to `output`.
#[macro_export]
macro_rules! succeed {
($($x:tt)*) => {
::stylus_sdk::console!($($x)*);
unsafe { ::stylus_sdk::evm::exit_early(0) };
}
}

/// Not intended for end users.
#[inline]
pub fn exit_early(status: u32) {
unsafe { hostio::exit_early(status) }
}

wrap_hostio!(
/// Gets the amount of gas remaining. See [`Ink and Gas`] for more information on Stylus's compute pricing.
/// Gets the amount of gas remaining. See [`Gas and Ink`] for more information on Stylus's compute pricing.
///
/// [`Ink and Gas`]: https://developer.arbitrum.io/TODO
/// [`Gas and Ink`]: https://docs.arbitrum.io/stylus/concepts/stylus-gas
gas_left evm_gas_left u64
);

wrap_hostio!(
/// Gets the amount of ink remaining. See [`Ink and Gas`] for more information on Stylus's compute pricing.
/// Gets the amount of ink remaining. See [`Gas and Ink`] for more information on Stylus's compute pricing.
///
/// [`Ink and Gas`]: https://developer.arbitrum.io/TODO
/// [`Gas and Ink`]: https://docs.arbitrum.io/stylus/concepts/stylus-gas
ink_left evm_ink_left u64
);
5 changes: 5 additions & 0 deletions stylus-sdk/src/hostio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ extern "C" {
/// naturally when `user_entrypoint` returns.
pub fn write_result(data: *const u8, len: usize);

/// 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.
pub fn exit_early(status: u32) -> !;

/// Returns the length of the last EVM call or deployment return result, or `0` if neither have
/// happened during the program's execution. The semantics are equivalent to that of the EVM's
/// [`RETURN_DATA_SIZE`] opcode.
Expand Down
Loading