Skip to content

Commit

Permalink
Add an internal _setApprovalForAll function (721 & 1155)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Aug 23, 2021
1 parent 83644fd commit 89fe594
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
15 changes: 12 additions & 3 deletions contracts/token/ERC1155/ERC1155.sol
Expand Up @@ -101,9 +101,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(_msgSender() != operator, "ERC1155: setting approval status for self");

_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
_setApprovalForAll(_msgSender(), operator, approved);
}

/**
Expand Down Expand Up @@ -369,6 +367,17 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
emit TransferBatch(operator, account, address(0), ids, amounts);
}

/**
* @dev Approve `to` to operate on all of `owner` tokens
*
* Emits a {ApprovalForAll} event.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
// TODO: add sanity checks?
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}

/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning, as well as batched variants.
Expand Down
15 changes: 12 additions & 3 deletions contracts/token/ERC721/ERC721.sol
Expand Up @@ -134,9 +134,7 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
require(operator != _msgSender(), "ERC721: approve to caller");

_operatorApprovals[_msgSender()][operator] = approved;
emit ApprovalForAll(_msgSender(), operator, approved);
_setApprovalForAll(_msgSender(), operator, approved);
}

/**
Expand Down Expand Up @@ -356,6 +354,17 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}

/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits a {ApprovalForAll} event.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
// TODO: add sanity checks?
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}

/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
Expand Down

0 comments on commit 89fe594

Please sign in to comment.