This commit is contained in:
2022-11-17 11:21:09 +08:00
parent 4afe97df7d
commit 3378a572a2
2 changed files with 133 additions and 16 deletions

View File

@@ -173,14 +173,7 @@ contract JZBG is
uint256[] memory amounts, uint256[] memory amounts,
bytes memory data bytes memory data
) internal virtual override(ERC1155, ERC1155Supply, ERC1155Pausable) { ) internal virtual override(ERC1155, ERC1155Supply, ERC1155Pausable) {
ERC1155Pausable._beforeTokenTransfer( super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
operator,
from,
to,
ids,
amounts,
data
);
// 记录增发数量 // 记录增发数量
if (from == address(0)) { if (from == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) { for (uint256 i = 0; i < ids.length; ++i) {
@@ -190,14 +183,7 @@ contract JZBG is
_total += amounts[i]; _total += amounts[i];
} }
} }
ERC1155Supply._beforeTokenTransfer(
operator,
from,
to,
ids,
amounts,
data
);
// 燃烧的时候减少数量 // 燃烧的时候减少数量
if (to == address(0)) { if (to == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) { for (uint256 i = 0; i < ids.length; ++i) {

131
src/ERC1155/MyERC1155.sol Normal file
View File

@@ -0,0 +1,131 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155URIStorage.sol";
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
contract MyERC1155 is
ERC1155,
ERC1155Burnable,
ERC1155Supply,
ERC1155URIStorage,
Ownable,
ERC1155Holder
{
using Strings for uint256;
string private _name;
string private _symbol;
constructor(
string memory name_,
string memory symbol_,
string memory uri_
) ERC1155(uri_) {
_name = name_;
_symbol = symbol_;
ERC1155URIStorage._setBaseURI(uri_);
}
function name() public view virtual returns (string memory) {
return _name;
}
function symbol() public view virtual returns (string memory) {
return _symbol;
}
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC1155, ERC1155Receiver)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
function setURI(uint256 tokenId, string memory tokenURI)
public
virtual
onlyOwner
{
_setURI(tokenId, tokenURI);
}
function setBaseURI(string memory baseURI) public virtual onlyOwner {
_setBaseURI(baseURI);
}
/**
* @dev 清空owner重写了防止误操作
*/
function renounceOwnership() public virtual override onlyOwner {}
/**
* @dev 增发
*/
function mint(
address to_,
uint256 tokenId_,
uint256 amount_
) public virtual onlyOwner {
_mint(to_, tokenId_, amount_, bytes(""));
}
/**
* @dev 批量增发
*/
function bacthAddressMint(
address to_,
uint256[] memory tokenIds_,
uint256[] memory amounts_
) public virtual onlyOwner {
_mintBatch(to_, tokenIds_, amounts_, "");
}
/**
* @dev 批量给地址增发同一种代币
*/
function batchAddressesMint(
address[] memory tos_,
uint256 tokenId_,
uint256 amount_,
string memory uri_
) public virtual onlyOwner {
for (uint256 i = 0; i < tos_.length; i++) {
_mint(tos_[i], tokenId_, amount_, "");
}
if (bytes(uri_).length > 0) {
_setURI(tokenId_, uri_);
}
}
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override(ERC1155, ERC1155Supply) {
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
}
function uri(uint256 tokenId)
public
view
virtual
override(ERC1155, ERC1155URIStorage)
returns (string memory)
{
return super.uri(tokenId);
}
}