You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.5 KiB
101 lines
3.5 KiB
// SPDX-License-Identifier: MIT
|
|
pragma solidity ^0.8.19;
|
|
|
|
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
|
|
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
|
|
import "./Utils.sol";
|
|
|
|
contract NFT is ERC721Enumerable {
|
|
address[] admins;
|
|
address public deployAddress;
|
|
bool first;
|
|
address public pledgeAddress;
|
|
uint256[] public blacks;
|
|
string public baseURI;
|
|
|
|
constructor(string memory name,string memory symbol,string memory uri) ERC721(name,symbol) {
|
|
require(first == false,"You can only use it once.");
|
|
admins.push(msg.sender);
|
|
deployAddress = msg.sender;
|
|
first = true;
|
|
baseURI = uri;
|
|
}
|
|
|
|
modifier onlyAdmin(){
|
|
bool isAdmin = Utils.isAdmin(admins, msg.sender);
|
|
require(isAdmin == true , "For administrators only");
|
|
_;
|
|
}
|
|
|
|
modifier onlyNFTBlack(uint256 _tokenId){
|
|
bool _isBlack = Utils.isNftBlacks(blacks, _tokenId);
|
|
require(!_isBlack , "For administrators only");
|
|
_;
|
|
}
|
|
|
|
function mint(address to, uint256 tokenId) external {
|
|
require(msg.sender == pledgeAddress,"Only the Pledge Agreement can be used.");
|
|
require(tokenId>0,"NFT ID must be greater than 0");
|
|
_safeMint(to, tokenId);
|
|
}
|
|
|
|
function setPledgeAddress(address _pledgeAddr) external onlyAdmin{
|
|
pledgeAddress = _pledgeAddr;
|
|
}
|
|
|
|
function addAdmin(address[] memory _adds) external onlyAdmin {
|
|
require(_adds.length>0,"Must enter at least one address");
|
|
require(deployAddress == msg.sender,"Can only be called by the contract deployer");
|
|
for(uint256 i=0;i<_adds.length;i++){
|
|
address _item = _adds[i];
|
|
bool isExist = Utils.isAdmin(admins, _item);
|
|
require(!isExist,"Address already exists");
|
|
}
|
|
address[] memory _admins = Utils.addAdmin(admins, _adds);
|
|
admins = _admins;
|
|
}
|
|
|
|
function deleteAdmin(address[] memory _dels) external onlyAdmin {
|
|
bool isDeploy = Utils.isAdmin(_dels, deployAddress);
|
|
require(deployAddress == msg.sender,"Can only be called by the contract deployer");
|
|
require(isDeploy == false,"Unable to delete contract deployers");
|
|
require(_dels.length>0,"Must enter at least one address");
|
|
address[] memory _admins = Utils.deleteAdmin(admins, _dels);
|
|
admins = _admins;
|
|
}
|
|
|
|
function setBaseURI(string memory _uri) external onlyAdmin {
|
|
baseURI = _uri;
|
|
}
|
|
|
|
function getAdmin() public view returns(address[] memory){
|
|
return admins;
|
|
}
|
|
|
|
function addBlacks(uint256[] memory _tokenIds) external {
|
|
require(msg.sender == pledgeAddress,"Only the Pledge Agreement can be used.");
|
|
uint256[] memory _tokens = Utils.addNftBlacks(blacks,_tokenIds);
|
|
blacks = _tokens;
|
|
}
|
|
|
|
function delBlacks(uint256[] memory _tokenIds) external {
|
|
require(msg.sender == pledgeAddress,"Only the Pledge Agreement can be used.");
|
|
uint256[] memory _tokens = Utils.deleteNftBlacks(blacks, _tokenIds);
|
|
blacks = _tokens;
|
|
}
|
|
|
|
function getBlacks() public view returns(uint256[] memory){
|
|
return blacks;
|
|
}
|
|
|
|
function _update(address to, uint256 tokenId, address auth) internal virtual override returns(address) {
|
|
bool _isBlack = Utils.isNftBlacks(blacks, tokenId);
|
|
require(!_isBlack,"Unable to Transfer, the NFT Tokend is blacklisted.");
|
|
return super._update(to,tokenId,auth);
|
|
}
|
|
|
|
function tokenURI(uint256 tokenId) public view override returns (string memory) {
|
|
return baseURI;
|
|
}
|
|
|
|
}
|