Skip to content
Prev Previous commit
Next Next commit
Improved function docs
  • Loading branch information
ernestognw committed Jul 20, 2023
commit 9777b62972df08dfc1515cea53ecfeb66a53029e
16 changes: 16 additions & 0 deletions contracts/proxy/utils/Initializable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ abstract contract Initializable {
}
}

/**
* @dev Sets the initialized version.
*
* Requirements:
*
* - If the contract is initializing the version set must not be that of an reinitializer.
* - If the contract is not initializing the version must not be already set.
*/
function _setInitializedVersion(uint64 version) private returns (bool) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
Expand All @@ -204,6 +212,10 @@ abstract contract Initializable {
return !initializing;
}

/**
* @dev Runs before initialization.
* It sets the initialized version and sets the initializing flag to true.
*/
function _beforeInitialize(uint64 version) private returns (bool) {
bool isTopLevelCall = _setInitializedVersion(version);
if (isTopLevelCall) {
Expand All @@ -212,6 +224,10 @@ abstract contract Initializable {
return isTopLevelCall;
}

/**
* @dev Runs after initialization.
* It clears the initializing flag and emits an {Initialized} event if it is a top level call.
*/
function _afterInitialize(bool isTopLevelCall, uint64 version) private {
if (isTopLevelCall) {
_getInitializableStorage()._initializing = false;
Expand Down