add queryable extension to ERC721Base#560
Conversation
| * @title ERC721A Queryable | ||
| * @dev ERC721A subclass with convenience query functions. | ||
| */ | ||
| abstract contract ERC721AQueryable is ERC721A, IERC721AQueryable { |
There was a problem hiding this comment.
don't we already have this file somewhere?
There was a problem hiding this comment.
don't we already have this file somewhere?
There isn't a non-upgradable version currently.
joaquim-verges
left a comment
There was a problem hiding this comment.
How's the contract sizes? Bases should have a bit of wiggle room to add custom fns
ERC721Base has 13kb in left over space. The queryable adds ~1kb. |
|
Should be plenty. Ship it |
Signed-off-by: WhiteOakKong <92236155+WhiteOakKong@users.noreply.github.com>
|
@nkrishang @kumaryash90 can you review? |
| */ | ||
| function tokensOfOwner(address owner) external view override returns (uint256[] memory) { | ||
| unchecked { | ||
| uint256 tokenIdsIdx; |
Check warning
Code scanning / Slither
Uninitialized local variables
| * - `burned = `false` | ||
| */ | ||
| function explicitOwnershipOf(uint256 tokenId) public view override returns (TokenOwnership memory) { | ||
| TokenOwnership memory ownership; |
Check warning
Code scanning / Slither
Uninitialized local variables
| function tokensOfOwner(address owner) external view override returns (uint256[] memory) { | ||
| unchecked { | ||
| uint256 tokenIdsIdx; | ||
| address currOwnershipAddr; |
Check warning
Code scanning / Slither
Uninitialized local variables
| function tokensOfOwnerIn( | ||
| address owner, | ||
| uint256 start, | ||
| uint256 stop | ||
| ) external view override returns (uint256[] memory) { | ||
| unchecked { | ||
| if (start >= stop) revert InvalidQueryRange(); | ||
| uint256 tokenIdsIdx; | ||
| uint256 stopLimit = _currentIndex; | ||
| // Set `start = max(start, _startTokenId())`. | ||
| if (start < _startTokenId()) { | ||
| start = _startTokenId(); | ||
| } | ||
| // Set `stop = min(stop, _currentIndex)`. | ||
| if (stop > stopLimit) { | ||
| stop = stopLimit; | ||
| } | ||
| uint256 tokenIdsMaxLength = balanceOf(owner); | ||
| // Set `tokenIdsMaxLength = min(balanceOf(owner), stop - start)`, | ||
| // to cater for cases where `balanceOf(owner)` is too big. | ||
| if (start < stop) { | ||
| uint256 rangeLength = stop - start; | ||
| if (rangeLength < tokenIdsMaxLength) { | ||
| tokenIdsMaxLength = rangeLength; | ||
| } | ||
| } else { | ||
| tokenIdsMaxLength = 0; | ||
| } | ||
| uint256[] memory tokenIds = new uint256[](tokenIdsMaxLength); | ||
| if (tokenIdsMaxLength == 0) { | ||
| return tokenIds; | ||
| } | ||
| // We need to call `explicitOwnershipOf(start)`, | ||
| // because the slot at `start` may not be initialized. | ||
| TokenOwnership memory ownership = explicitOwnershipOf(start); | ||
| address currOwnershipAddr; | ||
| // If the starting slot exists (i.e. not burned), initialize `currOwnershipAddr`. | ||
| // `ownership.address` will not be zero, as `start` is clamped to the valid token ID range. | ||
| if (!ownership.burned) { | ||
| currOwnershipAddr = ownership.addr; | ||
| } | ||
| for (uint256 i = start; i != stop && tokenIdsIdx != tokenIdsMaxLength; ++i) { | ||
| ownership = _ownerships[i]; | ||
| if (ownership.burned) { | ||
| continue; | ||
| } | ||
| if (ownership.addr != address(0)) { | ||
| currOwnershipAddr = ownership.addr; | ||
| } | ||
| if (currOwnershipAddr == owner) { | ||
| tokenIds[tokenIdsIdx++] = i; | ||
| } | ||
| } | ||
| // Downsize the array to fit. | ||
| assembly { | ||
| mstore(tokenIds, tokenIdsIdx) | ||
| } | ||
| return tokenIds; | ||
| } | ||
| } |
Check warning
Code scanning / Slither
Assembly usage
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #560 +/- ##
==========================================
- Coverage 62.34% 57.43% -4.91%
==========================================
Files 216 215 -1
Lines 6647 6614 -33
==========================================
- Hits 4144 3799 -345
- Misses 2503 2815 +312 ☔ View full report in Codecov by Sentry. |
No description provided.