Created
October 31, 2022 09:17
-
-
Save joaostein/9fb9d69d4bf5ced9b53f467f2dae0f5a to your computer and use it in GitHub Desktop.
Simple `_status()` implementation using enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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