|
@@ -1,4 +1,5 @@
|
|
// SPDX-License-Identifier: MIT
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
+// OpenZeppelin Contracts v4.3.2 (token/ERC1155/ERC1155.sol)
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
@@ -100,10 +101,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");
|
|
|
|
-
|
|
|
|
- _operatorApprovals[_msgSender()][operator] = approved;
|
|
|
|
- emit ApprovalForAll(_msgSender(), operator, approved);
|
|
|
|
|
|
+ _setApprovalForAll(_msgSender(), operator, approved);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -249,32 +247,32 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @dev Creates `amount` tokens of token type `id`, and assigns them to `account`.
|
|
|
|
|
|
+ * @dev Creates `amount` tokens of token type `id`, and assigns them to `to`.
|
|
*
|
|
*
|
|
* Emits a {TransferSingle} event.
|
|
* Emits a {TransferSingle} event.
|
|
*
|
|
*
|
|
* Requirements:
|
|
* Requirements:
|
|
*
|
|
*
|
|
- * - `account` cannot be the zero address.
|
|
|
|
- * - If `account` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
|
|
|
|
|
|
+ * - `to` cannot be the zero address.
|
|
|
|
+ * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
|
|
* acceptance magic value.
|
|
* acceptance magic value.
|
|
*/
|
|
*/
|
|
function _mint(
|
|
function _mint(
|
|
- address account,
|
|
|
|
|
|
+ address to,
|
|
uint256 id,
|
|
uint256 id,
|
|
uint256 amount,
|
|
uint256 amount,
|
|
bytes memory data
|
|
bytes memory data
|
|
) internal virtual {
|
|
) internal virtual {
|
|
- require(account != address(0), "ERC1155: mint to the zero address");
|
|
|
|
|
|
+ require(to != address(0), "ERC1155: mint to the zero address");
|
|
|
|
|
|
address operator = _msgSender();
|
|
address operator = _msgSender();
|
|
|
|
|
|
- _beforeTokenTransfer(operator, address(0), account, _asSingletonArray(id), _asSingletonArray(amount), data);
|
|
|
|
|
|
+ _beforeTokenTransfer(operator, address(0), to, _asSingletonArray(id), _asSingletonArray(amount), data);
|
|
|
|
|
|
- _balances[id][account] += amount;
|
|
|
|
- emit TransferSingle(operator, address(0), account, id, amount);
|
|
|
|
|
|
+ _balances[id][to] += amount;
|
|
|
|
+ emit TransferSingle(operator, address(0), to, id, amount);
|
|
|
|
|
|
- _doSafeTransferAcceptanceCheck(operator, address(0), account, id, amount, data);
|
|
|
|
|
|
+ _doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -309,31 +307,31 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @dev Destroys `amount` tokens of token type `id` from `account`
|
|
|
|
|
|
+ * @dev Destroys `amount` tokens of token type `id` from `from`
|
|
*
|
|
*
|
|
* Requirements:
|
|
* Requirements:
|
|
*
|
|
*
|
|
- * - `account` cannot be the zero address.
|
|
|
|
- * - `account` must have at least `amount` tokens of token type `id`.
|
|
|
|
|
|
+ * - `from` cannot be the zero address.
|
|
|
|
+ * - `from` must have at least `amount` tokens of token type `id`.
|
|
*/
|
|
*/
|
|
function _burn(
|
|
function _burn(
|
|
- address account,
|
|
|
|
|
|
+ address from,
|
|
uint256 id,
|
|
uint256 id,
|
|
uint256 amount
|
|
uint256 amount
|
|
) internal virtual {
|
|
) internal virtual {
|
|
- require(account != address(0), "ERC1155: burn from the zero address");
|
|
|
|
|
|
+ require(from != address(0), "ERC1155: burn from the zero address");
|
|
|
|
|
|
address operator = _msgSender();
|
|
address operator = _msgSender();
|
|
|
|
|
|
- _beforeTokenTransfer(operator, account, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");
|
|
|
|
|
|
+ _beforeTokenTransfer(operator, from, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");
|
|
|
|
|
|
- uint256 accountBalance = _balances[id][account];
|
|
|
|
- require(accountBalance >= amount, "ERC1155: burn amount exceeds balance");
|
|
|
|
|
|
+ uint256 fromBalance = _balances[id][from];
|
|
|
|
+ require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
|
|
unchecked {
|
|
unchecked {
|
|
- _balances[id][account] = accountBalance - amount;
|
|
|
|
|
|
+ _balances[id][from] = fromBalance - amount;
|
|
}
|
|
}
|
|
|
|
|
|
- emit TransferSingle(operator, account, address(0), id, amount);
|
|
|
|
|
|
+ emit TransferSingle(operator, from, address(0), id, amount);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -344,29 +342,44 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
* - `ids` and `amounts` must have the same length.
|
|
* - `ids` and `amounts` must have the same length.
|
|
*/
|
|
*/
|
|
function _burnBatch(
|
|
function _burnBatch(
|
|
- address account,
|
|
|
|
|
|
+ address from,
|
|
uint256[] memory ids,
|
|
uint256[] memory ids,
|
|
uint256[] memory amounts
|
|
uint256[] memory amounts
|
|
) internal virtual {
|
|
) internal virtual {
|
|
- require(account != address(0), "ERC1155: burn from the zero address");
|
|
|
|
|
|
+ require(from != address(0), "ERC1155: burn from the zero address");
|
|
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
|
|
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
|
|
|
|
|
|
address operator = _msgSender();
|
|
address operator = _msgSender();
|
|
|
|
|
|
- _beforeTokenTransfer(operator, account, address(0), ids, amounts, "");
|
|
|
|
|
|
+ _beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
|
|
|
|
|
|
for (uint256 i = 0; i < ids.length; i++) {
|
|
for (uint256 i = 0; i < ids.length; i++) {
|
|
uint256 id = ids[i];
|
|
uint256 id = ids[i];
|
|
uint256 amount = amounts[i];
|
|
uint256 amount = amounts[i];
|
|
|
|
|
|
- uint256 accountBalance = _balances[id][account];
|
|
|
|
- require(accountBalance >= amount, "ERC1155: burn amount exceeds balance");
|
|
|
|
|
|
+ uint256 fromBalance = _balances[id][from];
|
|
|
|
+ require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
|
|
unchecked {
|
|
unchecked {
|
|
- _balances[id][account] = accountBalance - amount;
|
|
|
|
|
|
+ _balances[id][from] = fromBalance - amount;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- emit TransferBatch(operator, account, 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);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|