Interface.sol (670B)
1 pragma solidity >= 0.8.0; 2 3 // SPDX-License-Identifier: GPL-3.0-or-later 4 5 contract InterfaceCheckSample { 6 uint256 interfaces; 7 8 constructor(uint256 _interfaces) { 9 interfaces = _interfaces; 10 } 11 12 // EIP-165 13 function supportsInterface(bytes4 interfaceID) external view returns (bool) { 14 uint32 interfaceN; 15 uint32 masked; 16 17 interfaceN = uint32(interfaceID); 18 19 // EIP165 interface id 20 if (uint32(interfaceID) == 0x01ffc9a7) { 21 return true; 22 } 23 24 for (uint256 i = 0; i < 256; i += 32) { 25 masked = uint32((interfaces >> i) & 0xffffffff); 26 if (masked == 0) { 27 return false; 28 } 29 if (interfaceN == masked) { 30 return true; 31 } 32 } 33 34 return false; 35 } 36 }