-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a13d668
commit 2eb3e24
Showing
2 changed files
with
34 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
|
||
/** | ||
* Utility library of inline functions on addresses | ||
*/ | ||
library AddressUtils { | ||
|
||
/** | ||
* Returns whether the target address is a contract | ||
* @dev This function will return false if invoked during the constructor of a contract, | ||
* as the code is not actually created until after the constructor finishes. | ||
* @param _addr address to check | ||
* @return whether the target address is a contract | ||
*/ | ||
function isContract(address _addr) internal view returns (bool) { | ||
uint256 size; | ||
// XXX Currently there is no better way to check if there is a contract in an address | ||
// than to check the size of the code at that address. | ||
// See https://ethereum.stackexchange.com/a/14016/36603 | ||
// for more details about how this works. | ||
// TODO Check this again before the Serenity release, because all addresses will be | ||
// contracts then. | ||
// solium-disable-next-line security/no-inline-assembly | ||
assembly { size := extcodesize(_addr) } | ||
return size > 0; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters