Address.sol 1.0 KB

12345678910111213141516171819202122232425262728
  1. pragma solidity ^0.4.24;
  2. /**
  3. * Utility library of inline functions on addresses
  4. */
  5. library Address {
  6. /**
  7. * Returns whether the target address is a contract
  8. * @dev This function will return false if invoked during the constructor of a contract,
  9. * as the code is not actually created until after the constructor finishes.
  10. * @param account address of the account to check
  11. * @return whether the target address is a contract
  12. */
  13. function isContract(address account) internal view returns (bool) {
  14. uint256 size;
  15. // XXX Currently there is no better way to check if there is a contract in an address
  16. // than to check the size of the code at that address.
  17. // See https://ethereum.stackexchange.com/a/14016/36603
  18. // for more details about how this works.
  19. // TODO Check this again before the Serenity release, because all addresses will be
  20. // contracts then.
  21. // solium-disable-next-line security/no-inline-assembly
  22. assembly { size := extcodesize(account) }
  23. return size > 0;
  24. }
  25. }