You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.1 KiB
56 lines
1.1 KiB
7 years ago
|
pragma solidity ^0.4.18;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @title Roles
|
||
|
* @author Francisco Giordano (@frangio)
|
||
|
* @dev Library for managing addresses assigned to a Role.
|
||
|
* See RBAC.sol for example usage.
|
||
|
*/
|
||
|
library Roles {
|
||
|
struct Role {
|
||
|
mapping (address => bool) bearer;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @dev give an address access to this role
|
||
|
*/
|
||
|
function add(Role storage role, address addr)
|
||
|
internal
|
||
|
{
|
||
|
role.bearer[addr] = true;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @dev remove an address' access to this role
|
||
|
*/
|
||
|
function remove(Role storage role, address addr)
|
||
|
internal
|
||
|
{
|
||
|
role.bearer[addr] = false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @dev check if an address has this role
|
||
|
* // reverts
|
||
|
*/
|
||
|
function check(Role storage role, address addr)
|
||
|
view
|
||
|
internal
|
||
|
{
|
||
|
require(has(role, addr));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @dev check if an address has this role
|
||
|
* @return bool
|
||
|
*/
|
||
|
function has(Role storage role, address addr)
|
||
|
view
|
||
|
internal
|
||
|
returns (bool)
|
||
|
{
|
||
|
return role.bearer[addr];
|
||
|
}
|
||
|
}
|