Achievement
Inherits: IERC721, AccessControlEnumerableUpgradeable, ERC721Upgradeable, IErrors, IEvents, IAchievement
State Variables
APP_ADMIN_ROLE
bytes32 public constant APP_ADMIN_ROLE = keccak256("APP_ADMIN_ROLE");
APP_USER_ROLE
bytes32 public constant APP_USER_ROLE = keccak256("APP_USER_ROLE");
_counter
uint256 internal _counter;
_totalSupply
uint256 internal _totalSupply;
_powerToken
address internal _powerToken;
_achievements
EnumerableSet.Bytes32Set internal _achievements;
_achievementDetails
mapping(bytes32 => AchievementDetails) internal _achievementDetails;
_tokenIdToAchievements
mapping(uint256 => bytes32) internal _tokenIdToAchievements;
_userAchievements
mapping(address => mapping(bytes32 => bool)) internal _userAchievements;
Functions
initialize
Initializes the contract. Setup token name, symbol and account with APP_ADMIN_ROLE.
function initialize(
string calldata name_,
string calldata symbol_,
address admin_,
address powerToken_
) external override initializer;
Parameters
Name | Type | Description |
---|---|---|
name_ | string | The name of the token. |
symbol_ | string | The symbol of the token. |
admin_ | address | The account to be granted with APP_ADMIN_ROLE. |
powerToken_ | address | The address of the power token. |
setAchievement
Only the APP_ADMIN_ROLE can set the achievement details.
function setAchievement(string calldata name, string calldata description, string calldata imageURL)
external
override
onlyRole(APP_ADMIN_ROLE);
Parameters
Name | Type | Description |
---|---|---|
name | string | Name of the achievement. |
description | string | Description of the achievement. |
imageURL | string | Image URL of the achievement. |
mint
Mints a token to account
.
function mint(string calldata achievementName) external override returns (uint256 tokenId);
Parameters
Name | Type | Description |
---|---|---|
achievementName | string |
Returns
Name | Type | Description |
---|---|---|
tokenId | uint256 | The new minted token id. |
tokenURI
See {IERC721Metadata-tokenURI}.
function tokenURI(uint256 id) public view override returns (string memory);
totalSupply
Returns total supply of tokens.
function totalSupply() external view override returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Total supply of tokens. |
getAllAchievements
Returns the achievement details of all achievements.
function getAllAchievements() external view override returns (AchievementDetails[] memory);
Returns
Name | Type | Description |
---|---|---|
<none> | AchievementDetails[] | Achievement details. |
hasAchievement
Returns whether the account has the achievement.
function hasAchievement(address account, string calldata achievementName)
external
view
override
returns (bool);
Parameters
Name | Type | Description |
---|---|---|
account | address | The address of the account. |
achievementName | string | The name of the achievement. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Whether the account has the achievement. |
powerToken
Returns the address of the PowerToken contract.
function powerToken() external view override returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | Address of the PowerToken contract. |
supportsInterface
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(AccessControlEnumerableUpgradeable, ERC721Upgradeable, IERC165)
returns (bool);
_getNameHash
function _getNameHash(string calldata name) internal pure returns (bytes32);