wip: refactor on current nft contract
This commit is contained in:
parent
3a316a6fea
commit
3f37d82aca
|
|
@ -4,38 +4,22 @@ pragma solidity ^0.8.7;
|
||||||
|
|
||||||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
|
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
|
||||||
import "@openzeppelin/contracts/utils/Counters.sol";
|
import "@openzeppelin/contracts/utils/Counters.sol";
|
||||||
import "@openzeppelin/contracts/access/AccessControl.sol";
|
import "./FleekAccessControl.sol";
|
||||||
import "../interfaces/ISitesNFTs.sol";
|
import "../interfaces/ISitesNFTs.sol";
|
||||||
|
|
||||||
contract SitesNFTs is ISitesNFTs, ERC721URIStorage, AccessControl {
|
contract SitesNFTs is ISitesNFTs, ERC721URIStorage, FleekAccessControl {
|
||||||
using Counters for Counters.Counter;
|
using Counters for Counters.Counter;
|
||||||
Counters.Counter private _tokenIds;
|
Counters.Counter private _tokenIds;
|
||||||
string private baseURI;
|
|
||||||
|
|
||||||
bytes32 public constant MINTER_ROLE =
|
constructor(
|
||||||
0x4d494e5445525f524f4c45000000000000000000000000000000000000000000; // "MINTER_ROLE"
|
string memory name,
|
||||||
|
string memory symbol
|
||||||
modifier canMint() {
|
) ERC721(name, symbol) {}
|
||||||
bool isMinterOrAdmin = hasRole(MINTER_ROLE, msg.sender) ||
|
|
||||||
hasRole(DEFAULT_ADMIN_ROLE, msg.sender);
|
|
||||||
require(isMinterOrAdmin, "Caller has no permission to mint.");
|
|
||||||
_;
|
|
||||||
}
|
|
||||||
|
|
||||||
modifier canChangeBaseURI() {
|
|
||||||
require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender));
|
|
||||||
_;
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(string memory name, string memory symbol) ERC721(name, symbol) {
|
|
||||||
baseURI = "data:application/json;base64,";
|
|
||||||
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
function mint(
|
function mint(
|
||||||
string memory base64EncodedMetadata,
|
string memory base64EncodedMetadata,
|
||||||
address account
|
address account
|
||||||
) public override canMint returns (uint256) {
|
) public override requireController returns (uint256) {
|
||||||
uint256 newItemId = _tokenIds.current();
|
uint256 newItemId = _tokenIds.current();
|
||||||
_safeMint(account, newItemId);
|
_safeMint(account, newItemId);
|
||||||
_setTokenURI(newItemId, base64EncodedMetadata);
|
_setTokenURI(newItemId, base64EncodedMetadata);
|
||||||
|
|
@ -48,7 +32,7 @@ contract SitesNFTs is ISitesNFTs, ERC721URIStorage, AccessControl {
|
||||||
address tokenHolderAddress,
|
address tokenHolderAddress,
|
||||||
uint256 tokenId,
|
uint256 tokenId,
|
||||||
string memory base64EncodedMetadata
|
string memory base64EncodedMetadata
|
||||||
) public override canMint {
|
) public override requireController {
|
||||||
address tokenOwner = ownerOf(tokenId);
|
address tokenOwner = ownerOf(tokenId);
|
||||||
require(
|
require(
|
||||||
tokenOwner == tokenHolderAddress,
|
tokenOwner == tokenHolderAddress,
|
||||||
|
|
@ -57,6 +41,10 @@ contract SitesNFTs is ISitesNFTs, ERC721URIStorage, AccessControl {
|
||||||
_setTokenURI(tokenId, base64EncodedMetadata);
|
_setTokenURI(tokenId, base64EncodedMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCurrentTokenId() public view override returns (uint256) {
|
||||||
|
return _tokenIds.current();
|
||||||
|
}
|
||||||
|
|
||||||
function supportsInterface(
|
function supportsInterface(
|
||||||
bytes4 interfaceId
|
bytes4 interfaceId
|
||||||
)
|
)
|
||||||
|
|
@ -68,19 +56,4 @@ contract SitesNFTs is ISitesNFTs, ERC721URIStorage, AccessControl {
|
||||||
{
|
{
|
||||||
return super.supportsInterface(interfaceId);
|
return super.supportsInterface(interfaceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setBaseURI(
|
|
||||||
string memory _newBbaseURI
|
|
||||||
) public override canChangeBaseURI returns (string memory) {
|
|
||||||
baseURI = _newBbaseURI;
|
|
||||||
return baseURI;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCurrentTokenId() public view override returns (uint256) {
|
|
||||||
return _tokenIds.current();
|
|
||||||
}
|
|
||||||
|
|
||||||
function _baseURI() internal view override returns (string memory) {
|
|
||||||
return baseURI;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,12 @@ import "@openzeppelin/contracts/access/IAccessControl.sol";
|
||||||
/// @title SitesNFTs - A contract for managing sites NFTs
|
/// @title SitesNFTs - A contract for managing sites NFTs
|
||||||
/// @dev See
|
/// @dev See
|
||||||
interface ISitesNFTs is IERC721 {
|
interface ISitesNFTs is IERC721 {
|
||||||
|
enum FleekContract {
|
||||||
|
Site
|
||||||
|
}
|
||||||
|
|
||||||
function mint(
|
function mint(
|
||||||
|
FleekContract memory fleekContract,
|
||||||
string memory base64EncodedMetadata,
|
string memory base64EncodedMetadata,
|
||||||
address account
|
address account
|
||||||
) external returns (uint256);
|
) external returns (uint256);
|
||||||
|
|
@ -19,9 +24,5 @@ interface ISitesNFTs is IERC721 {
|
||||||
string memory base64EncodedMetadata
|
string memory base64EncodedMetadata
|
||||||
) external;
|
) external;
|
||||||
|
|
||||||
function setBaseURI(
|
|
||||||
string memory _newBbaseURI
|
|
||||||
) external returns (string memory);
|
|
||||||
|
|
||||||
function getCurrentTokenId() external view returns (uint256);
|
function getCurrentTokenId() external view returns (uint256);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue