update 721
This commit is contained in:
@@ -7,7 +7,7 @@ import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
|
|||||||
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Pausable.sol";
|
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Pausable.sol";
|
||||||
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
|
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
|
||||||
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155URIStorage.sol";
|
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155URIStorage.sol";
|
||||||
import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
|
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
|
||||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||||
import "@openzeppelin/contracts/utils/Strings.sol";
|
import "@openzeppelin/contracts/utils/Strings.sol";
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ contract JZBG is
|
|||||||
ERC1155Supply,
|
ERC1155Supply,
|
||||||
ERC1155URIStorage,
|
ERC1155URIStorage,
|
||||||
Ownable,
|
Ownable,
|
||||||
IERC1155Receiver
|
ERC1155Holder
|
||||||
{
|
{
|
||||||
using Strings for uint256;
|
using Strings for uint256;
|
||||||
|
|
||||||
@@ -45,41 +45,14 @@ contract JZBG is
|
|||||||
return _symbol;
|
return _symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function supportsInterface(bytes4 interfaceId)
|
||||||
* @dev 有这两个方法,才可以接收其他代币的转账进来
|
public
|
||||||
*/
|
view
|
||||||
function onERC1155Received(
|
virtual
|
||||||
address,
|
override(ERC1155, ERC1155Receiver)
|
||||||
address,
|
returns (bool)
|
||||||
uint256,
|
{
|
||||||
uint256,
|
return super.supportsInterface(interfaceId);
|
||||||
bytes calldata
|
|
||||||
) public view virtual override returns (bytes4) {
|
|
||||||
return IERC1155Receiver.onERC1155Received.selector;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev 有这两个方法,才可以接收其他代币的转账进来
|
|
||||||
*/
|
|
||||||
function onERC1155BatchReceived(
|
|
||||||
address,
|
|
||||||
address,
|
|
||||||
uint256[] calldata,
|
|
||||||
uint256[] calldata,
|
|
||||||
bytes calldata
|
|
||||||
) public view virtual override returns (bytes4) {
|
|
||||||
return IERC1155Receiver.onERC1155BatchReceived.selector;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev 从合约中转出NFT
|
|
||||||
*/
|
|
||||||
function tranferNFT(
|
|
||||||
address to,
|
|
||||||
uint256 tokenId,
|
|
||||||
uint256 amount
|
|
||||||
) public virtual onlyOwner {
|
|
||||||
_safeTransferFrom(address(this), to, tokenId, amount, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setURI(uint256 tokenId, string memory tokenURI)
|
function setURI(uint256 tokenId, string memory tokenURI)
|
||||||
@@ -243,6 +216,6 @@ contract JZBG is
|
|||||||
override(ERC1155, ERC1155URIStorage)
|
override(ERC1155, ERC1155URIStorage)
|
||||||
returns (string memory)
|
returns (string memory)
|
||||||
{
|
{
|
||||||
return ERC1155URIStorage.uri(tokenId);
|
return super.uri(tokenId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,19 +3,12 @@
|
|||||||
pragma solidity ^0.8.0;
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
|
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
|
||||||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
|
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
|
||||||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Pausable.sol";
|
|
||||||
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
|
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
|
||||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||||
|
import "src/common/Pause.sol";
|
||||||
|
|
||||||
contract MyERC721 is
|
contract MyERC721 is ERC721, ERC721Burnable, ERC721Holder, Ownable, Pause {
|
||||||
ERC721,
|
|
||||||
IERC721Receiver,
|
|
||||||
ERC721Enumerable,
|
|
||||||
ERC721Pausable,
|
|
||||||
ERC721Holder,
|
|
||||||
Ownable
|
|
||||||
{
|
|
||||||
// onERC721Received
|
// onERC721Received
|
||||||
string private _address;
|
string private _address;
|
||||||
|
|
||||||
@@ -26,7 +19,7 @@ contract MyERC721 is
|
|||||||
string memory symbol_,
|
string memory symbol_,
|
||||||
string memory baseUri_
|
string memory baseUri_
|
||||||
) ERC721(name_, symbol_) {
|
) ERC721(name_, symbol_) {
|
||||||
setBaseURI(baseUri_);
|
_setBaseURI(baseUri_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,17 +29,6 @@ contract MyERC721 is
|
|||||||
_safeMint(to, tokenId);
|
_safeMint(to, tokenId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev 燃烧NFT
|
|
||||||
*/
|
|
||||||
function burn(uint256 tokenId) public virtual {
|
|
||||||
require(
|
|
||||||
_isApprovedOrOwner(_msgSender(), tokenId),
|
|
||||||
"ERC721: caller is not token owner or approved"
|
|
||||||
);
|
|
||||||
_burn(tokenId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev 从合约中转出NFT
|
* @dev 从合约中转出NFT
|
||||||
*/
|
*/
|
||||||
@@ -58,49 +40,23 @@ contract MyERC721 is
|
|||||||
* @dev 设置TOKEN的URI
|
* @dev 设置TOKEN的URI
|
||||||
*/
|
*/
|
||||||
function setBaseURI(string memory baseUri_) public virtual onlyOwner {
|
function setBaseURI(string memory baseUri_) public virtual onlyOwner {
|
||||||
|
_setBaseURI(baseUri_);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _setBaseURI(string memory baseUri_) internal virtual {
|
||||||
_baseUri = baseUri_;
|
_baseUri = baseUri_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev 暂停交易
|
|
||||||
*/
|
|
||||||
function pause() public virtual onlyOwner {
|
|
||||||
_pause();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev 解除暂停
|
|
||||||
*/
|
|
||||||
function unpause() public virtual onlyOwner {
|
|
||||||
_unpause();
|
|
||||||
}
|
|
||||||
|
|
||||||
function _baseURI() internal view virtual override returns (string memory) {
|
function _baseURI() internal view virtual override returns (string memory) {
|
||||||
return _baseUri;
|
return _baseUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
function supportsInterface(bytes4 interfaceId)
|
|
||||||
public
|
|
||||||
view
|
|
||||||
virtual
|
|
||||||
override(ERC721, ERC721Enumerable)
|
|
||||||
returns (bool)
|
|
||||||
{
|
|
||||||
return ERC721Enumerable.supportsInterface(interfaceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
function _beforeTokenTransfer(
|
function _beforeTokenTransfer(
|
||||||
address from,
|
address from,
|
||||||
address to,
|
address to,
|
||||||
uint256 firstTokenId,
|
uint256 firstTokenId,
|
||||||
uint256 batchSize
|
uint256 batchSize
|
||||||
) internal virtual override(ERC721, ERC721Enumerable, ERC721Pausable) {
|
) internal virtual override(ERC721, ERC721Pausable) {
|
||||||
ERC721Pausable._beforeTokenTransfer(from, to, firstTokenId, batchSize);
|
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
|
||||||
ERC721Enumerable._beforeTokenTransfer(
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
firstTokenId,
|
|
||||||
batchSize
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
src/common/Pause.sol
Normal file
22
src/common/Pause.sol
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Pausable.sol";
|
||||||
|
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||||
|
|
||||||
|
abstract contract Pause is ERC721Pausable, Ownable {
|
||||||
|
/**
|
||||||
|
* @dev 暂停交易
|
||||||
|
*/
|
||||||
|
function pause() public virtual onlyOwner {
|
||||||
|
_pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev 解除暂停
|
||||||
|
*/
|
||||||
|
function unpause() public virtual onlyOwner {
|
||||||
|
_unpause();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,5 +28,5 @@ abstract contract Paymentable is Ownable {
|
|||||||
/**
|
/**
|
||||||
* @dev 这个是为了接收ETH转账用的
|
* @dev 这个是为了接收ETH转账用的
|
||||||
*/
|
*/
|
||||||
receive() external payable {}
|
receive() external payable virtual {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user