-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathW8day5.sol
More file actions
43 lines (34 loc) · 1.01 KB
/
W8day5.sol
File metadata and controls
43 lines (34 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract RBACExample {
mapping(bytes32 => mapping(address => bool)) private roles;
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant MEME_MAKER = keccak256("MEME_MAKER");
uint256 public totalSupply;
constructor() {
roles[ADMIN_ROLE][msg.sender] = true;
}
modifier onlyRole(bytes32 role) {
require(roles[role][msg.sender], "Access denied");
_;
}
function grantRole(bytes32 role, address account)
public
onlyRole(ADMIN_ROLE)
{
roles[role][account] = true;
}
function revokeRole(bytes32 role, address account)
public
onlyRole(ADMIN_ROLE)
{
roles[role][account] = false;
}
function mint(uint amount)
public
onlyRole(MINTER_ROLE)
{
totalSupply += amount;
}
}