Advertisement
Infinity99HD

Untitled

Jul 31st, 2022
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // SPDX-License-Identifier: GPL-3.0
  2. pragma solidity >=0.8.15;
  3.  
  4. import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; //reentrancy guard
  5. import "@openzeppelin/contracts/access/Ownable.sol"; //onlyOwner modifier
  6. import "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; //implements RBAC for its current token
  7. import "./Utilities.sol";
  8. import "./CustomNFT.sol";
  9.  
  10. contract NFT_Platform is AccessControlEnumerable,ReentrancyGuard,Ownable
  11. {
  12.  
  13.     //Access Control Roles declaration
  14.     bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); //has minting permissions (can create CustomNFT istances)
  15.     bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE"); //has burn permissions (can burn custom NFTs)
  16.     bytes32 public constant READER_ROLE = keccak256("READER_ROLE"); //has read permission about roles and CustomNFT objects
  17.     bytes32 public constant LIMITED_ROLE = keccak256("LIMITED_ROLE"); //allows childNFTs to read Platform status such as permissions
  18.  
  19.     address[] public childNFT_address; //keep track of minted CustomNFT objects in the blockchain
  20.     mapping(string => CustomNFT) private childNFT; //maps a readable contract name to the corresponding CustomNFT object
  21.  
  22.     event childContractMinted(string name, string symbol, address contract_name);
  23.  
  24.     constructor()  
  25.     {    
  26.         _setRoleAdmin(MINTER_ROLE,DEFAULT_ADMIN_ROLE); //should be ignorable
  27.         _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
  28.         _grantRole(READER_ROLE, msg.sender);
  29.         _grantRole(BURNER_ROLE, msg.sender);
  30.     }
  31.  
  32.     function deployCustomNFTCollection(string memory name, string memory symbol) public nonReentrant onlyRole(MINTER_ROLE) //mint new NFT Collection and keep track of child NFTs
  33.     {
  34.         require(!Utilities.compareStrings(name,""),"Name cannot be empty!");
  35.  
  36.         CustomNFT newContract = new CustomNFT(name,symbol,NFT_Platform(address(this))); //NFT_Platform type-casted proxy address to be inserted later as father contract
  37.  
  38.         //tracking contracts creation
  39.         childNFT_address.push(address(newContract));
  40.         childNFT[name] = newContract;
  41.         _grantRole(LIMITED_ROLE, address(newContract)); //allows contracts to call hasPermission, see LIMITED_ROLE comment
  42.  
  43.         emit childContractMinted(name,symbol,address(newContract)); //notifies when a CustomNFT contract is deployed on the network
  44.     }
  45.  
  46.     function getChildContract(string memory contract_name) public view onlyRole(READER_ROLE) returns(CustomNFT)
  47.     {
  48.         require(address(childNFT[contract_name]) != address(0),"No names associated with this address!"); //check for contract existence
  49.         require(childNFT[contract_name].owner() == address(this), "Contract not deployed by this father contract!"); //check for correct ownership in the blockchain
  50.  
  51.         return childNFT[contract_name];
  52.     }
  53.  
  54.     function getPrivilegedAccounts(string memory role) public view onlyRole(READER_ROLE) returns(address[] memory)
  55.     {
  56.         bytes32 role_bytes = keccak256(abi.encodePacked(role));
  57.  
  58.         address[] memory members = new address[](getRoleMemberCount(role_bytes));
  59.         for(uint i=0; i < getRoleMemberCount(role_bytes); i ++) { members[i] = getRoleMember(role_bytes,i); }
  60.  
  61.         return members;
  62.     }
  63.  
  64.     function hasPermission(bytes32 role, address contract_name) public view onlyRole(LIMITED_ROLE) returns(bool) { return hasRole(role,contract_name); } //used by child contracts in order to check permissions
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement