UNPKG

@openzeppelin/upgrades

Version:

JavaScript library for the OpenZeppelin smart contract platform

437 lines (436 loc) 17.8 kB
{ "fileName": "Proxy.sol", "contractName": "Proxy", "source": "pragma solidity ^0.5.0;\n\n/**\n * @title Proxy\n * @dev Implements delegation of calls to other contracts, with proper\n * forwarding of return values and bubbling of failures.\n * It defines a fallback function that delegates all calls to the address\n * returned by the abstract _implementation() internal function.\n */\ncontract Proxy {\n /**\n * @dev Fallback function.\n * Implemented entirely in `_fallback`.\n */\n function () payable external {\n _fallback();\n }\n\n /**\n * @return The Address of the implementation.\n */\n function _implementation() internal view returns (address);\n\n /**\n * @dev Delegates execution to an implementation contract.\n * This is a low level function that doesn't return to its internal call site.\n * It will return to the external caller whatever the implementation returns.\n * @param implementation Address to delegate.\n */\n function _delegate(address implementation) internal {\n assembly {\n // Copy msg.data. We take full control of memory in this inline assembly\n // block because it will not return to Solidity code. We overwrite the\n // Solidity scratch pad at memory position 0.\n calldatacopy(0, 0, calldatasize)\n\n // Call the implementation.\n // out and outsize are 0 because we don't know the size yet.\n let result := delegatecall(gas, implementation, 0, calldatasize, 0, 0)\n\n // Copy the returned data.\n returndatacopy(0, 0, returndatasize)\n\n switch result\n // delegatecall returns 0 on error.\n case 0 { revert(0, returndatasize) }\n default { return(0, returndatasize) }\n }\n }\n\n /**\n * @dev Function that is run as the first thing in the fallback function.\n * Can be redefined in derived contracts to add functionality.\n * Redefinitions must call super._willFallback().\n */\n function _willFallback() internal {\n }\n\n /**\n * @dev fallback implementation.\n * Extracted to enable manual triggering.\n */\n function _fallback() internal {\n _willFallback();\n _delegate(_implementation());\n }\n}\n", "sourcePath": "contracts/upgradeability/Proxy.sol", "sourceMap": "", "deployedSourceMap": "", "abi": [ { "payable": true, "stateMutability": "payable", "type": "fallback" } ], "ast": { "absolutePath": "contracts/upgradeability/Proxy.sol", "exportedSymbols": { "Proxy": [ 5896 ] }, "id": 5897, "nodeType": "SourceUnit", "nodes": [ { "id": 5860, "literals": [ "solidity", "^", "0.5", ".0" ], "nodeType": "PragmaDirective", "src": "0:23:39" }, { "baseContracts": [], "contractDependencies": [], "contractKind": "contract", "documentation": "@title Proxy\n@dev Implements delegation of calls to other contracts, with proper\nforwarding of return values and bubbling of failures.\nIt defines a fallback function that delegates all calls to the address\nreturned by the abstract _implementation() internal function.", "fullyImplemented": false, "id": 5896, "linearizedBaseContracts": [ 5896 ], "name": "Proxy", "nodeType": "ContractDefinition", "nodes": [ { "body": { "id": 5866, "nodeType": "Block", "src": "447:22:39", "statements": [ { "expression": { "argumentTypes": null, "arguments": [], "expression": { "argumentTypes": [], "id": 5863, "name": "_fallback", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5895, "src": "453:9:39", "typeDescriptions": { "typeIdentifier": "t_function_internal_nonpayable$__$returns$__$", "typeString": "function ()" } }, "id": 5864, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "453:11:39", "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 5865, "nodeType": "ExpressionStatement", "src": "453:11:39" } ] }, "documentation": "@dev Fallback function.\nImplemented entirely in `_fallback`.", "id": 5867, "implemented": true, "kind": "fallback", "modifiers": [], "name": "", "nodeType": "FunctionDefinition", "parameters": { "id": 5861, "nodeType": "ParameterList", "parameters": [], "src": "427:2:39" }, "returnParameters": { "id": 5862, "nodeType": "ParameterList", "parameters": [], "src": "447:0:39" }, "scope": 5896, "src": "418:51:39", "stateMutability": "payable", "superFunction": null, "visibility": "external" }, { "body": null, "documentation": "@return The Address of the implementation.", "id": 5872, "implemented": false, "kind": "function", "modifiers": [], "name": "_implementation", "nodeType": "FunctionDefinition", "parameters": { "id": 5868, "nodeType": "ParameterList", "parameters": [], "src": "557:2:39" }, "returnParameters": { "id": 5871, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 5870, "name": "", "nodeType": "VariableDeclaration", "scope": 5872, "src": "583:7:39", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 5869, "name": "address", "nodeType": "ElementaryTypeName", "src": "583:7:39", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "582:9:39" }, "scope": 5896, "src": "533:59:39", "stateMutability": "view", "superFunction": null, "visibility": "internal" }, { "body": { "id": 5878, "nodeType": "Block", "src": "930:679:39", "statements": [ { "externalReferences": [ { "implementation": { "declaration": 5874, "isOffset": false, "isSlot": false, "src": "1334:14:39", "valueSize": 1 } } ], "id": 5877, "nodeType": "InlineAssembly", "operations": "{\n calldatacopy(0, 0, calldatasize())\n let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)\n returndatacopy(0, 0, returndatasize())\n switch result\n case 0 {\n revert(0, returndatasize())\n }\n default {\n return(0, returndatasize())\n }\n}", "src": "936:673:39" } ] }, "documentation": "@dev Delegates execution to an implementation contract.\nThis is a low level function that doesn't return to its internal call site.\nIt will return to the external caller whatever the implementation returns.\n@param implementation Address to delegate.", "id": 5879, "implemented": true, "kind": "function", "modifiers": [], "name": "_delegate", "nodeType": "FunctionDefinition", "parameters": { "id": 5875, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 5874, "name": "implementation", "nodeType": "VariableDeclaration", "scope": 5879, "src": "897:22:39", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 5873, "name": "address", "nodeType": "ElementaryTypeName", "src": "897:7:39", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "896:24:39" }, "returnParameters": { "id": 5876, "nodeType": "ParameterList", "parameters": [], "src": "930:0:39" }, "scope": 5896, "src": "878:731:39", "stateMutability": "nonpayable", "superFunction": null, "visibility": "internal" }, { "body": { "id": 5882, "nodeType": "Block", "src": "1852:5:39", "statements": [] }, "documentation": "@dev Function that is run as the first thing in the fallback function.\nCan be redefined in derived contracts to add functionality.\nRedefinitions must call super._willFallback().", "id": 5883, "implemented": true, "kind": "function", "modifiers": [], "name": "_willFallback", "nodeType": "FunctionDefinition", "parameters": { "id": 5880, "nodeType": "ParameterList", "parameters": [], "src": "1840:2:39" }, "returnParameters": { "id": 5881, "nodeType": "ParameterList", "parameters": [], "src": "1852:0:39" }, "scope": 5896, "src": "1818:39:39", "stateMutability": "nonpayable", "superFunction": null, "visibility": "internal" }, { "body": { "id": 5894, "nodeType": "Block", "src": "1982:60:39", "statements": [ { "expression": { "argumentTypes": null, "arguments": [], "expression": { "argumentTypes": [], "id": 5886, "name": "_willFallback", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5883, "src": "1988:13:39", "typeDescriptions": { "typeIdentifier": "t_function_internal_nonpayable$__$returns$__$", "typeString": "function ()" } }, "id": 5887, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1988:15:39", "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 5888, "nodeType": "ExpressionStatement", "src": "1988:15:39" }, { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "arguments": [], "expression": { "argumentTypes": [], "id": 5890, "name": "_implementation", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5872, "src": "2019:15:39", "typeDescriptions": { "typeIdentifier": "t_function_internal_view$__$returns$_t_address_$", "typeString": "function () view returns (address)" } }, "id": 5891, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "2019:17:39", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_address", "typeString": "address" } ], "id": 5889, "name": "_delegate", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5879, "src": "2009:9:39", "typeDescriptions": { "typeIdentifier": "t_function_internal_nonpayable$_t_address_$returns$__$", "typeString": "function (address)" } }, "id": 5892, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "2009:28:39", "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 5893, "nodeType": "ExpressionStatement", "src": "2009:28:39" } ] }, "documentation": "@dev fallback implementation.\nExtracted to enable manual triggering.", "id": 5895, "implemented": true, "kind": "function", "modifiers": [], "name": "_fallback", "nodeType": "FunctionDefinition", "parameters": { "id": 5884, "nodeType": "ParameterList", "parameters": [], "src": "1970:2:39" }, "returnParameters": { "id": 5885, "nodeType": "ParameterList", "parameters": [], "src": "1982:0:39" }, "scope": 5896, "src": "1952:90:39", "stateMutability": "nonpayable", "superFunction": null, "visibility": "internal" } ], "scope": 5897, "src": "316:1728:39" } ], "src": "0:2045:39" }, "bytecode": "0x", "deployedBytecode": "0x", "compiler": { "name": "solc", "version": "0.5.3+commit.10d17f24.Emscripten.clang", "optimizer": {}, "evmVersion": "constantinople" } }