Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SPDX-License-Identifier: GPL-3.0
- pragma solidity >=0.8.15;
- import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; //reentrancy guard
- import "@openzeppelin/contracts/access/Ownable.sol"; //onlyOwner modifier
- import "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; //implements RBAC for its current token
- import "./Utilities.sol";
- import "./CustomNFT.sol";
- contract NFT_Platform is AccessControlEnumerable,ReentrancyGuard,Ownable
- {
- //Access Control Roles declaration
- bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); //has minting permissions (can create CustomNFT istances)
- bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE"); //has burn permissions (can burn custom NFTs)
- bytes32 public constant READER_ROLE = keccak256("READER_ROLE"); //has read permission about roles and CustomNFT objects
- bytes32 public constant LIMITED_ROLE = keccak256("LIMITED_ROLE"); //allows childNFTs to read Platform status such as permissions
- address[] public childNFT_address; //keep track of minted CustomNFT objects in the blockchain
- mapping(string => CustomNFT) private childNFT; //maps a readable contract name to the corresponding CustomNFT object
- event childContractMinted(string name, string symbol, address contract_name);
- constructor()
- {
- _setRoleAdmin(MINTER_ROLE,DEFAULT_ADMIN_ROLE); //should be ignorable
- _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
- _grantRole(READER_ROLE, msg.sender);
- _grantRole(BURNER_ROLE, msg.sender);
- }
- function deployCustomNFTCollection(string memory name, string memory symbol) public nonReentrant onlyRole(MINTER_ROLE) //mint new NFT Collection and keep track of child NFTs
- {
- require(!Utilities.compareStrings(name,""),"Name cannot be empty!");
- CustomNFT newContract = new CustomNFT(name,symbol,NFT_Platform(address(this))); //NFT_Platform type-casted proxy address to be inserted later as father contract
- //tracking contracts creation
- childNFT_address.push(address(newContract));
- childNFT[name] = newContract;
- _grantRole(LIMITED_ROLE, address(newContract)); //allows contracts to call hasPermission, see LIMITED_ROLE comment
- emit childContractMinted(name,symbol,address(newContract)); //notifies when a CustomNFT contract is deployed on the network
- }
- function getChildContract(string memory contract_name) public view onlyRole(READER_ROLE) returns(CustomNFT)
- {
- require(address(childNFT[contract_name]) != address(0),"No names associated with this address!"); //check for contract existence
- require(childNFT[contract_name].owner() == address(this), "Contract not deployed by this father contract!"); //check for correct ownership in the blockchain
- return childNFT[contract_name];
- }
- function getPrivilegedAccounts(string memory role) public view onlyRole(READER_ROLE) returns(address[] memory)
- {
- bytes32 role_bytes = keccak256(abi.encodePacked(role));
- address[] memory members = new address[](getRoleMemberCount(role_bytes));
- for(uint i=0; i < getRoleMemberCount(role_bytes); i ++) { members[i] = getRoleMember(role_bytes,i); }
- return members;
- }
- 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
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement