Skip to content

Commit

Permalink
make methods public (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege authored Jan 30, 2024
1 parent 200f57d commit 31179de
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
16 changes: 8 additions & 8 deletions src/tokens/ERC6160Ext1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,29 @@ contract ERC6160Ext1155 is ERC1155, ERC165Storage, IERC6160Ext1155 {
}

/// @notice Mints token to the specified account `_to`
function safeMint(address _to, uint256 _id, uint256 _amount, bytes calldata _data) external {
function safeMint(address _to, uint256 _id, uint256 _amount, bytes calldata _data) public {
if (!isRoleAdmin(MINTER_ROLE) && !hasRole(MINTER_ROLE, _msgSender())) revert PermissionDenied();
super._mint(_to, _id, _amount, _data);
}

/// @notice Mints token in batch to the specified account `_to`
function safeMintBatch(address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data)
external
public
{
if (!isRoleAdmin(MINTER_ROLE) && !hasRole(MINTER_ROLE, _msgSender())) revert PermissionDenied();
super._mintBatch(to, ids, amounts, data);
}

/// @notice Burns token associated with the specified account `_from`
function burn(address _from, uint256 _id, uint256 _amount, bytes[] calldata) external {
function burn(address _from, uint256 _id, uint256 _amount, bytes[] calldata) public {
bool isApproved = isApprovedForAll(_msgSender(), _from);
bool hasBurnRole = isRoleAdmin(BURNER_ROLE) || hasRole(BURNER_ROLE, _msgSender());
if (!isApproved && !hasBurnRole) revert PermissionDenied();
super._burn(_from, _id, _amount);
}

/// @notice Burns token in batch associated with the specified account `_from`
function burnBatch(address _from, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata) external {
function burnBatch(address _from, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata) public {
bool isApproved = isApprovedForAll(_msgSender(), _from);
bool hasBurnRole = isRoleAdmin(BURNER_ROLE) || hasRole(BURNER_ROLE, _msgSender());
if (!isApproved && !hasBurnRole) revert PermissionDenied();
Expand All @@ -80,7 +80,7 @@ contract ERC6160Ext1155 is ERC1155, ERC165Storage, IERC6160Ext1155 {
/// @dev This method can only be called from an admin of the given role
/// @param _role The role to set for the account
/// @param _account The account to be granted the specified role
function grantRole(bytes32 _role, address _account) external {
function grantRole(bytes32 _role, address _account) public {
if (!isRoleAdmin(_role)) revert NotRoleAdmin();
_roles[_role][_account] = true;
}
Expand All @@ -89,7 +89,7 @@ contract ERC6160Ext1155 is ERC1155, ERC165Storage, IERC6160Ext1155 {
/// @dev This method can only be called from an admin of the given role
/// @param _role The role to revoke for the account
/// @param _account The account whose role is to be revoked
function revokeRole(bytes32 _role, address _account) external {
function revokeRole(bytes32 _role, address _account) public {
if (!isRoleAdmin(_role)) revert NotRoleAdmin();
_roles[_role][_account] = false;
}
Expand All @@ -107,12 +107,12 @@ contract ERC6160Ext1155 is ERC1155, ERC165Storage, IERC6160Ext1155 {
}

/// @notice Get the Minter-Role ID
function getMinterRole() external pure returns (bytes32) {
function getMinterRole() public pure returns (bytes32) {
return MINTER_ROLE;
}

/// @notice Get the Burner-Role ID
function getBurnerRole() external pure returns (bytes32) {
function getBurnerRole() public pure returns (bytes32) {
return BURNER_ROLE;
}

Expand Down
52 changes: 26 additions & 26 deletions src/tokens/ERC6160Ext20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,66 +13,59 @@ error PermissionDenied();

contract ERC6160Ext20 is ERC165Storage, ERC20, IERC6160Ext20 {
/// @notice InterfaceId for ERC6160Ext20
bytes4 constant _IERC6160Ext20_ID_ = 0xbbb8b47e;
bytes4 private constant IERC6160Ext20_ID = 0xbbb8b47e;

/// @notice The Id of Role required to mint token
bytes32 constant MINTER_ROLE = keccak256("MINTER ROLE");
bytes32 public constant MINTER_ROLE = keccak256("MINTER ROLE");

/// @notice The Id of Role required to burn token
bytes32 constant BURNER_ROLE = keccak256("BURNER ROLE");
bytes32 public constant BURNER_ROLE = keccak256("BURNER ROLE");

/// @notice mapping of defined roles in the contract
mapping(bytes32 => mapping(address => bool)) _roles;
mapping(bytes32 => mapping(address => bool)) internal _roles;

/// @notice mapping of admins of defined roles
mapping(bytes32 => mapping(address => bool)) _rolesAdmin;
mapping(bytes32 => mapping(address => bool)) internal _rolesAdmin;

constructor(address admin, string memory name, string memory symbol) ERC20(name, symbol) {
_registerInterface(_IERC6160Ext20_ID_);
_registerInterface(IERC6160Ext20_ID);
_registerInterface(type(IERC5679Ext20).interfaceId);
_registerInterface(type(IERC_ACL_CORE).interfaceId);

_rolesAdmin[MINTER_ROLE][admin] = true;
_roles[MINTER_ROLE][admin] = true;

_rolesAdmin[BURNER_ROLE][admin] = true;

_roles[MINTER_ROLE][admin] = true;
_roles[BURNER_ROLE][admin] = true;
}

/// @notice Mints token to the specified account `_to`
function mint(address _to, uint256 _amount, bytes calldata) external {
if (!isRoleAdmin(MINTER_ROLE) && !hasRole(MINTER_ROLE, _msgSender())) revert PermissionDenied();
function mint(address _to, uint256 _amount, bytes calldata) public {
if (!_isRoleAdmin(MINTER_ROLE) && !hasRole(MINTER_ROLE, _msgSender())) revert PermissionDenied();
super._mint(_to, _amount);
}

/// @notice Burns token associated with the specified account `_from`
function burn(address _from, uint256 _amount, bytes calldata) external {
if (!isRoleAdmin(BURNER_ROLE) && !hasRole(BURNER_ROLE, _msgSender())) revert PermissionDenied();
function burn(address _from, uint256 _amount, bytes calldata) public {
if (!_isRoleAdmin(BURNER_ROLE) && !hasRole(BURNER_ROLE, _msgSender())) revert PermissionDenied();
super._burn(_from, _amount);
}

/// @notice Checks that an account has a specified role
/// @param _role The role to query
/// @param _account The account to query for the given role
function hasRole(bytes32 _role, address _account) public view returns (bool) {
return _roles[_role][_account];
}

/// @notice Grants a given role to the specified account
/// @dev This method can only be called from an admin of the given role
/// @param _role The role to set for the account
/// @param _account The account to be granted the specified role
function grantRole(bytes32 _role, address _account) external {
if (!isRoleAdmin(_role)) revert NotRoleAdmin();
function grantRole(bytes32 _role, address _account) public {
if (!_isRoleAdmin(_role)) revert NotRoleAdmin();
_roles[_role][_account] = true;
}

/// @notice Revokes a given role to the specified account
/// @dev This method can only be called from an admin of the given role
/// @param _role The role to revoke for the account
/// @param _account The account whose role is to be revoked
function revokeRole(bytes32 _role, address _account) external {
if (!isRoleAdmin(_role)) revert NotRoleAdmin();
function revokeRole(bytes32 _role, address _account) public {
if (!_isRoleAdmin(_role)) revert NotRoleAdmin();
_roles[_role][_account] = false;
}

Expand All @@ -82,20 +75,27 @@ contract ERC6160Ext20 is ERC165Storage, ERC20, IERC6160Ext20 {
return super.supportsInterface(_interfaceId);
}

/// @notice Checks that an account has a specified role
/// @param _role The role to query
/// @param _account The account to query for the given role
function hasRole(bytes32 _role, address _account) public view returns (bool) {
return _roles[_role][_account];
}

/// @notice Get the Minter-Role ID
function getMinterRole() external pure returns (bytes32) {
function getMinterRole() public pure returns (bytes32) {
return MINTER_ROLE;
}

/// @notice Get the Burner-Role ID
function getBurnerRole() external pure returns (bytes32) {
function getBurnerRole() public pure returns (bytes32) {
return BURNER_ROLE;
}

/**
* INTERNAL FUNCTIONS *
*/
function isRoleAdmin(bytes32 role) internal view returns (bool) {
function _isRoleAdmin(bytes32 role) internal view returns (bool) {
return _rolesAdmin[role][_msgSender()];
}
}
14 changes: 7 additions & 7 deletions src/tokens/ERC6160Ext721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ contract ERC6160Ext721 is ERC721, ERC165Storage, IERC6160Ext721 {
}

/// @notice Mints token with ID of `_tokenId` to the specified account `_to`
function safeMint(address _to, uint256 _tokenId, bytes calldata _data) external {
function safeMint(address _to, uint256 _tokenId, bytes calldata _data) public {
if (!isRoleAdmin(MINTER_ROLE) && !hasRole(MINTER_ROLE, _msgSender())) revert PermissionDenied();
super._safeMint(_to, _tokenId, _data);
}

/// @notice Burns token with ID of `_tokenId`
function burn(address, uint256 _tokenId, bytes calldata) external {
function burn(address, uint256 _tokenId, bytes calldata) public {
bool isApproved = _isApprovedOrOwner(_msgSender(), _tokenId);
bool hasBurnRole = isRoleAdmin(BURNER_ROLE) || hasRole(BURNER_ROLE, _msgSender());
if (!isApproved && !hasBurnRole) revert PermissionDenied();
Expand All @@ -64,7 +64,7 @@ contract ERC6160Ext721 is ERC721, ERC165Storage, IERC6160Ext721 {
/// @dev This method can only be called from an admin of the given role
/// @param _role The role to set for the account
/// @param _account The account to be granted the specified role
function grantRole(bytes32 _role, address _account) external {
function grantRole(bytes32 _role, address _account) public {
if (!isRoleAdmin(_role)) revert NotRoleAdmin();
_roles[_role][_account] = true;
}
Expand All @@ -73,7 +73,7 @@ contract ERC6160Ext721 is ERC721, ERC165Storage, IERC6160Ext721 {
/// @dev This method can only be called from an admin of the given role
/// @param _role The role to revoke for the account
/// @param _account The account whose role is to be revoked
function revokeRole(bytes32 _role, address _account) external {
function revokeRole(bytes32 _role, address _account) public {
if (!isRoleAdmin(_role)) revert NotRoleAdmin();
_roles[_role][_account] = false;
}
Expand All @@ -96,17 +96,17 @@ contract ERC6160Ext721 is ERC721, ERC165Storage, IERC6160Ext721 {
}

/// @notice Checks that token of ID `_tokenID` exists
function exists(uint256 _tokenID) external view returns (bool) {
function exists(uint256 _tokenID) public view returns (bool) {
return super._exists(_tokenID);
}

/// @notice Get the Minter-Role ID
function getMinterRole() external pure returns (bytes32) {
function getMinterRole() public pure returns (bytes32) {
return MINTER_ROLE;
}

/// @notice Get the Burner-Role ID
function getBurnerRole() external pure returns (bytes32) {
function getBurnerRole() public pure returns (bytes32) {
return BURNER_ROLE;
}

Expand Down

0 comments on commit 31179de

Please sign in to comment.