Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove 'external' functions #2162

Merged
merged 11 commits into from
Apr 2, 2020
Prev Previous commit
Replace isConstructor for !isContract
  • Loading branch information
nventuro committed Apr 2, 2020
commit f8104fd21baa43311f5785179308601626ce9996
18 changes: 3 additions & 15 deletions contracts/access/AccessControl.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma solidity ^0.6.0;

import "../utils/EnumerableSet.sol";
import "../utils/Address.sol";
import "../GSN/Context.sol";

/**
Expand Down Expand Up @@ -36,6 +37,7 @@ import "../GSN/Context.sol";
*/
abstract contract AccessControl is Context {
using EnumerableSet for EnumerableSet.AddressSet;
using Address for address;

struct RoleData {
EnumerableSet.AddressSet members;
Expand Down Expand Up @@ -167,7 +169,7 @@ abstract contract AccessControl is Context {
* - this function can only be called from a constructor.
*/
function _setupRole(bytes32 role, address account) internal virtual {
nventuro marked this conversation as resolved.
Show resolved Hide resolved
require(_isConstructor(), "AccessControl: roles cannot be setup after construction");
require(!address(this).isContract(), "AccessControl: roles cannot be setup after construction");
_grantRole(role, account);
}

Expand All @@ -189,18 +191,4 @@ abstract contract AccessControl is Context {
emit RoleRevoked(role, account, _msgSender());
}
}

// @dev Returns true if and only if the function is running in the constructor
function _isConstructor() private view returns (bool) {
// extcodesize checks the size of the code stored in an address, and
// address returns the current address. Since the code is still not
// deployed when running a constructor, any checks on its code size will
// yield zero, making it an effective way to detect if a contract is
// under construction or not.
address self = address(this);
uint256 cs;
// solhint-disable-next-line no-inline-assembly
assembly { cs := extcodesize(self) }
return cs == 0;
}
}