Skip to content

Commit

Permalink
exit_early
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Benfield committed Mar 12, 2024
1 parent 290326c commit 1eee40d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions stylus-sdk/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ pub fn pay_for_memory_grow(pages: u16) {
unsafe { hostio::memory_grow(pages) }
}

/// 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) }
}

wrap_hostio!(
/// Gets the amount of gas remaining. See [`Ink and Gas`] for more information on Stylus's compute pricing.
///
Expand Down
5 changes: 5 additions & 0 deletions stylus-sdk/src/hostio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,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

0 comments on commit 1eee40d

Please sign in to comment.