Skip to content

Instantly share code, notes, and snippets.

@hiddentao
Last active March 10, 2020 03:27
Show Gist options
  • Save hiddentao/06a3eee75fb433192563890a5d605240 to your computer and use it in GitHub Desktop.
Save hiddentao/06a3eee75fb433192563890a5d605240 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;
}
_;
}
}
@sebastinez
Copy link

Thank you very much for this great implementation! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment