diff --git a/contracts/token/ERC1155/ERC1155.sol b/contracts/token/ERC1155/ERC1155.sol index 1af455cc6e2..c5ea3a2a223 100644 --- a/contracts/token/ERC1155/ERC1155.sol +++ b/contracts/token/ERC1155/ERC1155.sol @@ -95,12 +95,16 @@ abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IER return _operatorApprovals[account][operator]; } - /// @inheritdoc IERC1155 - function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) public virtual { + function _checkAuthorized(address from) internal view { address sender = _msgSender(); if (from != sender && !isApprovedForAll(from, sender)) { revert ERC1155MissingApprovalForAll(sender, from); } + } + + /// @inheritdoc IERC1155 + function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) public virtual { + _checkAuthorized(from); _safeTransferFrom(from, to, id, value, data); } @@ -112,13 +116,9 @@ abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IER uint256[] memory values, bytes memory data ) public virtual { - address sender = _msgSender(); - if (from != sender && !isApprovedForAll(from, sender)) { - revert ERC1155MissingApprovalForAll(sender, from); - } + _checkAuthorized(from); _safeBatchTransferFrom(from, to, ids, values, data); } - /** * @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`. Will mint (or burn) if `from` * (or `to`) is the zero address.