chore: remove counters library from the contract code. (#137)
* chore: remove the counters lib from the contract and create private vars instead. * merge: develop. fix conflicts. * style: remove unnecessary white space
This commit is contained in:
parent
d7841717ff
commit
b3b9f30f05
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
pragma solidity ^0.8.7;
|
pragma solidity ^0.8.7;
|
||||||
|
|
||||||
import "@openzeppelin/contracts/utils/Counters.sol";
|
|
||||||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
||||||
|
|
||||||
error MustHaveCollectionRole(uint8 role);
|
error MustHaveCollectionRole(uint8 role);
|
||||||
|
|
@ -11,7 +10,6 @@ error MustHaveAtLeastOneOwner();
|
||||||
error RoleAlreadySet();
|
error RoleAlreadySet();
|
||||||
|
|
||||||
contract FleekAccessControl is Initializable {
|
contract FleekAccessControl is Initializable {
|
||||||
using Counters for Counters.Counter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev All available collection roles.
|
* @dev All available collection roles.
|
||||||
|
|
@ -57,7 +55,7 @@ contract FleekAccessControl is Initializable {
|
||||||
* @dev _collectionRolesCounter[role] is the number of addresses that have the role.
|
* @dev _collectionRolesCounter[role] is the number of addresses that have the role.
|
||||||
* This is prevent Owner role to go to 0.
|
* This is prevent Owner role to go to 0.
|
||||||
*/
|
*/
|
||||||
mapping(CollectionRoles => Counters.Counter) private _collectionRolesCounter;
|
mapping(CollectionRoles => uint256) private _collectionRolesCounter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev _collectionRoles[role][address] is the mapping of addresses that have the role.
|
* @dev _collectionRoles[role][address] is the mapping of addresses that have the role.
|
||||||
|
|
@ -69,7 +67,7 @@ contract FleekAccessControl is Initializable {
|
||||||
* The version is incremented every time the token roles are cleared.
|
* The version is incremented every time the token roles are cleared.
|
||||||
* Should be incremented every token transfer.
|
* Should be incremented every token transfer.
|
||||||
*/
|
*/
|
||||||
mapping(uint256 => Counters.Counter) private _tokenRolesVersion;
|
mapping(uint256 => uint256) private _tokenRolesVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev _tokenRoles[tokenId][version][role][address] is the mapping of addresses that have the role.
|
* @dev _tokenRoles[tokenId][version][role][address] is the mapping of addresses that have the role.
|
||||||
|
|
@ -108,7 +106,7 @@ contract FleekAccessControl is Initializable {
|
||||||
* @dev Returns `True` if a certain address has the token role.
|
* @dev Returns `True` if a certain address has the token role.
|
||||||
*/
|
*/
|
||||||
function hasTokenRole(uint256 tokenId, TokenRoles role, address account) public view returns (bool) {
|
function hasTokenRole(uint256 tokenId, TokenRoles role, address account) public view returns (bool) {
|
||||||
uint256 currentVersion = _tokenRolesVersion[tokenId].current();
|
uint256 currentVersion = _tokenRolesVersion[tokenId];
|
||||||
return _tokenRoles[tokenId][currentVersion][role][account];
|
return _tokenRoles[tokenId][currentVersion][role][account];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +117,7 @@ contract FleekAccessControl is Initializable {
|
||||||
if (hasCollectionRole(role, account)) revert RoleAlreadySet();
|
if (hasCollectionRole(role, account)) revert RoleAlreadySet();
|
||||||
|
|
||||||
_collectionRoles[role][account] = true;
|
_collectionRoles[role][account] = true;
|
||||||
_collectionRolesCounter[role].increment();
|
_collectionRolesCounter[role] += 1;
|
||||||
|
|
||||||
emit CollectionRoleChanged(role, account, true, msg.sender);
|
emit CollectionRoleChanged(role, account, true, msg.sender);
|
||||||
}
|
}
|
||||||
|
|
@ -129,11 +127,11 @@ contract FleekAccessControl is Initializable {
|
||||||
*/
|
*/
|
||||||
function _revokeCollectionRole(CollectionRoles role, address account) internal {
|
function _revokeCollectionRole(CollectionRoles role, address account) internal {
|
||||||
if (!hasCollectionRole(role, account)) revert RoleAlreadySet();
|
if (!hasCollectionRole(role, account)) revert RoleAlreadySet();
|
||||||
if (role == CollectionRoles.Owner && _collectionRolesCounter[role].current() == 1)
|
if (role == CollectionRoles.Owner && _collectionRolesCounter[role] == 1)
|
||||||
revert MustHaveAtLeastOneOwner();
|
revert MustHaveAtLeastOneOwner();
|
||||||
|
|
||||||
_collectionRoles[role][account] = false;
|
_collectionRoles[role][account] = false;
|
||||||
_collectionRolesCounter[role].decrement();
|
_collectionRolesCounter[role] -= 1;
|
||||||
|
|
||||||
emit CollectionRoleChanged(role, account, false, msg.sender);
|
emit CollectionRoleChanged(role, account, false, msg.sender);
|
||||||
}
|
}
|
||||||
|
|
@ -144,7 +142,7 @@ contract FleekAccessControl is Initializable {
|
||||||
function _grantTokenRole(uint256 tokenId, TokenRoles role, address account) internal {
|
function _grantTokenRole(uint256 tokenId, TokenRoles role, address account) internal {
|
||||||
if (hasTokenRole(tokenId, role, account)) revert RoleAlreadySet();
|
if (hasTokenRole(tokenId, role, account)) revert RoleAlreadySet();
|
||||||
|
|
||||||
uint256 currentVersion = _tokenRolesVersion[tokenId].current();
|
uint256 currentVersion = _tokenRolesVersion[tokenId];
|
||||||
_tokenRoles[tokenId][currentVersion][role][account] = true;
|
_tokenRoles[tokenId][currentVersion][role][account] = true;
|
||||||
|
|
||||||
emit TokenRoleChanged(tokenId, role, account, true, msg.sender);
|
emit TokenRoleChanged(tokenId, role, account, true, msg.sender);
|
||||||
|
|
@ -156,18 +154,19 @@ contract FleekAccessControl is Initializable {
|
||||||
function _revokeTokenRole(uint256 tokenId, TokenRoles role, address account) internal {
|
function _revokeTokenRole(uint256 tokenId, TokenRoles role, address account) internal {
|
||||||
if (!hasTokenRole(tokenId, role, account)) revert RoleAlreadySet();
|
if (!hasTokenRole(tokenId, role, account)) revert RoleAlreadySet();
|
||||||
|
|
||||||
uint256 currentVersion = _tokenRolesVersion[tokenId].current();
|
uint256 currentVersion = _tokenRolesVersion[tokenId];
|
||||||
_tokenRoles[tokenId][currentVersion][role][account] = false;
|
_tokenRoles[tokenId][currentVersion][role][account] = false;
|
||||||
|
|
||||||
emit TokenRoleChanged(tokenId, role, account, false, msg.sender);
|
emit TokenRoleChanged(tokenId, role, account, false, msg.sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Clears all token roles for a certain tokenId and grants the owner role to a new address.
|
* @dev This empty reserved space is put in place to allow future versions to add new
|
||||||
* Should only be used for transferring tokens.
|
* variables without shifting down storage in the inheritance chain.
|
||||||
|
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
|
||||||
*/
|
*/
|
||||||
function _clearTokenRoles(uint256 tokenId) internal {
|
function _clearTokenRoles(uint256 tokenId) internal {
|
||||||
_tokenRolesVersion[tokenId].increment();
|
_tokenRolesVersion[tokenId] += 1;
|
||||||
emit TokenRolesCleared(tokenId, msg.sender);
|
emit TokenRolesCleared(tokenId, msg.sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
pragma solidity ^0.8.7;
|
pragma solidity ^0.8.7;
|
||||||
|
|
||||||
import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
|
import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
|
||||||
import "@openzeppelin/contracts/utils/Counters.sol";
|
|
||||||
import "@openzeppelin/contracts/utils/Base64.sol";
|
import "@openzeppelin/contracts/utils/Base64.sol";
|
||||||
import "@openzeppelin/contracts/utils/Strings.sol";
|
import "@openzeppelin/contracts/utils/Strings.sol";
|
||||||
import "./FleekAccessControl.sol";
|
import "./FleekAccessControl.sol";
|
||||||
|
|
@ -15,7 +14,6 @@ error ThereIsNoTokenMinted();
|
||||||
|
|
||||||
contract FleekERC721 is Initializable, ERC721Upgradeable, FleekAccessControl, FleekPausable {
|
contract FleekERC721 is Initializable, ERC721Upgradeable, FleekAccessControl, FleekPausable {
|
||||||
using Strings for uint256;
|
using Strings for uint256;
|
||||||
using Counters for Counters.Counter;
|
|
||||||
using FleekStrings for FleekERC721.App;
|
using FleekStrings for FleekERC721.App;
|
||||||
using FleekStrings for FleekERC721.AccessPoint;
|
using FleekStrings for FleekERC721.AccessPoint;
|
||||||
using FleekStrings for string;
|
using FleekStrings for string;
|
||||||
|
|
@ -116,7 +114,7 @@ contract FleekERC721 is Initializable, ERC721Upgradeable, FleekAccessControl, Fl
|
||||||
AccessPointCreationStatus status;
|
AccessPointCreationStatus status;
|
||||||
}
|
}
|
||||||
|
|
||||||
Counters.Counter private _appIds;
|
uint256 private _appIds;
|
||||||
mapping(uint256 => App) private _apps;
|
mapping(uint256 => App) private _apps;
|
||||||
mapping(string => AccessPoint) private _accessPoints;
|
mapping(string => AccessPoint) private _accessPoints;
|
||||||
|
|
||||||
|
|
@ -126,6 +124,7 @@ contract FleekERC721 is Initializable, ERC721Upgradeable, FleekAccessControl, Fl
|
||||||
function initialize(string memory _name, string memory _symbol) public initializer {
|
function initialize(string memory _name, string memory _symbol) public initializer {
|
||||||
__ERC721_init(_name, _symbol);
|
__ERC721_init(_name, _symbol);
|
||||||
__FleekAccessControl_init();
|
__FleekAccessControl_init();
|
||||||
|
_appIds = 0;
|
||||||
__FleekPausable_init();
|
__FleekPausable_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -160,9 +159,10 @@ contract FleekERC721 is Initializable, ERC721Upgradeable, FleekAccessControl, Fl
|
||||||
uint24 color,
|
uint24 color,
|
||||||
bool accessPointAutoApproval
|
bool accessPointAutoApproval
|
||||||
) public payable requireCollectionRole(CollectionRoles.Owner) returns (uint256) {
|
) public payable requireCollectionRole(CollectionRoles.Owner) returns (uint256) {
|
||||||
uint256 tokenId = _appIds.current();
|
uint256 tokenId = _appIds;
|
||||||
_mint(to, tokenId);
|
_mint(to, tokenId);
|
||||||
_appIds.increment();
|
|
||||||
|
_appIds += 1;
|
||||||
|
|
||||||
App storage app = _apps[tokenId];
|
App storage app = _apps[tokenId];
|
||||||
app.name = name;
|
app.name = name;
|
||||||
|
|
@ -176,7 +176,6 @@ contract FleekERC721 is Initializable, ERC721Upgradeable, FleekAccessControl, Fl
|
||||||
// The mint interaction is considered to be the first build of the site. Updates from now on all increment the currentBuild by one and update the mapping.
|
// The mint interaction is considered to be the first build of the site. Updates from now on all increment the currentBuild by one and update the mapping.
|
||||||
app.currentBuild = 0;
|
app.currentBuild = 0;
|
||||||
app.builds[0] = Build(commitHash, gitRepository);
|
app.builds[0] = Build(commitHash, gitRepository);
|
||||||
|
|
||||||
emit NewMint(
|
emit NewMint(
|
||||||
tokenId,
|
tokenId,
|
||||||
name,
|
name,
|
||||||
|
|
@ -239,7 +238,7 @@ contract FleekERC721 is Initializable, ERC721Upgradeable, FleekAccessControl, Fl
|
||||||
* @dev Returns the last minted tokenId.
|
* @dev Returns the last minted tokenId.
|
||||||
*/
|
*/
|
||||||
function getLastTokenId() public view virtual returns (uint256) {
|
function getLastTokenId() public view virtual returns (uint256) {
|
||||||
uint256 current = _appIds.current();
|
uint256 current = _appIds;
|
||||||
if (current == 0) revert ThereIsNoTokenMinted();
|
if (current == 0) revert ThereIsNoTokenMinted();
|
||||||
return current - 1;
|
return current - 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue