-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibRoles.sol
56 lines (51 loc) · 1.16 KB
/
LibRoles.sol
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
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: MIT
pragma solidity =0.7.5;
/**
* @dev Library for managing addresses assigned to a Role.
*/
library Roles {
struct Role
{
mapping (address => bool) bearer;
}
/**
* @dev Give an account access to this role.
*/
function add(
Role storage role,
address account
)
internal
{
require(!has(role, account), "Roles: account already has role");
role.bearer[account] = true;
}
/**
* @dev Remove an account's access to this role.
*/
function remove(
Role storage role,
address account
)
internal
{
require(has(role, account), "Roles: account does not have role");
role.bearer[account] = false;
}
/**
* @dev Check if an account has this role.
*
* @return bool
*/
function has(
Role storage role,
address account
)
internal
view
returns (bool)
{
require(account != address(0), "Roles: account is the zero address");
return role.bearer[account];
}
}