pub struct AccessControl {
pub _roles: StorageMap<FixedBytes<32>, RoleData>,
}
Expand description
State of an AccessControl
contract.
Fields§
§_roles: StorageMap<FixedBytes<32>, RoleData>
Role identifier -> Role information.
Implementations§
source§impl AccessControl
impl AccessControl
sourcepub const DEFAULT_ADMIN_ROLE: [u8; 32] = _
pub const DEFAULT_ADMIN_ROLE: [u8; 32] = _
The default admin role. [0; 32]
by default.
sourcepub fn has_role(&self, role: B256, account: Address) -> bool
pub fn has_role(&self, role: B256, account: Address) -> bool
Returns true
if account
has been granted role
.
§Arguments
&self
- Read access to the contract’s state.role
- The role identifier.account
- The account to check for membership.
sourcepub fn only_role(&self, role: B256) -> Result<(), Error>
pub fn only_role(&self, role: B256) -> Result<(), Error>
Checks if msg::sender
has been granted role
.
§Arguments
&self
- Read access to the contract’s state.role
- The role identifier.
§Errors
If msg::sender
has not been granted role
, then the error
Error::UnauthorizedAccount
is returned.
sourcepub fn get_role_admin(&self, role: B256) -> B256
pub fn get_role_admin(&self, role: B256) -> B256
Returns the admin role that controls role
. See Self::grant_role
and Self::revoke_role
.
To change a role’s admin, use Self::_set_role_admin
.
§Arguments
&self
- Read access to the contract’s state.role
- The role identifier.
sourcepub fn grant_role(&mut self, role: B256, account: Address) -> Result<(), Error>
pub fn grant_role(&mut self, role: B256, account: Address) -> Result<(), Error>
Grants role
to account
.
If account
had not been already granted role
, emits a
RoleGranted
event.
§Requirements:
- The caller must have
role
’s admin role.
§Arguments
&mut self
- Write access to the contract’s state.role
- The role identifier.account
- The account which will be granted the role.
§Errors
If msg::sender
has not been granted role
, then the error
Error::UnauthorizedAccount
is returned.
§Events
May emit a RoleGranted
event.
sourcepub fn revoke_role(&mut self, role: B256, account: Address) -> Result<(), Error>
pub fn revoke_role(&mut self, role: B256, account: Address) -> Result<(), Error>
Revokes role
from account
.
If account
had been granted role
, emits a RoleRevoked
event.
§Requirements:
- The caller must have
role
’s admin role.
§Arguments
&mut self
- Write access to the contract’s state.role
- The role identifier.account
- The account which will be revoked the role.
§Errors
If msg::sender
has not been granted role
, then the error
Error::UnauthorizedAccount
is returned.
§Events
May emit a RoleRevoked
event.
sourcepub fn renounce_role(
&mut self,
role: B256,
confirmation: Address,
) -> Result<(), Error>
pub fn renounce_role( &mut self, role: B256, confirmation: Address, ) -> Result<(), Error>
Revokes role
from the calling account.
Roles are often managed via Self::grant_role
and
Self::revoke_role
: this function’s purpose is to provide a mechanism
for accounts to lose their privileges if they are compromised (such as
when a trusted device is misplaced).
§Requirements:
- The caller must be
confirmation
.
§Arguments
&mut self
- Write access to the contract’s state.role
- The role identifier.confirmation
- The account which will be revoked the role.
§Errors
If msg::sender
is not the confirmation
address, then the error
Error::BadConfirmation
is returned.
§Events
If the calling account has its role
revoked, emits a RoleRevoked
event.
source§impl AccessControl
impl AccessControl
sourcepub fn _set_role_admin(&mut self, role: B256, new_admin_role: B256)
pub fn _set_role_admin(&mut self, role: B256, new_admin_role: B256)
Sets admin_role
as role
’s admin role.
§Arguments
&mut self
- Write access to the contract’s state.role
- The identifier of the role we are changing the admin to.new_admin_role
- The new admin role.
§Events
Emits a RoleAdminChanged
event.
sourcepub fn _check_role(&self, role: B256, account: Address) -> Result<(), Error>
pub fn _check_role(&self, role: B256, account: Address) -> Result<(), Error>
Checks if account
has been granted role
.
§Arguments
&self
- Read access to the contract’s state.role
- The role identifier.account
- The account to check for membership.
§Errors
If msg::sender
has not been granted role
, then the error
Error::UnauthorizedAccount
is returned.
sourcepub fn _grant_role(&mut self, role: B256, account: Address) -> bool
pub fn _grant_role(&mut self, role: B256, account: Address) -> bool
Attempts to grant role
to account
and returns a boolean indicating
if role
was granted.
Internal function without access restriction.
§Arguments
&mut self
- Write access to the contract’s state.role
- The role identifier.account
- The account which will be granted the role.
§Events
May emit a RoleGranted
event.
sourcepub fn _revoke_role(&mut self, role: B256, account: Address) -> bool
pub fn _revoke_role(&mut self, role: B256, account: Address) -> bool
Attempts to revoke role
from account
and returns a boolean
indicating if role
was revoked.
Internal function without access restriction.
§Arguments
&mut self
- Write access to the contract’s state.role
- The role identifier.account
- The account which will be granted the role.
§Events
May emit a RoleRevoked
event.
Trait Implementations§
source§impl<S> Router<S> for AccessControlwhere
S: TopLevelStorage + BorrowMut<Self>,
impl<S> Router<S> for AccessControlwhere
S: TopLevelStorage + BorrowMut<Self>,
source§type Storage = AccessControl
type Storage = AccessControl
TopLevelStorage
borrows into. Usually just Self
.source§fn route(storage: &mut S, selector: u32, input: &[u8]) -> Option<ArbResult>
fn route(storage: &mut S, selector: u32, input: &[u8]) -> Option<ArbResult>
None
if none is found.
Routes add via #[inherit]
will only execute if no match is found among Self
.
This means that it is possible to override a method by redefining it in Self
.source§impl StorageType for AccessControl
impl StorageType for AccessControl
source§const SLOT_BYTES: usize = 32usize
const SLOT_BYTES: usize = 32usize
StorageType::new
. Read moresource§const REQUIRED_SLOTS: usize = 1usize
const REQUIRED_SLOTS: usize = 1usize
source§type Wraps<'a> = StorageGuard<'a, AccessControl>
where
Self: 'a
type Wraps<'a> = StorageGuard<'a, AccessControl> where Self: 'a
StorageType
being collected.source§type WrapsMut<'a> = StorageGuardMut<'a, AccessControl>
where
Self: 'a
type WrapsMut<'a> = StorageGuardMut<'a, AccessControl> where Self: 'a
source§unsafe fn new(root: U256, offset: u8) -> Self
unsafe fn new(root: U256, offset: u8) -> Self
const
once generic_const_exprs
stabilizes. Read more