Skip to content

Commit

Permalink
Replace isConstructor for !isContract
Browse files Browse the repository at this point in the history
  • Loading branch information
nventuro committed Apr 2, 2020
1 parent 834c2a2 commit 907d734
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions contracts/token/ERC20/ERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.6.0;
import "../../GSN/Context.sol";
import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";

/**
* @dev Implementation of the {IERC20} interface.
Expand Down Expand Up @@ -30,6 +31,7 @@ import "../../math/SafeMath.sol";
*/
contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
using Address for address;

mapping (address => uint256) private _balances;

Expand Down Expand Up @@ -282,7 +284,7 @@ contract ERC20 is Context, IERC20 {
* - this function can only be called from a constructor.
*/
function _setupDecimals(uint8 decimals_) internal {
require(_isConstructor(), "ERC20: decimals cannot be changed after construction");
require(!address(this).isContract(), "ERC20: decimals cannot be changed after construction");
_decimals = decimals_;
}

Expand All @@ -301,18 +303,4 @@ contract ERC20 is Context, IERC20 {
* To learn more about hooks, head to xref:ROOT:using-hooks.adoc[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }

// @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;
}
}

0 comments on commit 907d734

Please sign in to comment.