Added leading underscore to internal functions, renamed supportsInterfaces. (#1435)
This commit is contained in:
@ -20,15 +20,15 @@ library ERC165Checker {
|
|||||||
* @param account The address of the contract to query for support of ERC165
|
* @param account The address of the contract to query for support of ERC165
|
||||||
* @return true if the contract at account implements ERC165
|
* @return true if the contract at account implements ERC165
|
||||||
*/
|
*/
|
||||||
function supportsERC165(address account)
|
function _supportsERC165(address account)
|
||||||
internal
|
internal
|
||||||
view
|
view
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
// Any contract that implements ERC165 must explicitly indicate support of
|
// Any contract that implements ERC165 must explicitly indicate support of
|
||||||
// InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
|
// InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
|
||||||
return supportsERC165Interface(account, _InterfaceId_ERC165) &&
|
return _supportsERC165Interface(account, _InterfaceId_ERC165) &&
|
||||||
!supportsERC165Interface(account, _InterfaceId_Invalid);
|
!_supportsERC165Interface(account, _InterfaceId_Invalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,14 +39,14 @@ library ERC165Checker {
|
|||||||
* identifier interfaceId, false otherwise
|
* identifier interfaceId, false otherwise
|
||||||
* @dev Interface identification is specified in ERC-165.
|
* @dev Interface identification is specified in ERC-165.
|
||||||
*/
|
*/
|
||||||
function supportsInterface(address account, bytes4 interfaceId)
|
function _supportsInterface(address account, bytes4 interfaceId)
|
||||||
internal
|
internal
|
||||||
view
|
view
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
// query support of both ERC165 as per the spec and support of _interfaceId
|
// query support of both ERC165 as per the spec and support of _interfaceId
|
||||||
return supportsERC165(account) &&
|
return _supportsERC165(account) &&
|
||||||
supportsERC165Interface(account, interfaceId);
|
_supportsERC165Interface(account, interfaceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,19 +57,19 @@ library ERC165Checker {
|
|||||||
* interfaceIds list, false otherwise
|
* interfaceIds list, false otherwise
|
||||||
* @dev Interface identification is specified in ERC-165.
|
* @dev Interface identification is specified in ERC-165.
|
||||||
*/
|
*/
|
||||||
function supportsInterfaces(address account, bytes4[] interfaceIds)
|
function _supportsAllInterfaces(address account, bytes4[] interfaceIds)
|
||||||
internal
|
internal
|
||||||
view
|
view
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
// query support of ERC165 itself
|
// query support of ERC165 itself
|
||||||
if (!supportsERC165(account)) {
|
if (!_supportsERC165(account)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// query support of each interface in _interfaceIds
|
// query support of each interface in _interfaceIds
|
||||||
for (uint256 i = 0; i < interfaceIds.length; i++) {
|
for (uint256 i = 0; i < interfaceIds.length; i++) {
|
||||||
if (!supportsERC165Interface(account, interfaceIds[i])) {
|
if (!_supportsERC165Interface(account, interfaceIds[i])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,14 +89,14 @@ library ERC165Checker {
|
|||||||
* with the `supportsERC165` method in this library.
|
* with the `supportsERC165` method in this library.
|
||||||
* Interface identification is specified in ERC-165.
|
* Interface identification is specified in ERC-165.
|
||||||
*/
|
*/
|
||||||
function supportsERC165Interface(address account, bytes4 interfaceId)
|
function _supportsERC165Interface(address account, bytes4 interfaceId)
|
||||||
private
|
private
|
||||||
view
|
view
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
// success determines whether the staticcall succeeded and result determines
|
// success determines whether the staticcall succeeded and result determines
|
||||||
// whether the contract at account indicates support of _interfaceId
|
// whether the contract at account indicates support of _interfaceId
|
||||||
(bool success, bool result) = callERC165SupportsInterface(
|
(bool success, bool result) = _callERC165SupportsInterface(
|
||||||
account, interfaceId);
|
account, interfaceId);
|
||||||
|
|
||||||
return (success && result);
|
return (success && result);
|
||||||
@ -110,7 +110,7 @@ library ERC165Checker {
|
|||||||
* @return result true if the STATICCALL succeeded and the contract at account
|
* @return result true if the STATICCALL succeeded and the contract at account
|
||||||
* indicates support of the interface with identifier interfaceId, false otherwise
|
* indicates support of the interface with identifier interfaceId, false otherwise
|
||||||
*/
|
*/
|
||||||
function callERC165SupportsInterface(
|
function _callERC165SupportsInterface(
|
||||||
address account,
|
address account,
|
||||||
bytes4 interfaceId
|
bytes4 interfaceId
|
||||||
)
|
)
|
||||||
|
|||||||
@ -10,7 +10,7 @@ contract ERC165CheckerMock {
|
|||||||
view
|
view
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
return account.supportsERC165();
|
return account._supportsERC165();
|
||||||
}
|
}
|
||||||
|
|
||||||
function supportsInterface(address account, bytes4 interfaceId)
|
function supportsInterface(address account, bytes4 interfaceId)
|
||||||
@ -18,14 +18,14 @@ contract ERC165CheckerMock {
|
|||||||
view
|
view
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
return account.supportsInterface(interfaceId);
|
return account._supportsInterface(interfaceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function supportsInterfaces(address account, bytes4[] interfaceIds)
|
function supportsAllInterfaces(address account, bytes4[] interfaceIds)
|
||||||
public
|
public
|
||||||
view
|
view
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
return account.supportsInterfaces(interfaceIds);
|
return account._supportsAllInterfaces(interfaceIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,8 +32,8 @@ contract('ERC165Checker', function () {
|
|||||||
supported.should.equal(false);
|
supported.should.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not support mock interface via supportsInterfaces', async function () {
|
it('does not support mock interface via supportsAllInterfaces', async function () {
|
||||||
const supported = await this.mock.supportsInterfaces(this.target.address, [DUMMY_ID]);
|
const supported = await this.mock.supportsAllInterfaces(this.target.address, [DUMMY_ID]);
|
||||||
supported.should.equal(false);
|
supported.should.equal(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -53,8 +53,8 @@ contract('ERC165Checker', function () {
|
|||||||
supported.should.equal(false);
|
supported.should.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not support mock interface via supportsInterfaces', async function () {
|
it('does not support mock interface via supportsAllInterfaces', async function () {
|
||||||
const supported = await this.mock.supportsInterfaces(this.target.address, [DUMMY_ID]);
|
const supported = await this.mock.supportsAllInterfaces(this.target.address, [DUMMY_ID]);
|
||||||
supported.should.equal(false);
|
supported.should.equal(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -74,8 +74,8 @@ contract('ERC165Checker', function () {
|
|||||||
supported.should.equal(true);
|
supported.should.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports mock interface via supportsInterfaces', async function () {
|
it('supports mock interface via supportsAllInterfaces', async function () {
|
||||||
const supported = await this.mock.supportsInterfaces(this.target.address, [DUMMY_ID]);
|
const supported = await this.mock.supportsAllInterfaces(this.target.address, [DUMMY_ID]);
|
||||||
supported.should.equal(true);
|
supported.should.equal(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -98,22 +98,22 @@ contract('ERC165Checker', function () {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports all interfaceIds via supportsInterfaces', async function () {
|
it('supports all interfaceIds via supportsAllInterfaces', async function () {
|
||||||
const supported = await this.mock.supportsInterfaces(this.target.address, this.supportedInterfaces);
|
const supported = await this.mock.supportsAllInterfaces(this.target.address, this.supportedInterfaces);
|
||||||
supported.should.equal(true);
|
supported.should.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports none of the interfaces queried via supportsInterfaces', async function () {
|
it('supports none of the interfaces queried via supportsAllInterfaces', async function () {
|
||||||
const interfaceIdsToTest = [DUMMY_UNSUPPORTED_ID, DUMMY_UNSUPPORTED_ID_2];
|
const interfaceIdsToTest = [DUMMY_UNSUPPORTED_ID, DUMMY_UNSUPPORTED_ID_2];
|
||||||
|
|
||||||
const supported = await this.mock.supportsInterfaces(this.target.address, interfaceIdsToTest);
|
const supported = await this.mock.supportsAllInterfaces(this.target.address, interfaceIdsToTest);
|
||||||
supported.should.equal(false);
|
supported.should.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports not all of the interfaces queried via supportsInterfaces', async function () {
|
it('supports not all of the interfaces queried via supportsAllInterfaces', async function () {
|
||||||
const interfaceIdsToTest = [...this.supportedInterfaces, DUMMY_UNSUPPORTED_ID];
|
const interfaceIdsToTest = [...this.supportedInterfaces, DUMMY_UNSUPPORTED_ID];
|
||||||
|
|
||||||
const supported = await this.mock.supportsInterfaces(this.target.address, interfaceIdsToTest);
|
const supported = await this.mock.supportsAllInterfaces(this.target.address, interfaceIdsToTest);
|
||||||
supported.should.equal(false);
|
supported.should.equal(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -129,8 +129,8 @@ contract('ERC165Checker', function () {
|
|||||||
supported.should.equal(false);
|
supported.should.equal(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not support mock interface via supportsInterfaces', async function () {
|
it('does not support mock interface via supportsAllInterfaces', async function () {
|
||||||
const supported = await this.mock.supportsInterfaces(DUMMY_ACCOUNT, [DUMMY_ID]);
|
const supported = await this.mock.supportsAllInterfaces(DUMMY_ACCOUNT, [DUMMY_ID]);
|
||||||
supported.should.equal(false);
|
supported.should.equal(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user