-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor ERC165 to use function overriding instead of storage. #2505
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
25d4344
Replace storage dependency of ERC165 with virtual inheritance
Amxx 8153132
Merge branch 'master' into refactor/virtualERC165
Amxx 592e8c3
add a ERC165Storage implementation
Amxx d963cf8
Merge branch 'master' into refactor/virtualERC165
Amxx 0604e82
improve coverage
Amxx ec04443
Merge branch 'master' into refactor/virtualERC165
Amxx 41eb0dd
rename ERC165Mock
Amxx 0b39f85
adjust documentation for new implementations
frangio 1cac9b8
remove storage test from plain 165 test
frangio 88c576b
lint
frangio 7a48976
add changelog entry
Amxx 0384b49
Merge branch 'master' into refactor/virtualERC165
frangio c7fcbf8
add ERC165Storage to docs site
frangio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./ERC165.sol"; | ||
|
||
/** | ||
* @dev Implementation of the {IERC165} interface. | ||
* | ||
* Contracts may inherit from this and call {_registerInterface} to declare | ||
* their support of an interface. | ||
*/ | ||
abstract contract ERC165Storage is ERC165 { | ||
/** | ||
* @dev Mapping of interface ids to whether or not it's supported. | ||
*/ | ||
mapping(bytes4 => bool) private _supportedInterfaces; | ||
|
||
/** | ||
* @dev See {IERC165-supportsInterface}. | ||
*/ | ||
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { | ||
return super.supportsInterface(interfaceId) || _supportedInterfaces[interfaceId]; | ||
} | ||
|
||
/** | ||
* @dev Registers the contract as an implementer of the interface defined by | ||
* `interfaceId`. Support of the actual ERC165 interface is automatic and | ||
* registering its interface id is not required. | ||
* | ||
* See {IERC165-supportsInterface}. | ||
* | ||
* Requirements: | ||
* | ||
* - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`). | ||
*/ | ||
function _registerInterface(bytes4 interfaceId) internal virtual { | ||
require(interfaceId != 0xffffffff, "ERC165: invalid interface id"); | ||
_supportedInterfaces[interfaceId] = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,12 @@ contract('ERC165', function (accounts) { | |
this.mock = await ERC165Mock.new(); | ||
}); | ||
|
||
it('register interface', async function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test should be removed since it pertains to |
||
expect(await this.mock.supportsInterface('0x00000001')).to.be.equal(false); | ||
await this.mock.registerInterface('0x00000001'); | ||
expect(await this.mock.supportsInterface('0x00000001')).to.be.equal(true); | ||
}); | ||
|
||
it('does not allow 0xffffffff', async function () { | ||
await expectRevert(this.mock.registerInterface('0xffffffff'), 'ERC165: invalid interface id'); | ||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this entire file can be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then
ERC165Storage
should not be abstract, right ?