axelar-gmp-sdk-solidity

Solidity API

RolesBase

A contract module which provides a set if internal functions for implementing role control features.

ROLES_PREFIX

bytes32 ROLES_PREFIX

PROPOSE_ROLES_PREFIX

bytes32 PROPOSE_ROLES_PREFIX

onlyRole

modifier onlyRole(uint8 role)

Modifier that throws an error if called by any account missing the role.

withEveryRole

modifier withEveryRole(uint8[] roles)

Modifier that throws an error if called by an account without all the roles.

withAnyRole

modifier withAnyRole(uint8[] roles)

Modifier that throws an error if called by an account without any of the roles.

hasRole

function hasRole(address account, uint8 role) public view returns (bool)

Checks if an account has a role.

Parameters

Name Type Description
account address The address to check
role uint8 The role to check

Return Values

Name Type Description
[0] bool True if the account has the role, false otherwise

_toAccountRoles

function _toAccountRoles(uint8[] roles) internal pure returns (uint256)

Internal function to convert an array of roles to a uint256.

Parameters

Name Type Description
roles uint8[] The roles to convert

Return Values

Name Type Description
[0] uint256 accountRoles The roles in uint256 format

_rolesKey

function _rolesKey(address account) internal view virtual returns (bytes32 key)

Internal function to get the key of the roles mapping.

Parameters

Name Type Description
account address The address to get the key for

Return Values

Name Type Description
key bytes32 The key of the roles mapping

_getRoles

function _getRoles(address account) internal view returns (uint256 accountRoles)

Internal function to get the roles of an account.

Parameters

Name Type Description
account address The address to get the roles for

Return Values

Name Type Description
accountRoles uint256 The roles of the account in uint256 format

_proposalKey

function _proposalKey(address fromAccount, address toAccount) internal view virtual returns (bytes32 key)

Internal function to get the key of the proposed roles mapping.

Parameters

Name Type Description
fromAccount address The address of the current role
toAccount address The address of the pending role

Return Values

Name Type Description
key bytes32 The key of the proposed roles mapping

_getProposedRoles

function _getProposedRoles(address fromAccount, address toAccount) internal view returns (uint256 proposedRoles_)

Internal function to get the proposed roles of an account.

Parameters

Name Type Description
fromAccount address The address of the current role
toAccount address The address of the pending role

Return Values

Name Type Description
proposedRoles_ uint256 The proposed roles of the account in uint256 format

_addRole

function _addRole(address account, uint8 role) internal

Internal function to add a role to an account.

emits a RolesAdded event.

Parameters

Name Type Description
account address The address to add the role to
role uint8 The role to add

_addRoles

function _addRoles(address account, uint8[] roles) internal

Internal function to add roles to an account.

emits a RolesAdded event. Called in the constructor to set the initial roles.

Parameters

Name Type Description
account address The address to add roles to
roles uint8[] The roles to add

_addAccountRoles

function _addAccountRoles(address account, uint256 accountRoles) internal

Internal function to add roles to an account.

emits a RolesAdded event. Called in the constructor to set the initial roles.

Parameters

Name Type Description
account address The address to add roles to
accountRoles uint256 The roles to add

_removeRole

function _removeRole(address account, uint8 role) internal

Internal function to remove a role from an account.

emits a RolesRemoved event.

Parameters

Name Type Description
account address The address to remove the role from
role uint8 The role to remove

_removeRoles

function _removeRoles(address account, uint8[] roles) internal

Internal function to remove roles from an account.

emits a RolesRemoved event.

Parameters

Name Type Description
account address The address to remove roles from
roles uint8[] The roles to remove

_removeAccountRoles

function _removeAccountRoles(address account, uint256 accountRoles) internal

Internal function to remove roles from an account.

emits a RolesRemoved event.

Parameters

Name Type Description
account address The address to remove roles from
accountRoles uint256 The roles to remove

_hasRole

function _hasRole(uint256 accountRoles, uint8 role) internal pure returns (bool)

Internal function to check if an account has a role.

Parameters

Name Type Description
accountRoles uint256 The roles of the account in uint256 format
role uint8 The role to check

Return Values

Name Type Description
[0] bool True if the account has the role, false otherwise

_hasAllTheRoles

function _hasAllTheRoles(uint256 hasAccountRoles, uint256 mustHaveAccountRoles) internal pure returns (bool)

Internal function to check if an account has all the roles.

Parameters

Name Type Description
hasAccountRoles uint256 The roles of the account in uint256 format
mustHaveAccountRoles uint256 The roles the account must have

Return Values

Name Type Description
[0] bool True if the account has all the roles, false otherwise

_hasAnyOfRoles

function _hasAnyOfRoles(uint256 hasAccountRoles, uint256 mustHaveAnyAccountRoles) internal pure returns (bool)

Internal function to check if an account has any of the roles.

Parameters

Name Type Description
hasAccountRoles uint256 The roles of the account in uint256 format
mustHaveAnyAccountRoles uint256 The roles to check in uint256 format

Return Values

Name Type Description
[0] bool True if the account has any of the roles, false otherwise

_proposeRole

function _proposeRole(address fromAccount, address toAccount, uint8 role) internal

Internal function to propose to transfer roles of message sender to a new account.

Original account must have all the proposed roles. Emits a RolesProposed event. Roles are not transferred until the new role accepts the role transfer.

Parameters

Name Type Description
fromAccount address The address of the current roles
toAccount address The address to transfer roles to
role uint8 The role to transfer

_proposeRoles

function _proposeRoles(address fromAccount, address toAccount, uint8[] roles) internal

Internal function to propose to transfer roles of message sender to a new account.

Original account must have all the proposed roles. Emits a RolesProposed event. Roles are not transferred until the new role accepts the role transfer.

Parameters

Name Type Description
fromAccount address The address of the current roles
toAccount address The address to transfer roles to
roles uint8[] The roles to transfer

_proposeAccountRoles

function _proposeAccountRoles(address fromAccount, address toAccount, uint256 accountRoles) internal

Internal function to propose to transfer roles of message sender to a new account.

Original account must have all the proposed roles. Emits a RolesProposed event. Roles are not transferred until the new role accepts the role transfer.

Parameters

Name Type Description
fromAccount address The address of the current roles
toAccount address The address to transfer roles to
accountRoles uint256 The account roles to transfer

_acceptRole

function _acceptRole(address fromAccount, address toAccount, uint8 role) internal virtual

Internal function to accept roles transferred from another account.

Pending account needs to pass all the proposed roles. Emits RolesRemoved and RolesAdded events.

Parameters

Name Type Description
fromAccount address The address of the current role
toAccount address  
role uint8 The role to accept

_acceptRoles

function _acceptRoles(address fromAccount, address toAccount, uint8[] roles) internal virtual

Internal function to accept roles transferred from another account.

Pending account needs to pass all the proposed roles. Emits RolesRemoved and RolesAdded events.

Parameters

Name Type Description
fromAccount address The address of the current role
toAccount address  
roles uint8[] The roles to accept

_acceptAccountRoles

function _acceptAccountRoles(address fromAccount, address toAccount, uint256 accountRoles) internal virtual

Internal function to accept roles transferred from another account.

Pending account needs to pass all the proposed roles. Emits RolesRemoved and RolesAdded events.

Parameters

Name Type Description
fromAccount address The address of the current role
toAccount address  
accountRoles uint256 The account roles to accept

_transferRole

function _transferRole(address fromAccount, address toAccount, uint8 role) internal

Internal function to transfer roles from one account to another.

Original account must have all the proposed roles.

Parameters

Name Type Description
fromAccount address The address of the current role
toAccount address The address to transfer role to
role uint8 The role to transfer

_transferRoles

function _transferRoles(address fromAccount, address toAccount, uint8[] roles) internal

Internal function to transfer roles from one account to another.

Original account must have all the proposed roles.

Parameters

Name Type Description
fromAccount address The address of the current role
toAccount address The address to transfer role to
roles uint8[] The roles to transfer

_transferAccountRoles

function _transferAccountRoles(address fromAccount, address toAccount, uint256 accountRoles) internal

Internal function to transfer roles from one account to another.

Original account must have all the proposed roles.

Parameters

Name Type Description
fromAccount address The address of the current role
toAccount address The address to transfer role to
accountRoles uint256 The account roles to transfer