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

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