Commit 6e0ace19 by Francisco Giordano

make initializer modifier check if running in constructor

parent 5b8d5eb5
...@@ -29,7 +29,7 @@ contract Initializable { ...@@ -29,7 +29,7 @@ contract Initializable {
* @dev Modifier to use in the initializer function of a contract. * @dev Modifier to use in the initializer function of a contract.
*/ */
modifier initializer() { modifier initializer() {
require(initializing || !initialized, "Contract instance has already been initialized"); require(initializing || isConstructor() || !initialized, "Contract instance has already been initialized");
bool wasInitializing = initializing; bool wasInitializing = initializing;
initializing = true; initializing = true;
...@@ -39,4 +39,11 @@ contract Initializable { ...@@ -39,4 +39,11 @@ contract Initializable {
initializing = wasInitializing; initializing = wasInitializing;
} }
/// @dev Returns true if and only if the function is running in the constructor
function isConstructor() private view returns (bool) {
uint cs;
assembly { cs := extcodesize(address) }
return cs == 0;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment