|
|
|
pragma solidity ^0.4.24;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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)
|
|
|
|
internal
|
|
|
|
view
|
|
|
|
{
|
|
|
|
require(has(_role, _addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev check if an address has this role
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function has(Role storage _role, address _addr)
|
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (bool)
|
|
|
|
{
|
|
|
|
return _role.bearer[_addr];
|
|
|
|
}
|
|
|
|
}
|