|
1 | 1 | // SPDX-License-Identifier: MIT; |
2 | | -pragma solidity ^0.6.0; |
| 2 | +pragma solidity 0.6.2; |
3 | 3 |
|
4 | | -import "@openzeppelin/contracts/introspection/ERC165.sol"; |
| 4 | +import "./IERC165.sol"; |
5 | 5 |
|
6 | 6 | /** |
7 | 7 | * @dev Custom implementation of the IERC165 interface. |
8 | 8 | * This is contract implemented by OpenZeppelin but extended with |
9 | 9 | * _removeInterface function |
10 | 10 | */ |
11 | | -contract ERC165Removable is ERC165 { |
12 | | - /** |
13 | | - * @dev Removes support of the interface |
14 | | - * @param interfaceId Interface Id |
15 | | - */ |
16 | | - function _removeInterface(bytes4 interfaceId) internal { |
17 | | - require(_supportedInterfaces[interfaceId], "ERC165: unknown interface id"); |
18 | | - _supportedInterfaces[interfaceId] = false; |
19 | | - } |
| 11 | +contract ERC165Removable is IERC165 { |
| 12 | + /** |
| 13 | + * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7 |
| 14 | + */ |
| 15 | + bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; |
| 16 | + |
| 17 | + /** |
| 18 | + * @dev Mapping of interface ids to whether or not it's supported. |
| 19 | + */ |
| 20 | + mapping(bytes4 => bool) private _supportedInterfaces; |
| 21 | + |
| 22 | + constructor () internal { |
| 23 | + // Derived contracts need only register support for their own interfaces, |
| 24 | + // we register support for ERC165 itself here |
| 25 | + _registerInterface(_INTERFACE_ID_ERC165); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * @dev See {IERC165-supportsInterface}. |
| 30 | + * |
| 31 | + * Time complexity O(1), guaranteed to always use less than 30 000 gas. |
| 32 | + */ |
| 33 | + function supportsInterface(bytes4 interfaceId) public view override returns (bool) { |
| 34 | + return _supportedInterfaces[interfaceId]; |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @dev Registers the contract as an implementer of the interface defined by |
| 39 | + * `interfaceId`. Support of the actual ERC165 interface is automatic and |
| 40 | + * registering its interface id is not required. |
| 41 | + * |
| 42 | + * See {IERC165-supportsInterface}. |
| 43 | + * |
| 44 | + * Requirements: |
| 45 | + * |
| 46 | + * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`). |
| 47 | + */ |
| 48 | + function _registerInterface(bytes4 interfaceId) internal virtual { |
| 49 | + require(interfaceId != 0xffffffff, "ERC165: invalid interface id"); |
| 50 | + _supportedInterfaces[interfaceId] = true; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @dev Removes support of the interface |
| 55 | + * @param interfaceId Interface Id |
| 56 | + */ |
| 57 | + function _removeInterface(bytes4 interfaceId) internal { |
| 58 | + require(_supportedInterfaces[interfaceId], "ERC165: unknown interface id"); |
| 59 | + _supportedInterfaces[interfaceId] = false; |
| 60 | + } |
20 | 61 | } |
0 commit comments