Merge tag 'v2.1.1' of github.com:OpenZeppelin/openzeppelin-solidity
v2.1.1
This commit is contained in:
@ -1,55 +1,44 @@
|
||||
pragma solidity ^0.4.24;
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
import "zos-lib/contracts/Initializable.sol";
|
||||
import "./IERC165.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title ERC165
|
||||
* @author Matt Condon (@shrugs)
|
||||
* @dev Implements ERC165 using a lookup table.
|
||||
*/
|
||||
contract ERC165 is Initializable, IERC165 {
|
||||
|
||||
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
|
||||
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
|
||||
/**
|
||||
* 0x01ffc9a7 ===
|
||||
* bytes4(keccak256('supportsInterface(bytes4)'))
|
||||
* bytes4(keccak256('supportsInterface(bytes4)'))
|
||||
*/
|
||||
|
||||
/**
|
||||
* @dev a mapping of interface id to whether or not it's supported
|
||||
*/
|
||||
mapping(bytes4 => bool) internal _supportedInterfaces;
|
||||
mapping(bytes4 => bool) private _supportedInterfaces;
|
||||
|
||||
/**
|
||||
* @dev A contract implementing SupportsInterfaceWithLookup
|
||||
* implement ERC165 itself
|
||||
*/
|
||||
function initialize()
|
||||
public
|
||||
initializer
|
||||
{
|
||||
function initialize() public initializer {
|
||||
_registerInterface(_InterfaceId_ERC165);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev implement supportsInterface(bytes4) using a lookup table
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId)
|
||||
public
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
function supportsInterface(bytes4 interfaceId) external view returns (bool) {
|
||||
return _supportedInterfaces[interfaceId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev private method for registering an interface
|
||||
* @dev internal method for registering an interface
|
||||
*/
|
||||
function _registerInterface(bytes4 interfaceId)
|
||||
internal
|
||||
{
|
||||
function _registerInterface(bytes4 interfaceId) internal {
|
||||
require(interfaceId != 0xffffffff);
|
||||
_supportedInterfaces[interfaceId] = true;
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
/**
|
||||
* @title ERC165Checker
|
||||
@ -8,29 +7,24 @@ pragma solidity ^0.4.24;
|
||||
*/
|
||||
library ERC165Checker {
|
||||
// As per the EIP-165 spec, no interface should ever match 0xffffffff
|
||||
bytes4 private constant _InterfaceId_Invalid = 0xffffffff;
|
||||
bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;
|
||||
|
||||
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
|
||||
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
|
||||
/**
|
||||
* 0x01ffc9a7 ===
|
||||
* bytes4(keccak256('supportsInterface(bytes4)'))
|
||||
* bytes4(keccak256('supportsInterface(bytes4)'))
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @notice Query if a contract supports ERC165
|
||||
* @param account The address of the contract to query for support of ERC165
|
||||
* @return true if the contract at account implements ERC165
|
||||
*/
|
||||
function supportsERC165(address account)
|
||||
internal
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
function _supportsERC165(address account) internal view returns (bool) {
|
||||
// Any contract that implements ERC165 must explicitly indicate support of
|
||||
// InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
|
||||
return supportsERC165Interface(account, _InterfaceId_ERC165) &&
|
||||
!supportsERC165Interface(account, _InterfaceId_Invalid);
|
||||
return _supportsERC165Interface(account, _INTERFACE_ID_ERC165) &&
|
||||
!_supportsERC165Interface(account, _INTERFACE_ID_INVALID);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,14 +35,10 @@ library ERC165Checker {
|
||||
* identifier interfaceId, false otherwise
|
||||
* @dev Interface identification is specified in ERC-165.
|
||||
*/
|
||||
function supportsInterface(address account, bytes4 interfaceId)
|
||||
internal
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
function _supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
|
||||
// query support of both ERC165 as per the spec and support of _interfaceId
|
||||
return supportsERC165(account) &&
|
||||
supportsERC165Interface(account, interfaceId);
|
||||
return _supportsERC165(account) &&
|
||||
_supportsERC165Interface(account, interfaceId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,19 +49,15 @@ library ERC165Checker {
|
||||
* interfaceIds list, false otherwise
|
||||
* @dev Interface identification is specified in ERC-165.
|
||||
*/
|
||||
function supportsInterfaces(address account, bytes4[] interfaceIds)
|
||||
internal
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
function _supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
|
||||
// query support of ERC165 itself
|
||||
if (!supportsERC165(account)) {
|
||||
if (!_supportsERC165(account)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// query support of each interface in _interfaceIds
|
||||
for (uint256 i = 0; i < interfaceIds.length; i++) {
|
||||
if (!supportsERC165Interface(account, interfaceIds[i])) {
|
||||
if (!_supportsERC165Interface(account, interfaceIds[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -91,15 +77,10 @@ library ERC165Checker {
|
||||
* with the `supportsERC165` method in this library.
|
||||
* Interface identification is specified in ERC-165.
|
||||
*/
|
||||
function supportsERC165Interface(address account, bytes4 interfaceId)
|
||||
private
|
||||
view
|
||||
returns (bool)
|
||||
{
|
||||
function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) {
|
||||
// success determines whether the staticcall succeeded and result determines
|
||||
// whether the contract at account indicates support of _interfaceId
|
||||
(bool success, bool result) = callERC165SupportsInterface(
|
||||
account, interfaceId);
|
||||
(bool success, bool result) = _callERC165SupportsInterface(account, interfaceId);
|
||||
|
||||
return (success && result);
|
||||
}
|
||||
@ -112,37 +93,31 @@ library ERC165Checker {
|
||||
* @return result true if the STATICCALL succeeded and the contract at account
|
||||
* indicates support of the interface with identifier interfaceId, false otherwise
|
||||
*/
|
||||
function callERC165SupportsInterface(
|
||||
address account,
|
||||
bytes4 interfaceId
|
||||
)
|
||||
function _callERC165SupportsInterface(address account, bytes4 interfaceId)
|
||||
private
|
||||
view
|
||||
returns (bool success, bool result)
|
||||
{
|
||||
bytes memory encodedParams = abi.encodeWithSelector(
|
||||
_InterfaceId_ERC165,
|
||||
interfaceId
|
||||
);
|
||||
bytes memory encodedParams = abi.encodeWithSelector(_INTERFACE_ID_ERC165, interfaceId);
|
||||
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
// solhint-disable-next-line no-inline-assembly
|
||||
assembly {
|
||||
let encodedParams_data := add(0x20, encodedParams)
|
||||
let encodedParams_size := mload(encodedParams)
|
||||
|
||||
let output := mload(0x40) // Find empty storage location using "free memory pointer"
|
||||
let output := mload(0x40) // Find empty storage location using "free memory pointer"
|
||||
mstore(output, 0x0)
|
||||
|
||||
success := staticcall(
|
||||
30000, // 30k gas
|
||||
account, // To addr
|
||||
30000, // 30k gas
|
||||
account, // To addr
|
||||
encodedParams_data,
|
||||
encodedParams_size,
|
||||
output,
|
||||
0x20 // Outputs are 32 bytes long
|
||||
0x20 // Outputs are 32 bytes long
|
||||
)
|
||||
|
||||
result := mload(output) // Load the result
|
||||
result := mload(output) // Load the result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,20 +1,15 @@
|
||||
pragma solidity ^0.4.24;
|
||||
|
||||
pragma solidity ^0.5.0;
|
||||
|
||||
/**
|
||||
* @title IERC165
|
||||
* @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md
|
||||
*/
|
||||
interface IERC165 {
|
||||
|
||||
/**
|
||||
* @notice Query if a contract implements an interface
|
||||
* @param interfaceId The interface identifier, as specified in ERC-165
|
||||
* @dev Interface identification is specified in ERC-165. This function
|
||||
* uses less than 30,000 gas.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId)
|
||||
external
|
||||
view
|
||||
returns (bool);
|
||||
function supportsInterface(bytes4 interfaceId) external view returns (bool);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user