Skip to content

Commit

Permalink
allow receive fn to return err
Browse files Browse the repository at this point in the history
  • Loading branch information
rauljordan committed Dec 20, 2024
1 parent e43a28a commit b23e212
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
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
7 changes: 5 additions & 2 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,7 +105,10 @@ where

if input.is_empty() {
console!("no calldata provided");
if R::receive(&mut storage).is_some() {
if let Some(res) = R::receive(&mut storage) {
if let Err(e) = res {
return Err(e);
}

Check warning on line 111 in stylus-sdk/src/abi/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this block may be rewritten with the `?` operator

warning: this block may be rewritten with the `?` operator --> stylus-sdk/src/abi/mod.rs:109:13 | 109 | / if let Err(e) = res { 110 | | return Err(e); 111 | | } | |_____________^ help: replace it with: `res?;` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark = note: `#[warn(clippy::question_mark)]` on by default
return Ok(Vec::new());
}
// Try fallback function with no inputs if defined.
Expand Down

0 comments on commit b23e212

Please sign in to comment.