chiru-labs / ERC721A

https://ERC721A.org
MIT License
2.51k stars 842 forks source link

Feature Request: Add block list using mapping for efficiency #417

Open maximonee opened 2 years ago

maximonee commented 2 years ago

Hi team,

I recently stumbled across a great feature request to add a block list to combat marketplaces not respecting royalties. I think the proposal was good, but it was unfortunately not very performant because the creator could have used a mapping instead as it is more efficient. I’ve rewritten the proposal using a more efficient mapping instead.

mapping (uint128 => address[]) public blockedAddrs;
uint256 numberOfBlockedAddressesBecauseOfCreatorRoyaltiesDisrespectingCreators = 0;

function populateBlockedAddrs(Address addr) public onlyOwner{
    blockedAddrs[numberOfBlockedAddressesBecauseOfCreatorRoyaltiesDisrespectingCreators] = addr;
    numberOfBlockedAddressesBecauseOfCreatorRoyaltiesDisrespectingCreators++;
}

function _beforeTokenTransfer(
    address from,
    address to,
    uint256 tokenId
) internal virtual override(ERC721, ERC721Enumerable) {

    uint256 i = 0;
    while(i < numberOfBlockedAddressesBecauseOfCreatorRoyaltiesDisrespectingCreators) {
        for (uint256 j = 0; j < blockedAddrs[i].length; j++) {

            require(msg.sender != blockedAddrs[i][j], "Thanks for the consideration");
            j = j + 1;
        }
        unchecked {
            i++;
        }
    }
    super._beforeTokenTransfer(from, to, tokenId);
}
Vectorized commented 2 years ago

Thank you for the request.

After much discussion, we have decided it is unsuitable for inclusion, citing reasons highlighted in #416.

However, due to the supposedly greatly improved efficiency of this implementation, we may leave this request open for a while as a reference for any devs aspiring to build a similar feature.