Skip to content

Instantly share code, notes, and snippets.

@mayukhdifferent
Forked from hiddentao/RoleBasedAcl.sol
Created December 10, 2017 02:27
Show Gist options
  • Save mayukhdifferent/b96e3df74d552504ac1e052bd2197545 to your computer and use it in GitHub Desktop.
Save mayukhdifferent/b96e3df74d552504ac1e052bd2197545 to your computer and use it in GitHub Desktop.
Ethereum solidity contract for role-based access control
pragma solidity ^0.4.10;
contract RoleBasedAcl {
address creator;
mapping(address => mapping(string => bool)) roles;
function RoleBasedAcl () {
creator = msg.sender;
}
function assignRole (address entity, string role) hasRole('superadmin') {
roles[entity][role] = true;
}
function unassignRole (address entity, string role) hasRole('superadmin') {
roles[entity][role] = false;
}
function isAssignedRole (address entity, string role) returns (bool) {
return roles[entity][role];
}
modifier hasRole (string role) {
if (!roles[msg.sender][role] && msg.sender != creator) {
throw;
}
_;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment