Skip to content

Instantly share code, notes, and snippets.

@joaostein
Created October 31, 2022 09:17
Show Gist options
  • Save joaostein/9fb9d69d4bf5ced9b53f467f2dae0f5a to your computer and use it in GitHub Desktop.
Save joaostein/9fb9d69d4bf5ced9b53f467f2dae0f5a to your computer and use it in GitHub Desktop.
Simple `_status()` implementation using enum
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.17;
contract StatusExample {
enum Status {
Active,
Succeeded,
Failed,
Canceled
}
function example() public {
if (_status() != /* condition */) {
// ... do something;
}
}
/**
* @notice determine the project status
* @dev uses the `Status` enum to return the correct sate
* @return Project status
*/
function _status() private view returns (Status) {
if (/* condition 1 */) {
return Status.Canceled;
} else if (/* condition 2 */) {
return Status.Succeeded;
} else if (/* condition 3 */) {
return Status.Failed;
} else {
return Status.Active;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment