diff --git a/EIPS/eip-165.md b/EIPS/eip-165.md index ed4b9112..af48ad20 100644 --- a/EIPS/eip-165.md +++ b/EIPS/eip-165.md @@ -115,48 +115,29 @@ Following is a caching contract that detects which interfaces other contracts im ```solidity pragma solidity ^0.4.20; -contract ERC165Cache { +contract ERC165Query { bytes4 constant InvalidID = 0xffffffff; bytes4 constant ERC165ID = 0x01ffc9a7; - enum ImplStatus { Unknown, No, Yes } - mapping (address => mapping (bytes4 => ImplStatus)) cache; - - // Return value from cache if available - function interfaceSupported(address _contract, bytes4 _interfaceId) external returns (bool) { - ImplStatus status = cache[_contract][_interfaceId]; - if (status == ImplStatus.Unknown) { - return checkInterfaceSupported(_contract, _interfaceId); - } - return status == ImplStatus.Yes; - } - - // Repull result into cache - function checkInterfaceSupported(address _contract, bytes4 _interfaceId) public returns (bool) { - ImplStatus status = determineInterfaceImplementationStatus(_contract, _interfaceId); - cache[_contract][_interfaceId] = status; - return status == ImplStatus.Yes; - } - - function determineInterfaceImplementationStatus(address _contract, bytes4 _interfaceId) internal view returns (ImplStatus) { + function doesContractImplementInterface(address _contract, bytes4 _interfaceId) external view returns (bool) { uint256 success; uint256 result; (success, result) = noThrowCall(_contract, ERC165ID); if ((success==0)||(result==0)) { - return ImplStatus.No; + return false; } (success, result) = noThrowCall(_contract, InvalidID); if ((success==0)||(result!=0)) { - return ImplStatus.No; + return false; } (success, result) = noThrowCall(_contract, _interfaceId); if ((success==1)&&(result==1)) { - return ImplStatus.Yes; + return true; } - return ImplStatus.No; + return false; } function noThrowCall(address _contract, bytes4 _interfaceId) constant internal returns (uint256 success, uint256 result) { @@ -171,7 +152,7 @@ contract ERC165Cache { 30000, // 30k gas _contract, // To addr x, // Inputs are stored at location x - 0x20, // Inputs are 8 byes long + 0x20, // Inputs are 8 byes long x, // Store output over input (saves space) 0x20) // Outputs are 32 bytes long