关于openzeppelin中AccessControl合约库的疑惑

image.png

合约库中grantRole 方法是给role角色 添加会员 , 在函数执行中会 经过onlyRolegetRoleAdmin(role))判断 getRoleAdmin(role)是返回当前role管理员=>adminRole image.png 然后将管理员这个by32类型 又当成角色role传递到_checkRole()函数中 从这里开始就疑惑了管理员和role角色不是不同的吗

而_checkRole是判断 调用人是否有这个role角色的会员 传值应该是role 而不应该是adminRole呀 这样转了 一圈 并没有 验证调用人就是adminRole这个管理员呀

image.png image.png

请先 登录 后评论

最佳答案 6天前

struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }
 比如这个是Manager组 role是0xabc
 onlyRole(getRoleAdmin(role))
    getRoleAdmin(role)==>获取role所在组的admin的Role adminRole
 onlyRole(adminRole)
    _checkRole(adminRole);
        _checkRole(adminRole, _msgSender());//检查调用者在不在admin组
           hasRole(adminRole, account)
             _roles[adminRole].members[account];//只要在adminRole所在组的成员,都是 (role是0xabc)的管理员

初始管理员 bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
struct RoleData {
        mapping(address => bool) members;//0x00这个管理组,可以有多个成员,
        bytes32 adminRole;//0x0 也就是如果没设置这个,都属于0x00
    }
请先 登录 后评论

其它 0 个回答