Skip to content

Commit

Permalink
Merge pull request #186 from OffchainLabs/allow-receive-return-err
Browse files Browse the repository at this point in the history
Allow Receive Fn to Return Error
  • Loading branch information
rauljordan authored Dec 20, 2024
2 parents e43a28a + 8672aac commit e6dad17
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 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
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) {
return res.map(|_| Vec::new());
}
// Try fallback function with no inputs if defined.
if let Some(res) = R::fallback(&mut storage, &[]) {
Expand Down

0 comments on commit e6dad17

Please sign in to comment.