编译器
0.8.18+commit.87f61d96
文件 1 的 5:CoverNFT.sol
pragma solidity ^0.8.18;
import "../../interfaces/ICoverNFT.sol";
import "../../interfaces/ICoverNFTDescriptor.sol";
contract CoverNFT is ICoverNFT {
string public name;
string public symbol;
mapping(uint => address) internal _ownerOf;
mapping(address => uint) internal _balanceOf;
mapping(uint => address) public getApproved;
mapping(address => mapping(address => bool)) public isApprovedForAll;
uint96 internal _totalSupply;
address public operator;
address public nftDescriptor;
modifier onlyOperator {
if (msg.sender != operator) revert NotOperator();
_;
}
constructor(
string memory _name,
string memory _symbol,
address _operator,
address _nftDescriptor
) {
name = _name;
symbol = _symbol;
operator = _operator;
nftDescriptor = _nftDescriptor;
}
function changeOperator(address _newOperator) public onlyOperator {
if (_newOperator == address(0)) revert InvalidNewOperatorAddress();
operator = _newOperator;
}
function changeNFTDescriptor(address _newNFTDescriptor) public onlyOperator {
if (_newNFTDescriptor == address(0)) revert InvalidNewNFTDescriptorAddress();
nftDescriptor = _newNFTDescriptor;
}
function mint(address to) external onlyOperator returns (uint id) {
if (to == address(0)) revert InvalidRecipient();
unchecked {
id = ++_totalSupply;
_balanceOf[to]++;
}
_ownerOf[id] = to;
emit Transfer(address(0), to, id);
}
function totalSupply() public view returns (uint) {
return _totalSupply;
}
function supportsInterface(bytes4 interfaceId) public pure returns (bool) {
return
interfaceId == 0x01ffc9a7 ||
interfaceId == 0x80ac58cd ||
interfaceId == 0x5b5e139f;
}
function tokenURI(uint id) public view virtual returns (string memory uri) {
if (_ownerOf[id] == address(0)) revert NotMinted();
return ICoverNFTDescriptor(nftDescriptor).tokenURI(id);
}
function ownerOf(uint id) public view returns (address owner) {
if ((owner = _ownerOf[id]) == address(0)) revert NotMinted();
}
function balanceOf(address owner) public view returns (uint) {
if (owner == address(0)) revert NotMinted();
return _balanceOf[owner];
}
function approve(address spender, uint id) public {
address owner = _ownerOf[id];
if (msg.sender != owner && !isApprovedForAll[owner][msg.sender]) revert NotAuthorized();
getApproved[id] = spender;
emit Approval(owner, spender, id);
}
function setApprovalForAll(address spender, bool approved) public {
isApprovedForAll[msg.sender][spender] = approved;
emit ApprovalForAll(msg.sender, spender, approved);
}
function isApprovedOrOwner(address spender, uint tokenId) external view returns (bool) {
address owner = ownerOf(tokenId);
return spender == owner || isApprovedForAll[owner][spender] || spender == getApproved[tokenId];
}
function transferFrom(address from, address to, uint id) public {
if (from != _ownerOf[id]) revert WrongFrom();
if (to == address(0)) revert InvalidRecipient();
if (msg.sender != from && !isApprovedForAll[from][msg.sender] && msg.sender != getApproved[id]) {
revert NotAuthorized();
}
unchecked {
_balanceOf[from]--;
_balanceOf[to]++;
}
_ownerOf[id] = to;
delete getApproved[id];
emit Transfer(from, to, id);
}
function safeTransferFrom(address from, address to, uint id) public {
transferFrom(from, to, id);
if (to.code.length != 0 && ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, "") != ERC721TokenReceiver.onERC721Received.selector) {
revert UnsafeRecipient();
}
}
function safeTransferFrom(
address from,
address to,
uint id,
bytes calldata data
) public {
transferFrom(from, to, id);
if (to.code.length != 0 && ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, data) != ERC721TokenReceiver.onERC721Received.selector) {
revert UnsafeRecipient();
}
}
}
abstract contract ERC721TokenReceiver {
function onERC721Received(address, address, uint, bytes calldata) external virtual returns
(bytes4) {
return ERC721TokenReceiver.onERC721Received.selector;
}
}
文件 2 的 5:ICoverNFT.sol
pragma solidity >=0.5.0;
import "@openzeppelin/contracts-v4/token/ERC721/IERC721.sol";
interface ICoverNFT is IERC721 {
function isApprovedOrOwner(address spender, uint tokenId) external returns (bool);
function mint(address to) external returns (uint tokenId);
function changeOperator(address newOperator) external;
function totalSupply() external view returns (uint);
function name() external view returns (string memory);
error NotOperator();
error NotMinted();
error WrongFrom();
error InvalidRecipient();
error InvalidNewOperatorAddress();
error InvalidNewNFTDescriptorAddress();
error NotAuthorized();
error UnsafeRecipient();
error AlreadyMinted();
}
文件 3 的 5:ICoverNFTDescriptor.sol
pragma solidity >=0.5.0;
interface ICoverNFTDescriptor {
function tokenURI(uint tokenId) external view returns (string memory);
}
文件 4 的 5:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 5 的 5:IERC721.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function approve(address to, uint256 tokenId) external;
function setApprovalForAll(address operator, bool _approved) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
{
"compilationTarget": {
"contracts/modules/cover/CoverNFT.sol": "CoverNFT"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"address","name":"_operator","type":"address"},{"internalType":"address","name":"_nftDescriptor","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyMinted","type":"error"},{"inputs":[],"name":"InvalidNewNFTDescriptorAddress","type":"error"},{"inputs":[],"name":"InvalidNewOperatorAddress","type":"error"},{"inputs":[],"name":"InvalidRecipient","type":"error"},{"inputs":[],"name":"NotAuthorized","type":"error"},{"inputs":[],"name":"NotMinted","type":"error"},{"inputs":[],"name":"NotOperator","type":"error"},{"inputs":[],"name":"UnsafeRecipient","type":"error"},{"inputs":[],"name":"WrongFrom","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newNFTDescriptor","type":"address"}],"name":"changeNFTDescriptor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newOperator","type":"address"}],"name":"changeOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"isApprovedOrOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nftDescriptor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"owner","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"uri","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"}]