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.

91 lines
3.3 KiB

1 year ago
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.19;
  3. import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
  4. import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
  5. import "./Utils.sol";
  6. contract NFT is ERC721Enumerable {
  7. address[] admins;
  8. address public deployAddress;
  9. bool first;
  10. address public pledgeAddress;
  11. uint256[] public blacks;
  12. constructor(string memory name,string memory symbol) ERC721(name,symbol) {
  13. require(first == false,"You can only use it once.");
  14. admins.push(msg.sender);
  15. deployAddress = msg.sender;
  16. first = true;
  17. }
  18. modifier onlyAdmin(){
  19. bool isAdmin = Utils.isAdmin(admins, msg.sender);
  20. require(isAdmin == true , "For administrators only");
  21. _;
  22. }
  23. modifier onlyNFTBlack(uint256 _tokenId){
  24. bool _isBlack = Utils.isNftBlacks(blacks, _tokenId);
  25. require(!_isBlack , "For administrators only");
  26. _;
  27. }
  28. function mint(address to, uint256 tokenId) external {
  29. require(msg.sender == pledgeAddress,"Only the Pledge Agreement can be used.");
  30. require(tokenId>0,"NFT ID must be greater than 0");
  31. _safeMint(to, tokenId);
  32. }
  33. function setPledgeAddress(address _pledgeAddr) external onlyAdmin{
  34. pledgeAddress = _pledgeAddr;
  35. }
  36. function addAdmin(address[] memory _adds) external onlyAdmin {
  37. require(_adds.length>0,"Must enter at least one address");
  38. require(deployAddress == msg.sender,"Can only be called by the contract deployer");
  39. for(uint256 i=0;i<_adds.length;i++){
  40. address _item = _adds[i];
  41. bool isExist = Utils.isAdmin(admins, _item);
  42. require(!isExist,"Address already exists");
  43. }
  44. address[] memory _admins = Utils.addAdmin(admins, _adds);
  45. admins = _admins;
  46. }
  47. function deleteAdmin(address[] memory _dels) external onlyAdmin {
  48. bool isDeploy = Utils.isAdmin(_dels, deployAddress);
  49. require(deployAddress == msg.sender,"Can only be called by the contract deployer");
  50. require(isDeploy == false,"Unable to delete contract deployers");
  51. require(_dels.length>0,"Must enter at least one address");
  52. address[] memory _admins = Utils.deleteAdmin(admins, _dels);
  53. admins = _admins;
  54. }
  55. function getAdmin() public view returns(address[] memory){
  56. return admins;
  57. }
  58. function addBlacks(uint256[] memory _tokenIds) external {
  59. require(msg.sender == pledgeAddress,"Only the Pledge Agreement can be used.");
  60. uint256[] memory _tokens = Utils.addNftBlacks(blacks,_tokenIds);
  61. blacks = _tokens;
  62. }
  63. function delBlacks(uint256[] memory _tokenIds) external {
  64. require(msg.sender == pledgeAddress,"Only the Pledge Agreement can be used.");
  65. uint256[] memory _tokens = Utils.deleteNftBlacks(blacks, _tokenIds);
  66. blacks = _tokens;
  67. }
  68. function getBlacks() public view returns(uint256[] memory){
  69. return blacks;
  70. }
  71. function _update(address to, uint256 tokenId, address auth) internal virtual override returns(address) {
  72. bool _isBlack = Utils.isNftBlacks(blacks, tokenId);
  73. require(!_isBlack,"Unable to Transfer, the NFT Tokend is blacklisted.");
  74. return super._update(to,tokenId,auth);
  75. }
  76. }