Skip to content

Commit

Permalink
removed openzeppelin dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
kostysh committed Nov 12, 2020
1 parent f24edd7 commit 9d86d87
Show file tree
Hide file tree
Showing 6 changed files with 6,045 additions and 765 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
build
temp
keys.json
63 changes: 52 additions & 11 deletions contracts/ERC165/ERC165Removable.sol
Original file line number Diff line number Diff line change
@@ -1,20 +1,61 @@
// SPDX-License-Identifier: MIT;
pragma solidity ^0.6.0;
pragma solidity 0.6.2;

import "@openzeppelin/contracts/introspection/ERC165.sol";
import "./IERC165.sol";

/**
* @dev Custom implementation of the IERC165 interface.
* This is contract implemented by OpenZeppelin but extended with
* _removeInterface function
*/
contract ERC165Removable is ERC165 {
/**
* @dev Removes support of the interface
* @param interfaceId Interface Id
*/
function _removeInterface(bytes4 interfaceId) internal {
require(_supportedInterfaces[interfaceId], "ERC165: unknown interface id");
_supportedInterfaces[interfaceId] = false;
}
contract ERC165Removable is IERC165 {
/**
* bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
*/
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;

/**
* @dev Mapping of interface ids to whether or not it's supported.
*/
mapping(bytes4 => bool) private _supportedInterfaces;

constructor () internal {
// Derived contracts need only register support for their own interfaces,
// we register support for ERC165 itself here
_registerInterface(_INTERFACE_ID_ERC165);
}

/**
* @dev See {IERC165-supportsInterface}.
*
* Time complexity O(1), guaranteed to always use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) public view override returns (bool) {
return _supportedInterfaces[interfaceId];
}

/**
* @dev Registers the contract as an implementer of the interface defined by
* `interfaceId`. Support of the actual ERC165 interface is automatic and
* registering its interface id is not required.
*
* See {IERC165-supportsInterface}.
*
* Requirements:
*
* - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
*/
function _registerInterface(bytes4 interfaceId) internal virtual {
require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
_supportedInterfaces[interfaceId] = true;
}

/**
* @dev Removes support of the interface
* @param interfaceId Interface Id
*/
function _removeInterface(bytes4 interfaceId) internal {
require(_supportedInterfaces[interfaceId], "ERC165: unknown interface id");
_supportedInterfaces[interfaceId] = false;
}
}
24 changes: 24 additions & 0 deletions contracts/ERC165/IERC165.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Loading

0 comments on commit 9d86d87

Please sign in to comment.