|
@@ -20,10 +20,10 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
using Address for address;
|
|
|
|
|
|
// Mapping from token ID to account balances
|
|
|
- mapping (uint256 => mapping(address => uint256)) private _balances;
|
|
|
+ mapping(uint256 => mapping(address => uint256)) private _balances;
|
|
|
|
|
|
// Mapping from account to operator approvals
|
|
|
- mapping (address => mapping(address => bool)) private _operatorApprovals;
|
|
|
+ mapping(address => mapping(address => bool)) private _operatorApprovals;
|
|
|
|
|
|
// Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
|
|
|
string private _uri;
|
|
@@ -31,7 +31,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
/**
|
|
|
* @dev See {_setURI}.
|
|
|
*/
|
|
|
- constructor (string memory uri_) {
|
|
|
+ constructor(string memory uri_) {
|
|
|
_setURI(uri_);
|
|
|
}
|
|
|
|
|
@@ -39,9 +39,10 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
* @dev See {IERC165-supportsInterface}.
|
|
|
*/
|
|
|
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
|
|
|
- return interfaceId == type(IERC1155).interfaceId
|
|
|
- || interfaceId == type(IERC1155MetadataURI).interfaceId
|
|
|
- || super.supportsInterface(interfaceId);
|
|
|
+ return
|
|
|
+ interfaceId == type(IERC1155).interfaceId ||
|
|
|
+ interfaceId == type(IERC1155MetadataURI).interfaceId ||
|
|
|
+ super.supportsInterface(interfaceId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -77,10 +78,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
*
|
|
|
* - `accounts` and `ids` must have the same length.
|
|
|
*/
|
|
|
- function balanceOfBatch(
|
|
|
- address[] memory accounts,
|
|
|
- uint256[] memory ids
|
|
|
- )
|
|
|
+ function balanceOfBatch(address[] memory accounts, uint256[] memory ids)
|
|
|
public
|
|
|
view
|
|
|
virtual
|
|
@@ -124,11 +122,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
uint256 id,
|
|
|
uint256 amount,
|
|
|
bytes memory data
|
|
|
- )
|
|
|
- public
|
|
|
- virtual
|
|
|
- override
|
|
|
- {
|
|
|
+ ) public virtual override {
|
|
|
require(
|
|
|
from == _msgSender() || isApprovedForAll(from, _msgSender()),
|
|
|
"ERC1155: caller is not owner nor approved"
|
|
@@ -145,11 +139,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
uint256[] memory ids,
|
|
|
uint256[] memory amounts,
|
|
|
bytes memory data
|
|
|
- )
|
|
|
- public
|
|
|
- virtual
|
|
|
- override
|
|
|
- {
|
|
|
+ ) public virtual override {
|
|
|
require(
|
|
|
from == _msgSender() || isApprovedForAll(from, _msgSender()),
|
|
|
"ERC1155: transfer caller is not owner nor approved"
|
|
@@ -175,10 +165,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
uint256 id,
|
|
|
uint256 amount,
|
|
|
bytes memory data
|
|
|
- )
|
|
|
- internal
|
|
|
- virtual
|
|
|
- {
|
|
|
+ ) internal virtual {
|
|
|
require(to != address(0), "ERC1155: transfer to the zero address");
|
|
|
|
|
|
address operator = _msgSender();
|
|
@@ -213,10 +200,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
uint256[] memory ids,
|
|
|
uint256[] memory amounts,
|
|
|
bytes memory data
|
|
|
- )
|
|
|
- internal
|
|
|
- virtual
|
|
|
- {
|
|
|
+ ) internal virtual {
|
|
|
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
|
|
|
require(to != address(0), "ERC1155: transfer to the zero address");
|
|
|
|
|
@@ -275,7 +259,12 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
* - If `account` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
|
|
|
* acceptance magic value.
|
|
|
*/
|
|
|
- function _mint(address account, uint256 id, uint256 amount, bytes memory data) internal virtual {
|
|
|
+ function _mint(
|
|
|
+ address account,
|
|
|
+ uint256 id,
|
|
|
+ uint256 amount,
|
|
|
+ bytes memory data
|
|
|
+ ) internal virtual {
|
|
|
require(account != address(0), "ERC1155: mint to the zero address");
|
|
|
|
|
|
address operator = _msgSender();
|
|
@@ -297,7 +286,12 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
|
|
|
* acceptance magic value.
|
|
|
*/
|
|
|
- function _mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) internal virtual {
|
|
|
+ function _mintBatch(
|
|
|
+ address to,
|
|
|
+ uint256[] memory ids,
|
|
|
+ uint256[] memory amounts,
|
|
|
+ bytes memory data
|
|
|
+ ) internal virtual {
|
|
|
require(to != address(0), "ERC1155: mint to the zero address");
|
|
|
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
|
|
|
|
|
@@ -305,7 +299,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
|
|
|
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
|
|
|
|
|
|
- for (uint i = 0; i < ids.length; i++) {
|
|
|
+ for (uint256 i = 0; i < ids.length; i++) {
|
|
|
_balances[ids[i]][to] += amounts[i];
|
|
|
}
|
|
|
|
|
@@ -322,7 +316,11 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
* - `account` cannot be the zero address.
|
|
|
* - `account` must have at least `amount` tokens of token type `id`.
|
|
|
*/
|
|
|
- function _burn(address account, uint256 id, uint256 amount) internal virtual {
|
|
|
+ function _burn(
|
|
|
+ address account,
|
|
|
+ uint256 id,
|
|
|
+ uint256 amount
|
|
|
+ ) internal virtual {
|
|
|
require(account != address(0), "ERC1155: burn from the zero address");
|
|
|
|
|
|
address operator = _msgSender();
|
|
@@ -345,7 +343,11 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
*
|
|
|
* - `ids` and `amounts` must have the same length.
|
|
|
*/
|
|
|
- function _burnBatch(address account, uint256[] memory ids, uint256[] memory amounts) internal virtual {
|
|
|
+ function _burnBatch(
|
|
|
+ address account,
|
|
|
+ uint256[] memory ids,
|
|
|
+ uint256[] memory amounts
|
|
|
+ ) internal virtual {
|
|
|
require(account != address(0), "ERC1155: burn from the zero address");
|
|
|
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
|
|
|
|
|
@@ -353,7 +355,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
|
|
|
_beforeTokenTransfer(operator, account, address(0), ids, amounts, "");
|
|
|
|
|
|
- for (uint i = 0; i < ids.length; i++) {
|
|
|
+ for (uint256 i = 0; i < ids.length; i++) {
|
|
|
uint256 id = ids[i];
|
|
|
uint256 amount = amounts[i];
|
|
|
|
|
@@ -394,10 +396,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
uint256[] memory ids,
|
|
|
uint256[] memory amounts,
|
|
|
bytes memory data
|
|
|
- )
|
|
|
- internal
|
|
|
- virtual
|
|
|
- { }
|
|
|
+ ) internal virtual {}
|
|
|
|
|
|
function _doSafeTransferAcceptanceCheck(
|
|
|
address operator,
|
|
@@ -406,9 +405,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
uint256 id,
|
|
|
uint256 amount,
|
|
|
bytes memory data
|
|
|
- )
|
|
|
- private
|
|
|
- {
|
|
|
+ ) private {
|
|
|
if (to.isContract()) {
|
|
|
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
|
|
|
if (response != IERC1155Receiver(to).onERC1155Received.selector) {
|
|
@@ -429,11 +426,11 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
uint256[] memory ids,
|
|
|
uint256[] memory amounts,
|
|
|
bytes memory data
|
|
|
- )
|
|
|
- private
|
|
|
- {
|
|
|
+ ) private {
|
|
|
if (to.isContract()) {
|
|
|
- try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (bytes4 response) {
|
|
|
+ try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
|
|
|
+ bytes4 response
|
|
|
+ ) {
|
|
|
if (response != IERC1155Receiver(to).onERC1155BatchReceived.selector) {
|
|
|
revert("ERC1155: ERC1155Receiver rejected tokens");
|
|
|
}
|