UNPKG

@openzeppelin/upgrades

Version:

JavaScript library for the OpenZeppelin smart contract platform

906 lines (905 loc) 37.9 kB
{ "fileName": "Initializable.sol", "contractName": "Initializable", "source": "pragma solidity >=0.4.24 <0.7.0;\n\n\n/**\n * @title Initializable\n *\n * @dev Helper contract to support initializer functions. To use it, replace\n * the constructor with a function that has the `initializer` modifier.\n * WARNING: Unlike constructors, initializer functions must be manually\n * invoked. This applies both to deploying an Initializable contract, as well\n * as extending an Initializable contract via inheritance.\n * WARNING: When used with inheritance, manual care must be taken to not invoke\n * a parent initializer twice, or ensure that all initializers are idempotent,\n * because this is not dealt with automatically as with constructors.\n */\ncontract Initializable {\n\n /**\n * @dev Indicates that the contract has been initialized.\n */\n bool private initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private initializing;\n\n /**\n * @dev Modifier to use in the initializer function of a contract.\n */\n modifier initializer() {\n require(initializing || isConstructor() || !initialized, \"Contract instance has already been initialized\");\n\n bool isTopLevelCall = !initializing;\n if (isTopLevelCall) {\n initializing = true;\n initialized = true;\n }\n\n _;\n\n if (isTopLevelCall) {\n initializing = false;\n }\n }\n\n /// @dev Returns true if and only if the function is running in the constructor\n function isConstructor() private view returns (bool) {\n // extcodesize checks the size of the code stored in an address, and\n // address returns the current address. Since the code is still not\n // deployed when running a constructor, any checks on its code size will\n // yield zero, making it an effective way to detect if a contract is\n // under construction or not.\n address self = address(this);\n uint256 cs;\n assembly { cs := extcodesize(self) }\n return cs == 0;\n }\n\n // Reserved storage space to allow for layout changes in the future.\n uint256[50] private ______gap;\n}\n", "sourcePath": "contracts/Initializable.sol", "sourceMap": "657:1357:0:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;657:1357:0;;;;;;;", "deployedSourceMap": "657:1357:0:-;;;;;", "abi": [], "ast": { "absolutePath": "contracts/Initializable.sol", "exportedSymbols": { "Initializable": [ 68 ] }, "id": 69, "nodeType": "SourceUnit", "nodes": [ { "id": 1, "literals": [ "solidity", ">=", "0.4", ".24", "<", "0.7", ".0" ], "nodeType": "PragmaDirective", "src": "0:32:0" }, { "baseContracts": [], "contractDependencies": [], "contractKind": "contract", "documentation": "@title Initializable\n * @dev Helper contract to support initializer functions. To use it, replace\nthe constructor with a function that has the `initializer` modifier.\nWARNING: Unlike constructors, initializer functions must be manually\ninvoked. This applies both to deploying an Initializable contract, as well\nas extending an Initializable contract via inheritance.\nWARNING: When used with inheritance, manual care must be taken to not invoke\na parent initializer twice, or ensure that all initializers are idempotent,\nbecause this is not dealt with automatically as with constructors.", "fullyImplemented": true, "id": 68, "linearizedBaseContracts": [ 68 ], "name": "Initializable", "nodeType": "ContractDefinition", "nodes": [ { "constant": false, "id": 3, "name": "initialized", "nodeType": "VariableDeclaration", "scope": 68, "src": "757:24:0", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "typeName": { "id": 2, "name": "bool", "nodeType": "ElementaryTypeName", "src": "757:4:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "value": null, "visibility": "private" }, { "constant": false, "id": 5, "name": "initializing", "nodeType": "VariableDeclaration", "scope": 68, "src": "876:25:0", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "typeName": { "id": 4, "name": "bool", "nodeType": "ElementaryTypeName", "src": "876:4:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "value": null, "visibility": "private" }, { "body": { "id": 42, "nodeType": "Block", "src": "1010:313:0", "statements": [ { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "commonType": { "typeIdentifier": "t_bool", "typeString": "bool" }, "id": 14, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_bool", "typeString": "bool" }, "id": 11, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 8, "name": "initializing", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5, "src": "1024:12:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "BinaryOperation", "operator": "||", "rightExpression": { "argumentTypes": null, "arguments": [], "expression": { "argumentTypes": [], "id": 9, "name": "isConstructor", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 63, "src": "1040:13:0", "typeDescriptions": { "typeIdentifier": "t_function_internal_view$__$returns$_t_bool_$", "typeString": "function () view returns (bool)" } }, "id": 10, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1040:15:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "src": "1024:31:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "BinaryOperation", "operator": "||", "rightExpression": { "argumentTypes": null, "id": 13, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "nodeType": "UnaryOperation", "operator": "!", "prefix": true, "src": "1059:12:0", "subExpression": { "argumentTypes": null, "id": 12, "name": "initialized", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3, "src": "1060:11:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "src": "1024:47:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, { "argumentTypes": null, "hexValue": "436f6e747261637420696e7374616e63652068617320616c7265616479206265656e20696e697469616c697a6564", "id": 15, "isConstant": false, "isLValue": false, "isPure": true, "kind": "string", "lValueRequested": false, "nodeType": "Literal", "src": "1073:48:0", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_stringliteral_9fbba6c4dcac9134893b633b9564f36435b3f927c1d5fa152c5c14b20cecb1a4", "typeString": "literal_string \"Contract instance has already been initialized\"" }, "value": "Contract instance has already been initialized" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_bool", "typeString": "bool" }, { "typeIdentifier": "t_stringliteral_9fbba6c4dcac9134893b633b9564f36435b3f927c1d5fa152c5c14b20cecb1a4", "typeString": "literal_string \"Contract instance has already been initialized\"" } ], "id": 7, "name": "require", "nodeType": "Identifier", "overloadedDeclarations": [ 6466, 6467 ], "referencedDeclaration": 6467, "src": "1016:7:0", "typeDescriptions": { "typeIdentifier": "t_function_require_pure$_t_bool_$_t_string_memory_ptr_$returns$__$", "typeString": "function (bool,string memory) pure" } }, "id": 16, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1016:106:0", "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 17, "nodeType": "ExpressionStatement", "src": "1016:106:0" }, { "assignments": [ 19 ], "declarations": [ { "constant": false, "id": 19, "name": "isTopLevelCall", "nodeType": "VariableDeclaration", "scope": 42, "src": "1129:19:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "typeName": { "id": 18, "name": "bool", "nodeType": "ElementaryTypeName", "src": "1129:4:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "value": null, "visibility": "internal" } ], "id": 22, "initialValue": { "argumentTypes": null, "id": 21, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "nodeType": "UnaryOperation", "operator": "!", "prefix": true, "src": "1151:13:0", "subExpression": { "argumentTypes": null, "id": 20, "name": "initializing", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5, "src": "1152:12:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "VariableDeclarationStatement", "src": "1129:35:0" }, { "condition": { "argumentTypes": null, "id": 23, "name": "isTopLevelCall", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 19, "src": "1174:14:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseBody": null, "id": 33, "nodeType": "IfStatement", "src": "1170:80:0", "trueBody": { "id": 32, "nodeType": "Block", "src": "1190:60:0", "statements": [ { "expression": { "argumentTypes": null, "id": 26, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 24, "name": "initializing", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5, "src": "1198:12:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "hexValue": "74727565", "id": 25, "isConstant": false, "isLValue": false, "isPure": true, "kind": "bool", "lValueRequested": false, "nodeType": "Literal", "src": "1213:4:0", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "value": "true" }, "src": "1198:19:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "id": 27, "nodeType": "ExpressionStatement", "src": "1198:19:0" }, { "expression": { "argumentTypes": null, "id": 30, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 28, "name": "initialized", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3, "src": "1225:11:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "hexValue": "74727565", "id": 29, "isConstant": false, "isLValue": false, "isPure": true, "kind": "bool", "lValueRequested": false, "nodeType": "Literal", "src": "1239:4:0", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "value": "true" }, "src": "1225:18:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "id": 31, "nodeType": "ExpressionStatement", "src": "1225:18:0" } ] } }, { "id": 34, "nodeType": "PlaceholderStatement", "src": "1256:1:0" }, { "condition": { "argumentTypes": null, "id": 35, "name": "isTopLevelCall", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 19, "src": "1268:14:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseBody": null, "id": 41, "nodeType": "IfStatement", "src": "1264:55:0", "trueBody": { "id": 40, "nodeType": "Block", "src": "1284:35:0", "statements": [ { "expression": { "argumentTypes": null, "id": 38, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 36, "name": "initializing", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5, "src": "1292:12:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "hexValue": "66616c7365", "id": 37, "isConstant": false, "isLValue": false, "isPure": true, "kind": "bool", "lValueRequested": false, "nodeType": "Literal", "src": "1307:5:0", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "value": "false" }, "src": "1292:20:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "id": 39, "nodeType": "ExpressionStatement", "src": "1292:20:0" } ] } } ] }, "documentation": "@dev Modifier to use in the initializer function of a contract.", "id": 43, "name": "initializer", "nodeType": "ModifierDefinition", "parameters": { "id": 6, "nodeType": "ParameterList", "parameters": [], "src": "1007:2:0" }, "src": "987:336:0", "visibility": "internal" }, { "body": { "id": 62, "nodeType": "Block", "src": "1462:445:0", "statements": [ { "assignments": [ 49 ], "declarations": [ { "constant": false, "id": 49, "name": "self", "nodeType": "VariableDeclaration", "scope": 62, "src": "1797:12:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 48, "name": "address", "nodeType": "ElementaryTypeName", "src": "1797:7:0", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "id": 53, "initialValue": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 51, "name": "this", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6477, "src": "1820:4:0", "typeDescriptions": { "typeIdentifier": "t_contract$_Initializable_$68", "typeString": "contract Initializable" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_contract$_Initializable_$68", "typeString": "contract Initializable" } ], "id": 50, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "nodeType": "ElementaryTypeNameExpression", "src": "1812:7:0", "typeDescriptions": { "typeIdentifier": "t_type$_t_address_$", "typeString": "type(address)" }, "typeName": "address" }, "id": 52, "isConstant": false, "isLValue": false, "isPure": false, "kind": "typeConversion", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1812:13:0", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "nodeType": "VariableDeclarationStatement", "src": "1797:28:0" }, { "assignments": [ 55 ], "declarations": [ { "constant": false, "id": 55, "name": "cs", "nodeType": "VariableDeclaration", "scope": 62, "src": "1831:10:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 54, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1831:7:0", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "id": 56, "initialValue": null, "nodeType": "VariableDeclarationStatement", "src": "1831:10:0" }, { "externalReferences": [ { "cs": { "declaration": 55, "isOffset": false, "isSlot": false, "src": "1858:2:0", "valueSize": 1 } }, { "self": { "declaration": 49, "isOffset": false, "isSlot": false, "src": "1876:4:0", "valueSize": 1 } } ], "id": 57, "nodeType": "InlineAssembly", "operations": "{\n cs := extcodesize(self)\n}", "src": "1847:47:0" }, { "expression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 60, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 58, "name": "cs", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 55, "src": "1895:2:0", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "==", "rightExpression": { "argumentTypes": null, "hexValue": "30", "id": 59, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1901:1:0", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" }, "value": "0" }, "src": "1895:7:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "functionReturnParameters": 47, "id": 61, "nodeType": "Return", "src": "1888:14:0" } ] }, "documentation": "@dev Returns true if and only if the function is running in the constructor", "id": 63, "implemented": true, "kind": "function", "modifiers": [], "name": "isConstructor", "nodeType": "FunctionDefinition", "parameters": { "id": 44, "nodeType": "ParameterList", "parameters": [], "src": "1431:2:0" }, "returnParameters": { "id": 47, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 46, "name": "", "nodeType": "VariableDeclaration", "scope": 63, "src": "1456:4:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "typeName": { "id": 45, "name": "bool", "nodeType": "ElementaryTypeName", "src": "1456:4:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "value": null, "visibility": "internal" } ], "src": "1455:6:0" }, "scope": 68, "src": "1409:498:0", "stateMutability": "view", "superFunction": null, "visibility": "private" }, { "constant": false, "id": 67, "name": "______gap", "nodeType": "VariableDeclaration", "scope": 68, "src": "1982:29:0", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_array$_t_uint256_$50_storage", "typeString": "uint256[50]" }, "typeName": { "baseType": { "id": 64, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1982:7:0", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 66, "length": { "argumentTypes": null, "hexValue": "3530", "id": 65, "isConstant": false, "isLValue": false, "isPure": false, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1990:2:0", "subdenomination": null, "typeDescriptions": { "typeIdentifier": null, "typeString": null }, "value": "50" }, "nodeType": "ArrayTypeName", "src": "1982:11:0", "typeDescriptions": { "typeIdentifier": "t_array$_t_uint256_$50_storage_ptr", "typeString": "uint256[50]" } }, "value": null, "visibility": "private" } ], "scope": 69, "src": "657:1357:0" } ], "src": "0:2015:0" }, "bytecode": "0x6080604052348015600f57600080fd5b50603580601d6000396000f3fe6080604052600080fdfea165627a7a72305820c29a3aab25ebc1cdb31c10a7e4dc61bbdac7bb067105441516aae3e31b1d84e70029", "deployedBytecode": "0x6080604052600080fdfea165627a7a72305820c29a3aab25ebc1cdb31c10a7e4dc61bbdac7bb067105441516aae3e31b1d84e70029", "compiler": { "name": "solc", "version": "0.5.3+commit.10d17f24.Emscripten.clang", "optimizer": {}, "evmVersion": "constantinople" } }