mirror of
https://github.com/status-im/EIPs.git
synced 2025-01-14 08:54:44 +00:00
Switch from a cache to a query contract, cache is out of scope
This commit is contained in:
parent
b675b4b3fa
commit
12fe0b505c
@ -115,48 +115,29 @@ Following is a caching contract that detects which interfaces other contracts im
|
|||||||
```solidity
|
```solidity
|
||||||
pragma solidity ^0.4.20;
|
pragma solidity ^0.4.20;
|
||||||
|
|
||||||
contract ERC165Cache {
|
contract ERC165Query {
|
||||||
bytes4 constant InvalidID = 0xffffffff;
|
bytes4 constant InvalidID = 0xffffffff;
|
||||||
bytes4 constant ERC165ID = 0x01ffc9a7;
|
bytes4 constant ERC165ID = 0x01ffc9a7;
|
||||||
|
|
||||||
enum ImplStatus { Unknown, No, Yes }
|
function doesContractImplementInterface(address _contract, bytes4 _interfaceId) external view returns (bool) {
|
||||||
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) {
|
|
||||||
uint256 success;
|
uint256 success;
|
||||||
uint256 result;
|
uint256 result;
|
||||||
|
|
||||||
(success, result) = noThrowCall(_contract, ERC165ID);
|
(success, result) = noThrowCall(_contract, ERC165ID);
|
||||||
if ((success==0)||(result==0)) {
|
if ((success==0)||(result==0)) {
|
||||||
return ImplStatus.No;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
(success, result) = noThrowCall(_contract, InvalidID);
|
(success, result) = noThrowCall(_contract, InvalidID);
|
||||||
if ((success==0)||(result!=0)) {
|
if ((success==0)||(result!=0)) {
|
||||||
return ImplStatus.No;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
(success, result) = noThrowCall(_contract, _interfaceId);
|
(success, result) = noThrowCall(_contract, _interfaceId);
|
||||||
if ((success==1)&&(result==1)) {
|
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) {
|
function noThrowCall(address _contract, bytes4 _interfaceId) constant internal returns (uint256 success, uint256 result) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user