Commit 6e0ace19 by Francisco Giordano

make initializer modifier check if running in constructor

parent 5b8d5eb5
......@@ -29,7 +29,7 @@ contract Initializable {
* @dev Modifier to use in the initializer function of a contract.
*/
modifier initializer() {
require(initializing || !initialized, "Contract instance has already been initialized");
require(initializing || isConstructor() || !initialized, "Contract instance has already been initialized");
bool wasInitializing = initializing;
initializing = true;
......@@ -39,4 +39,11 @@ contract Initializable {
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