add Initializable
This commit is contained in:
42
contracts/Initializable.sol
Normal file
42
contracts/Initializable.sol
Normal file
@ -0,0 +1,42 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
|
||||
/**
|
||||
* @title Initializable
|
||||
*
|
||||
* @dev Helper contract to support initializer functions. To use it, replace
|
||||
* the constructor with a function that has the `initializer` modifier.
|
||||
* WARNING: Unlike constructors, initializer functions must be manually
|
||||
* invoked. This applies both to deploying an Initializable contract, as well
|
||||
* as extending an Initializable contract via inheritance.
|
||||
* WARNING: When used with inheritance, manual care must be taken to not invoke
|
||||
* a parent initializer twice, because this is not dealt with automatically as
|
||||
* with constructors.
|
||||
*/
|
||||
contract Initializable {
|
||||
|
||||
/**
|
||||
* @dev Indicates that the contract has been initialized.
|
||||
*/
|
||||
bool private initialized;
|
||||
|
||||
/**
|
||||
* @dev Indicates that the contract is in the process of being initialized.
|
||||
*/
|
||||
bool private initializing;
|
||||
|
||||
/**
|
||||
* @dev Modifier to use in the initializer function of a contract.
|
||||
*/
|
||||
modifier initializer() {
|
||||
require(initializing || !initialized, "Contract instance has already been initialized");
|
||||
|
||||
bool wasInitializing = initializing;
|
||||
initializing = true;
|
||||
initialized = true;
|
||||
|
||||
_;
|
||||
|
||||
initializing = wasInitializing;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user