Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
b2e2d9ab
Commit
b2e2d9ab
authored
Jan 15, 2018
by
Matt Condon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: solium errors - indentation only
parent
4d263b7f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
252 additions
and
252 deletions
+252
-252
RBACMock.sol
contracts/mocks/RBACMock.sol
+51
-51
Contactable.sol
contracts/ownership/Contactable.sol
+8
-8
RBAC.sol
contracts/ownership/rbac/RBAC.sol
+139
-139
Roles.sol
contracts/ownership/rbac/Roles.sol
+40
-40
BurnableToken.sol
contracts/token/BurnableToken.sol
+14
-14
No files found.
contracts/mocks/RBACMock.sol
View file @
b2e2d9ab
...
@@ -5,65 +5,65 @@ import "../ownership/rbac/RBAC.sol";
...
@@ -5,65 +5,65 @@ import "../ownership/rbac/RBAC.sol";
contract RBACMock is RBAC {
contract RBACMock is RBAC {
string constant ROLE_ADVISOR = "advisor";
string constant ROLE_ADVISOR = "advisor";
modifier onlyAdminOrAdvisor()
modifier onlyAdminOrAdvisor()
{
{
require(
require(
hasRole(msg.sender, ROLE_ADMIN) ||
hasRole(msg.sender, ROLE_ADMIN) ||
hasRole(msg.sender, ROLE_ADVISOR)
hasRole(msg.sender, ROLE_ADVISOR)
);
);
_;
_;
}
}
function RBACMock(address[] _advisors)
function RBACMock(address[] _advisors)
public
public
{
{
addRole(msg.sender, ROLE_ADVISOR);
addRole(msg.sender, ROLE_ADVISOR);
for (uint256 i = 0; i < _advisors.length; i++) {
for (uint256 i = 0; i < _advisors.length; i++) {
addRole(_advisors[i], ROLE_ADVISOR);
addRole(_advisors[i], ROLE_ADVISOR);
}
}
}
}
function onlyAdminsCanDoThis()
function onlyAdminsCanDoThis()
onlyAdmin
onlyAdmin
view
view
external
external
{
{
}
}
function onlyAdvisorsCanDoThis()
function onlyAdvisorsCanDoThis()
onlyRole(ROLE_ADVISOR)
onlyRole(ROLE_ADVISOR)
view
view
external
external
{
{
}
}
function eitherAdminOrAdvisorCanDoThis()
function eitherAdminOrAdvisorCanDoThis()
onlyAdminOrAdvisor
onlyAdminOrAdvisor
view
view
external
external
{
{
}
}
function nobodyCanDoThis()
function nobodyCanDoThis()
onlyRole("unknown")
onlyRole("unknown")
view
view
external
external
{
{
}
}
// admins can remove advisor's role
// admins can remove advisor's role
function removeAdvisor(address _addr)
function removeAdvisor(address _addr)
onlyAdmin
onlyAdmin
public
public
{
{
// revert if the user isn't an advisor
// revert if the user isn't an advisor
// (perhaps you want to soft-fail here instead?)
// (perhaps you want to soft-fail here instead?)
checkRole(_addr, ROLE_ADVISOR);
checkRole(_addr, ROLE_ADVISOR);
// remove the advisor's role
// remove the advisor's role
removeRole(_addr, ROLE_ADVISOR);
removeRole(_addr, ROLE_ADVISOR);
}
}
}
}
contracts/ownership/Contactable.sol
View file @
b2e2d9ab
...
@@ -9,13 +9,13 @@ import "./Ownable.sol";
...
@@ -9,13 +9,13 @@ import "./Ownable.sol";
*/
*/
contract Contactable is Ownable{
contract Contactable is Ownable{
string public contactInformation;
string public contactInformation;
/**
/**
* @dev Allows the owner to set a string with their contact information.
* @dev Allows the owner to set a string with their contact information.
* @param info The contact information to attach to the contract.
* @param info The contact information to attach to the contract.
*/
*/
function setContactInformation(string info) onlyOwner public {
function setContactInformation(string info) onlyOwner public {
contactInformation = info;
contactInformation = info;
}
}
}
}
contracts/ownership/rbac/RBAC.sol
View file @
b2e2d9ab
...
@@ -15,143 +15,143 @@ import "./Roles.sol";
...
@@ -15,143 +15,143 @@ import "./Roles.sol";
* to avoid typos.
* to avoid typos.
*/
*/
contract RBAC {
contract RBAC {
using Roles for Roles.Role;
using Roles for Roles.Role;
mapping (string => Roles.Role) private roles;
mapping (string => Roles.Role) private roles;
event RoleAdded(address addr, string roleName);
event RoleAdded(address addr, string roleName);
event RoleRemoved(address addr, string roleName);
event RoleRemoved(address addr, string roleName);
/**
/**
* A constant role name for indicating admins.
* A constant role name for indicating admins.
*/
*/
string public constant ROLE_ADMIN = "admin";
string public constant ROLE_ADMIN = "admin";
/**
/**
* @dev constructor. Sets msg.sender as admin by default
* @dev constructor. Sets msg.sender as admin by default
*/
*/
function RBAC()
function RBAC()
public
public
{
{
addRole(msg.sender, ROLE_ADMIN);
addRole(msg.sender, ROLE_ADMIN);
}
}
/**
/**
* @dev add a role to an address
* @dev add a role to an address
* @param addr address
* @param addr address
* @param roleName the name of the role
* @param roleName the name of the role
*/
*/
function addRole(address addr, string roleName)
function addRole(address addr, string roleName)
internal
internal
{
{
roles[roleName].add(addr);
roles[roleName].add(addr);
RoleAdded(addr, roleName);
RoleAdded(addr, roleName);
}
}
/**
/**
* @dev remove a role from an address
* @dev remove a role from an address
* @param addr address
* @param addr address
* @param roleName the name of the role
* @param roleName the name of the role
*/
*/
function removeRole(address addr, string roleName)
function removeRole(address addr, string roleName)
internal
internal
{
{
roles[roleName].remove(addr);
roles[roleName].remove(addr);
RoleRemoved(addr, roleName);
RoleRemoved(addr, roleName);
}
}
/**
/**
* @dev reverts if addr does not have role
* @dev reverts if addr does not have role
* @param addr address
* @param addr address
* @param roleName the name of the role
* @param roleName the name of the role
* // reverts
* // reverts
*/
*/
function checkRole(address addr, string roleName)
function checkRole(address addr, string roleName)
view
view
public
public
{
{
roles[roleName].check(addr);
roles[roleName].check(addr);
}
}
/**
/**
* @dev determine if addr has role
* @dev determine if addr has role
* @param addr address
* @param addr address
* @param roleName the name of the role
* @param roleName the name of the role
* @return bool
* @return bool
*/
*/
function hasRole(address addr, string roleName)
function hasRole(address addr, string roleName)
view
view
public
public
returns (bool)
returns (bool)
{
{
return roles[roleName].has(addr);
return roles[roleName].has(addr);
}
}
/**
/**
* @dev add a role to an address
* @dev add a role to an address
* @param addr address
* @param addr address
* @param roleName the name of the role
* @param roleName the name of the role
*/
*/
function adminAddRole(address addr, string roleName)
function adminAddRole(address addr, string roleName)
onlyAdmin
onlyAdmin
public
public
{
{
addRole(addr, roleName);
addRole(addr, roleName);
}
}
/**
/**
* @dev remove a role from an address
* @dev remove a role from an address
* @param addr address
* @param addr address
* @param roleName the name of the role
* @param roleName the name of the role
*/
*/
function adminRemoveRole(address addr, string roleName)
function adminRemoveRole(address addr, string roleName)
onlyAdmin
onlyAdmin
public
public
{
{
removeRole(addr, roleName);
removeRole(addr, roleName);
}
}
/**
/**
* @dev modifier to scope access to a single role (uses msg.sender as addr)
* @dev modifier to scope access to a single role (uses msg.sender as addr)
* @param roleName the name of the role
* @param roleName the name of the role
* // reverts
* // reverts
*/
*/
modifier onlyRole(string roleName)
modifier onlyRole(string roleName)
{
{
checkRole(msg.sender, roleName);
checkRole(msg.sender, roleName);
_;
_;
}
}
/**
/**
* @dev modifier to scope access to admins
* @dev modifier to scope access to admins
* // reverts
* // reverts
*/
*/
modifier onlyAdmin()
modifier onlyAdmin()
{
{
checkRole(msg.sender, ROLE_ADMIN);
checkRole(msg.sender, ROLE_ADMIN);
_;
_;
}
}
/**
/**
* @dev modifier to scope access to a set of roles (uses msg.sender as addr)
* @dev modifier to scope access to a set of roles (uses msg.sender as addr)
* @param roleNames the names of the roles to scope access to
* @param roleNames the names of the roles to scope access to
* // reverts
* // reverts
*
*
* @TODO - when solidity supports dynamic arrays as arguments to modifiers, provide this
* @TODO - when solidity supports dynamic arrays as arguments to modifiers, provide this
* see: https://github.com/ethereum/solidity/issues/2467
* see: https://github.com/ethereum/solidity/issues/2467
*/
*/
// modifier onlyRoles(string[] roleNames) {
// modifier onlyRoles(string[] roleNames) {
// bool hasAnyRole = false;
// bool hasAnyRole = false;
// for (uint8 i = 0; i < roleNames.length; i++) {
// for (uint8 i = 0; i < roleNames.length; i++) {
// if (hasRole(msg.sender, roleNames[i])) {
// if (hasRole(msg.sender, roleNames[i])) {
// hasAnyRole = true;
// hasAnyRole = true;
// break;
// break;
// }
// }
// }
// }
// require(hasAnyRole);
// require(hasAnyRole);
// _;
// _;
// }
// }
}
}
contracts/ownership/rbac/Roles.sol
View file @
b2e2d9ab
...
@@ -8,48 +8,48 @@ pragma solidity ^0.4.18;
...
@@ -8,48 +8,48 @@ pragma solidity ^0.4.18;
* See RBAC.sol for example usage.
* See RBAC.sol for example usage.
*/
*/
library Roles {
library Roles {
struct Role {
struct Role {
mapping (address => bool) bearer;
mapping (address => bool) bearer;
}
}
/**
/**
* @dev give an address access to this role
* @dev give an address access to this role
*/
*/
function add(Role storage role, address addr)
function add(Role storage role, address addr)
internal
internal
{
{
role.bearer[addr] = true;
role.bearer[addr] = true;
}
}
/**
/**
* @dev remove an address' access to this role
* @dev remove an address' access to this role
*/
*/
function remove(Role storage role, address addr)
function remove(Role storage role, address addr)
internal
internal
{
{
role.bearer[addr] = false;
role.bearer[addr] = false;
}
}
/**
/**
* @dev check if an address has this role
* @dev check if an address has this role
* // reverts
* // reverts
*/
*/
function check(Role storage role, address addr)
function check(Role storage role, address addr)
view
view
internal
internal
{
{
require(has(role, addr));
require(has(role, addr));
}
}
/**
/**
* @dev check if an address has this role
* @dev check if an address has this role
* @return bool
* @return bool
*/
*/
function has(Role storage role, address addr)
function has(Role storage role, address addr)
view
view
internal
internal
returns (bool)
returns (bool)
{
{
return role.bearer[addr];
return role.bearer[addr];
}
}
}
}
contracts/token/BurnableToken.sol
View file @
b2e2d9ab
...
@@ -8,20 +8,20 @@ import "./BasicToken.sol";
...
@@ -8,20 +8,20 @@ import "./BasicToken.sol";
*/
*/
contract BurnableToken is BasicToken {
contract BurnableToken is BasicToken {
event Burn(address indexed burner, uint256 value);
event Burn(address indexed burner, uint256 value);
/**
/**
* @dev Burns a specific amount of tokens.
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
* @param _value The amount of token to be burned.
*/
*/
function burn(uint256 _value) public {
function burn(uint256 _value) public {
require(_value <= balances[msg.sender]);
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
totalSupply = totalSupply.sub(_value);
Burn(burner, _value);
Burn(burner, _value);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment