update 721

This commit is contained in:
2022-11-17 11:15:58 +08:00
parent 90f0f87a61
commit 4afe97df7d
4 changed files with 44 additions and 93 deletions

View File

@@ -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/ERC1155Supply.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/utils/Strings.sol";
@@ -18,7 +18,7 @@ contract JZBG is
ERC1155Supply,
ERC1155URIStorage,
Ownable,
IERC1155Receiver
ERC1155Holder
{
using Strings for uint256;
@@ -45,41 +45,14 @@ contract JZBG is
return _symbol;
}
/**
* @dev 有这两个方法,才可以接收其他代币的转账进来
*/
function onERC1155Received(
address,
address,
uint256,
uint256,
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 supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC1155, ERC1155Receiver)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
function setURI(uint256 tokenId, string memory tokenURI)
@@ -243,6 +216,6 @@ contract JZBG is
override(ERC1155, ERC1155URIStorage)
returns (string memory)
{
return ERC1155URIStorage.uri(tokenId);
return super.uri(tokenId);
}
}

View File

@@ -3,19 +3,12 @@
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Pausable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "src/common/Pause.sol";
contract MyERC721 is
ERC721,
IERC721Receiver,
ERC721Enumerable,
ERC721Pausable,
ERC721Holder,
Ownable
{
contract MyERC721 is ERC721, ERC721Burnable, ERC721Holder, Ownable, Pause {
// onERC721Received
string private _address;
@@ -26,7 +19,7 @@ contract MyERC721 is
string memory symbol_,
string memory baseUri_
) ERC721(name_, symbol_) {
setBaseURI(baseUri_);
_setBaseURI(baseUri_);
}
/**
@@ -36,17 +29,6 @@ contract MyERC721 is
_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
*/
@@ -58,49 +40,23 @@ contract MyERC721 is
* @dev 设置TOKEN的URI
*/
function setBaseURI(string memory baseUri_) public virtual onlyOwner {
_setBaseURI(baseUri_);
}
function _setBaseURI(string memory baseUri_) internal virtual {
_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) {
return _baseUri;
}
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721, ERC721Enumerable)
returns (bool)
{
return ERC721Enumerable.supportsInterface(interfaceId);
}
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual override(ERC721, ERC721Enumerable, ERC721Pausable) {
ERC721Pausable._beforeTokenTransfer(from, to, firstTokenId, batchSize);
ERC721Enumerable._beforeTokenTransfer(
from,
to,
firstTokenId,
batchSize
);
) internal virtual override(ERC721, ERC721Pausable) {
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
}
}

22
src/common/Pause.sol Normal file
View 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();
}
}

View File

@@ -28,5 +28,5 @@ abstract contract Paymentable is Ownable {
/**
* @dev 这个是为了接收ETH转账用的
*/
receive() external payable {}
receive() external payable virtual {}
}