123456789101112131415161718192021222324252627 |
- pragma solidity ^0.5.0;
- /**
- * @dev Collection of functions related to the address type,
- */
- library Address {
- /**
- * @dev Returns true if `account` is a contract.
- *
- * This test is non-exhaustive, and there may be false-negatives: during the
- * execution of a contract's constructor, its address will be reported as
- * not containing a contract.
- *
- * > It is unsafe to assume that an address for which this function returns
- * false is an externally-owned account (EOA) and not a contract.
- */
- function isContract(address account) internal view returns (bool) {
- // This method relies in extcodesize, which returns 0 for contracts in
- // construction, since the code is only stored at the end of the
- // constructor execution.
- uint256 size;
- // solhint-disable-next-line no-inline-assembly
- assembly { size := extcodesize(account) }
- return size > 0;
- }
- }
|