Add an internal _setApprovalForAll function (721 & 1155) (#2834)
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
@ -6,6 +6,7 @@
|
|||||||
* `AccessControl`: add internal `_grantRole(bytes32,address)` and `_revokeRole(bytes32,address)`. ([#2568](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2568))
|
* `AccessControl`: add internal `_grantRole(bytes32,address)` and `_revokeRole(bytes32,address)`. ([#2568](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2568))
|
||||||
* `AccessControl`: mark `_setupRole(bytes32,address)` as deprecated in favor of `_grantRole(bytes32,address)`. ([#2568](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2568))
|
* `AccessControl`: mark `_setupRole(bytes32,address)` as deprecated in favor of `_grantRole(bytes32,address)`. ([#2568](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2568))
|
||||||
* `EIP712`: cache `address(this)` to immutable storage to avoid potential issues if a vanilla contract is used in a delegatecall context. ([#2852](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2852))
|
* `EIP712`: cache `address(this)` to immutable storage to avoid potential issues if a vanilla contract is used in a delegatecall context. ([#2852](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2852))
|
||||||
|
* Add internal `_setApprovalForAll` to `ERC721` and `ERC1155`. ([#2834](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2834))
|
||||||
|
|
||||||
## 4.3.2 (2021-09-14)
|
## 4.3.2 (2021-09-14)
|
||||||
|
|
||||||
|
|||||||
@ -100,10 +100,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|||||||
* @dev See {IERC1155-setApprovalForAll}.
|
* @dev See {IERC1155-setApprovalForAll}.
|
||||||
*/
|
*/
|
||||||
function setApprovalForAll(address operator, bool approved) public virtual override {
|
function setApprovalForAll(address operator, bool approved) public virtual override {
|
||||||
require(_msgSender() != operator, "ERC1155: setting approval status for self");
|
_setApprovalForAll(_msgSender(), operator, approved);
|
||||||
|
|
||||||
_operatorApprovals[_msgSender()][operator] = approved;
|
|
||||||
emit ApprovalForAll(_msgSender(), operator, approved);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -369,6 +366,21 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|||||||
emit TransferBatch(operator, from, address(0), ids, amounts);
|
emit TransferBatch(operator, from, address(0), ids, amounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Approve `operator` to operate on all of `owner` tokens
|
||||||
|
*
|
||||||
|
* Emits a {ApprovalForAll} event.
|
||||||
|
*/
|
||||||
|
function _setApprovalForAll(
|
||||||
|
address owner,
|
||||||
|
address operator,
|
||||||
|
bool approved
|
||||||
|
) internal virtual {
|
||||||
|
require(owner != operator, "ERC1155: setting approval status for self");
|
||||||
|
_operatorApprovals[owner][operator] = approved;
|
||||||
|
emit ApprovalForAll(owner, operator, approved);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Hook that is called before any token transfer. This includes minting
|
* @dev Hook that is called before any token transfer. This includes minting
|
||||||
* and burning, as well as batched variants.
|
* and burning, as well as batched variants.
|
||||||
|
|||||||
@ -133,10 +133,7 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
|
|||||||
* @dev See {IERC721-setApprovalForAll}.
|
* @dev See {IERC721-setApprovalForAll}.
|
||||||
*/
|
*/
|
||||||
function setApprovalForAll(address operator, bool approved) public virtual override {
|
function setApprovalForAll(address operator, bool approved) public virtual override {
|
||||||
require(operator != _msgSender(), "ERC721: approve to caller");
|
_setApprovalForAll(_msgSender(), operator, approved);
|
||||||
|
|
||||||
_operatorApprovals[_msgSender()][operator] = approved;
|
|
||||||
emit ApprovalForAll(_msgSender(), operator, approved);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -356,6 +353,21 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
|
|||||||
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
|
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 {
|
||||||
|
require(owner != operator, "ERC721: approve to caller");
|
||||||
|
_operatorApprovals[owner][operator] = approved;
|
||||||
|
emit ApprovalForAll(owner, operator, approved);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
|
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
|
||||||
* The call is not executed if the target address is not a contract.
|
* The call is not executed if the target address is not a contract.
|
||||||
|
|||||||
Reference in New Issue
Block a user