commit b895ebbef9bebe2de8833ecc87894b806c312d80 parent c6493162b2484ff95f203bd5fb245baab4cd7110 Author: lash <dev@holbrook.no> Date: Sat, 25 Mar 2023 05:46:30 +0000 Add interface check sample contract Diffstat:
A | solidity/Interface.sol | | | 36 | ++++++++++++++++++++++++++++++++++++ |
1 file changed, 36 insertions(+), 0 deletions(-)
diff --git a/solidity/Interface.sol b/solidity/Interface.sol @@ -0,0 +1,36 @@ +pragma solidity >= 0.8.0; + +// SPDX-License-Identifier: GPL-3.0-or-later + +contract InterfaceCheckSample { + uint256 interfaces; + + constructor(uint256 _interfaces) { + interfaces = _interfaces; + } + + // EIP-165 + function supportsInterface(bytes4 interfaceID) external view returns (bool) { + uint32 interfaceN; + uint32 masked; + + interfaceN = uint32(interfaceID); + + // EIP165 interface id + if (uint32(interfaceID) == 0x01ffc9a7) { + return true; + } + + for (uint256 i = 0; i < 256; i += 32) { + masked = uint32((interfaces >> i) & 0xffffffff); + if (masked == 0) { + return false; + } + if (interfaceN == masked) { + return true; + } + } + + return false; + } +}