1155合约完成

This commit is contained in:
2022-11-09 12:01:09 +08:00
parent aac1979421
commit 441332e26d
2 changed files with 109 additions and 58 deletions

View File

@@ -958,7 +958,7 @@ abstract contract Ownable is Context {
}
}
contract JZBG1155 is
contract JZBG is
ERC1155,
ERC1155Burnable,
ERC1155Pausable,
@@ -969,6 +969,17 @@ contract JZBG1155 is
{
using Strings for uint256;
uint256 private _total;
uint256 private _count;
/**
* @dev Jing Zhong Bao Guo,JZBG,https://ipfs.jzbg.org/
* MINT: 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4,1,1234
* 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,1,1234567890
* TRANSFER: 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,0x5B38Da6a701c568545dCfcB03FcB875f56beddC4,1,5,0x
* mintBatch: 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,[1,2,3,4],[100,2000,30000,400000]
* safeTransferToAddresses: 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,[0x5B38Da6a701c568545dCfcB03FcB875f56beddC4,0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db,0x78731D3Ca6b7E34aC0F824c42a7cC18A495cabaB],1,200
*/
constructor(
string memory name_,
string memory symbol_,
@@ -989,53 +1000,56 @@ contract JZBG1155 is
_setBaseURI(baseURI);
}
/**
* @dev 获取所有的token发行总数
*/
function totalSupply() public view virtual returns (uint256) {
return _total;
}
/**
* @dev 获取已发行的TOKEN种类数量
*/
function tokenIdsTracker() public view virtual returns (uint256) {
return _count;
}
/**
* @dev 清空owner重写了防止误操作
*/
function renounceOwnership() public virtual override onlyOwner {}
/**
* @dev 增发
*/
function mint(
address to_,
uint256 tokenId_,
uint256 amount_,
string memory uri_
uint256 amount_
) public virtual onlyOwner {
_mint(to_, tokenId_, amount_, "");
if (bytes(uri_).length > 0) {
_setURI(tokenId_, uri_);
}
}
/**
* @dev 批量增发
*/
function bacthAddressMint(
address to_,
uint256[] memory tokenIds_,
uint256[] memory amounts_,
string[] memory uris_
) public virtual {
require(
tokenIds_.length == amounts_.length,
"The tokenIds and Amounts are not match"
);
if (uris_.length > 0) {
require(
tokenIds_.length == uris_.length,
"The ids and uris are not match"
);
}
uint256[] memory amounts_
) public virtual onlyOwner {
_mintBatch(to_, tokenIds_, amounts_, "");
if (uris_.length > 0) {
for (uint256 i = 0; i < tokenIds_.length; i++) {
_setURI(tokenIds_[i], uris_[i]);
}
}
}
/**
* @dev 批量给地址增发同一种代币
*/
function batchAddressesMint(
address[] memory tos_,
uint256 tokenId_,
uint256 amount_,
string memory uri_
) public virtual {
) public virtual onlyOwner {
for (uint256 i = 0; i < tos_.length; i++) {
_mint(tos_[i], tokenId_, amount_, "");
}
@@ -1045,6 +1059,9 @@ contract JZBG1155 is
}
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
*/
function safeTransferToAddresses(
address from_,
address[] memory tos_,
@@ -1067,10 +1084,16 @@ contract JZBG1155 is
}
}
/**
* @dev 暂停交易
*/
function pause() public virtual whenNotPaused onlyOwner {
_pause();
}
/**
* @dev 恢复交易
*/
function unpause() public virtual whenPaused onlyOwner {
_unpause();
}
@@ -1083,7 +1106,6 @@ contract JZBG1155 is
uint256[] memory amounts,
bytes memory data
) internal virtual override(ERC1155, ERC1155Supply, ERC1155Pausable) {
ERC1155._beforeTokenTransfer(operator, from, to, ids, amounts, data);
ERC1155Pausable._beforeTokenTransfer(
operator,
from,
@@ -1092,6 +1114,15 @@ contract JZBG1155 is
amounts,
data
);
// 记录增发数量
if (from == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
if (!ERC1155Supply.exists(ids[i])) {
_count++;
}
_total += amounts[i];
}
}
ERC1155Supply._beforeTokenTransfer(
operator,
from,
@@ -1100,6 +1131,15 @@ contract JZBG1155 is
amounts,
data
);
// 燃烧的时候减少数量
if (to == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
if (!ERC1155Supply.exists(ids[i])) {
_count--;
}
_total -= amounts[i];
}
}
}
function uri(uint256 tokenId)

View File

@@ -11,7 +11,7 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "../common/Symbolable.sol";
contract JZBG1155 is
contract JZBG is
ERC1155,
ERC1155Burnable,
ERC1155Pausable,
@@ -22,9 +22,12 @@ contract JZBG1155 is
{
using Strings for uint256;
uint256 private _total;
uint256 private _count;
/**
* @dev Jing Zhong Bao Guo,JZBG,https://jzbg.org/
* 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4,1,1234
* @dev Jing Zhong Bao Guo,JZBG,https://ipfs.jzbg.org/
* MINT: 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4,1,1234
* 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,1,1234567890
* TRANSFER: 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,0x5B38Da6a701c568545dCfcB03FcB875f56beddC4,1,5,0x
* mintBatch: 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,[1,2,3,4],[100,2000,30000,400000]
@@ -50,6 +53,20 @@ contract JZBG1155 is
_setBaseURI(baseURI);
}
/**
* @dev 获取所有的token发行总数
*/
function totalSupply() public view virtual returns (uint256) {
return _total;
}
/**
* @dev 获取已发行的TOKEN种类数量
*/
function tokenIdsTracker() public view virtual returns (uint256) {
return _count;
}
/**
* @dev 清空owner重写了防止误操作
*/
@@ -61,13 +78,9 @@ contract JZBG1155 is
function mint(
address to_,
uint256 tokenId_,
uint256 amount_,
string memory uri_
uint256 amount_
) public virtual onlyOwner {
_mint(to_, tokenId_, amount_, "");
if (bytes(uri_).length > 0) {
_setURI(tokenId_, uri_);
}
}
/**
@@ -76,28 +89,9 @@ contract JZBG1155 is
function bacthAddressMint(
address to_,
uint256[] memory tokenIds_,
uint256[] memory amounts_,
string[] memory uris_
uint256[] memory amounts_
) public virtual onlyOwner {
require(
tokenIds_.length == amounts_.length,
"The tokenIds and Amounts are not match"
);
if (uris_.length > 0) {
require(
tokenIds_.length == uris_.length,
"The ids and uris are not match"
);
}
_mintBatch(to_, tokenIds_, amounts_, "");
if (uris_.length > 0) {
for (uint256 i = 0; i < tokenIds_.length; i++) {
_setURI(tokenIds_[i], uris_[i]);
}
}
}
/**
@@ -165,7 +159,6 @@ contract JZBG1155 is
uint256[] memory amounts,
bytes memory data
) internal virtual override(ERC1155, ERC1155Supply, ERC1155Pausable) {
ERC1155._beforeTokenTransfer(operator, from, to, ids, amounts, data);
ERC1155Pausable._beforeTokenTransfer(
operator,
from,
@@ -174,6 +167,15 @@ contract JZBG1155 is
amounts,
data
);
// 记录增发数量
if (from == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
if (!ERC1155Supply.exists(ids[i])) {
_count++;
}
_total += amounts[i];
}
}
ERC1155Supply._beforeTokenTransfer(
operator,
from,
@@ -182,6 +184,15 @@ contract JZBG1155 is
amounts,
data
);
// 燃烧的时候减少数量
if (to == address(0)) {
for (uint256 i = 0; i < ids.length; ++i) {
if (!ERC1155Supply.exists(ids[i])) {
_count--;
}
_total -= amounts[i];
}
}
}
function uri(uint256 tokenId)