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

Allow Receive Fn to Return Error #186

Merged
merged 2 commits into from
Dec 20, 2024
Merged
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
2 changes: 1 addition & 1 deletion stylus-proc/src/macros/public/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl PublicImpl {
}

#[inline(always)]
fn receive(storage: &mut S) -> Option<()> {
fn receive(storage: &mut S) -> Option<Result<(), Vec<u8>>> {
#receive
}
}
Expand Down
6 changes: 3 additions & 3 deletions stylus-sdk/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ where
/// Receive functions are always payable, take in no inputs, and return no outputs.
/// If defined, they will always be called when a transaction does not send any
/// calldata, regardless of the transaction having a value attached.
fn receive(storage: &mut S) -> Option<()>;
fn receive(storage: &mut S) -> Option<Result<(), Vec<u8>>>;

/// Called when no receive function is defined.
/// If no #[fallback] function is defined in the contract, then any transactions that do not
Expand Down Expand Up @@ -105,8 +105,8 @@ where

if input.is_empty() {
console!("no calldata provided");
if R::receive(&mut storage).is_some() {
return Ok(Vec::new());
if let Some(res) = R::receive(&mut storage) {
rauljordan marked this conversation as resolved.
Show resolved Hide resolved
return res.map(|_| Vec::new());
}
// Try fallback function with no inputs if defined.
if let Some(res) = R::fallback(&mut storage, &[]) {
Expand Down
Loading