pub struct AccessControl { /* private fields */ }Expand description
This contract module enables the implementation of role-based access control mechanisms for children modules.
Roles are identified by their 32-bytes identifier, which should be unique and exposed in the external API.
Roles can be used to represent a set of permissions, and the hasRole function is used to restrict access to a function call.
Roles can be granted and revoked dynamically using the grant_role() and
revoke_role() functions,
respectively. Each role has an associated admin role, and only accounts that have the role’s admin role
can call grant_role and revoke_role.
By default, the admin role for all roles is DEFAULT_ADMIN_ROLE, which means that only accounts with
this role can grant or revoke other roles.
More complex role relationships can be established using the set_admin_role() function.
Implementations§
Source§impl AccessControl
impl AccessControl
Sourcepub fn has_role(&self, role: &Role, address: &Address) -> bool
pub fn has_role(&self, role: &Role, address: &Address) -> bool
Returns true if account has been granted role.
Sourcepub fn get_role_admin(&self, role: &Role) -> Role
pub fn get_role_admin(&self, role: &Role) -> Role
Returns the admin role that controls role.
The admin role may be changed using set_admin_role().
Sourcepub fn grant_role(&mut self, role: &Role, address: &Address)
pub fn grant_role(&mut self, role: &Role, address: &Address)
Grants role to address.
If the role has been already granted - nothing happens,
otherwise RoleGranted event is emitted.
The caller must have role’s admin role.
Sourcepub fn revoke_role(&mut self, role: &Role, address: &Address)
pub fn revoke_role(&mut self, role: &Role, address: &Address)
Grants role to address.
If the role has been already revoked - nothing happens,
otherwise RoleRevoked event is emitted.
The caller must have role’s admin role.
Sourcepub fn renounce_role(&mut self, role: &Role, address: &Address)
pub fn renounce_role(&mut self, role: &Role, address: &Address)
The function is used to remove a role from the account that initiated the call.
One common way of managing roles is by using grant_role()
and revoke_role().
The purpose of revokeRole is to provide a mechanism for revoking privileges from an account
in case it gets compromised.
If the account had previously been granted the role, the function will trigger a RoleRevoked event.
Note that only address is authorized to call this function.
Source§impl AccessControl
impl AccessControl
Sourcepub fn check_role(&self, role: &Role, address: &Address)
pub fn check_role(&self, role: &Role, address: &Address)
Ensures address has role. If not, reverts with Error::MissingRole.
Sourcepub fn set_admin_role(&mut self, role: &Role, admin_role: &Role)
pub fn set_admin_role(&mut self, role: &Role, admin_role: &Role)
Sets admin_role as role’s admin role.
Emits a RoleAdminChanged event.
Sourcepub fn unchecked_grant_role(&mut self, role: &Role, address: &Address)
pub fn unchecked_grant_role(&mut self, role: &Role, address: &Address)
Grants role to address.
Internal function without access restriction. This function should be used to setup the initial access control.
May emit a RoleGranted event.
Sourcepub fn unchecked_revoke_role(&mut self, role: &Role, address: &Address)
pub fn unchecked_revoke_role(&mut self, role: &Role, address: &Address)
Revokes role from address.
Internal function without access restriction. This function should be used to setup the initial access control.
May emit a RoleRevoked event.
Trait Implementations§
Source§impl HasEntrypoints for AccessControl
impl HasEntrypoints for AccessControl
Source§fn entrypoints() -> Vec<Entrypoint>
fn entrypoints() -> Vec<Entrypoint>
Source§impl HasEvents for AccessControl
impl HasEvents for AccessControl
Source§impl Module for AccessControl
impl Module for AccessControl
Source§fn new(env: Rc<ContractEnv>) -> Self
fn new(env: Rc<ContractEnv>) -> Self
Source§fn env(&self) -> Rc<ContractEnv>
fn env(&self) -> Rc<ContractEnv>
Source§impl OdraContract for AccessControl
impl OdraContract for AccessControl
Source§type ContractRef = AccessControlContractRef
type ContractRef = AccessControlContractRef
Source§type UpgradeArgs = NoArgs
type UpgradeArgs = NoArgs
Source§impl SchemaCustomTypes for AccessControl
impl SchemaCustomTypes for AccessControl
Source§fn schema_types() -> Vec<Option<CustomType>>
fn schema_types() -> Vec<Option<CustomType>>
Source§impl SchemaEntrypoints for AccessControl
impl SchemaEntrypoints for AccessControl
Source§fn schema_entrypoints() -> Vec<Entrypoint>
fn schema_entrypoints() -> Vec<Entrypoint>
Source§impl SchemaErrors for AccessControl
impl SchemaErrors for AccessControl
Source§impl SchemaEvents for AccessControl
impl SchemaEvents for AccessControl
Source§fn custom_types() -> Vec<Option<CustomType>>
fn custom_types() -> Vec<Option<CustomType>>
Auto Trait Implementations§
impl Freeze for AccessControl
impl !RefUnwindSafe for AccessControl
impl !Send for AccessControl
impl !Sync for AccessControl
impl Unpin for AccessControl
impl !UnwindSafe for AccessControl
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<R> Deployer<R> for Rwhere
R: OdraContract,
impl<R> Deployer<R> for Rwhere
R: OdraContract,
Source§fn deploy(
env: &HostEnv,
init_args: <R as OdraContract>::InitArgs,
) -> <R as OdraContract>::HostRef
fn deploy( env: &HostEnv, init_args: <R as OdraContract>::InitArgs, ) -> <R as OdraContract>::HostRef
Source§fn try_deploy(
env: &HostEnv,
init_args: <R as OdraContract>::InitArgs,
) -> Result<<R as OdraContract>::HostRef, OdraError>
fn try_deploy( env: &HostEnv, init_args: <R as OdraContract>::InitArgs, ) -> Result<<R as OdraContract>::HostRef, OdraError>
Source§fn deploy_with_cfg(
env: &HostEnv,
init_args: <R as OdraContract>::InitArgs,
cfg: InstallConfig,
) -> <R as OdraContract>::HostRef
fn deploy_with_cfg( env: &HostEnv, init_args: <R as OdraContract>::InitArgs, cfg: InstallConfig, ) -> <R as OdraContract>::HostRef
Source§fn try_deploy_with_cfg(
env: &HostEnv,
init_args: <R as OdraContract>::InitArgs,
cfg: InstallConfig,
) -> Result<<R as OdraContract>::HostRef, OdraError>
fn try_deploy_with_cfg( env: &HostEnv, init_args: <R as OdraContract>::InitArgs, cfg: InstallConfig, ) -> Result<<R as OdraContract>::HostRef, OdraError>
Source§fn try_upgrade(
env: &HostEnv,
contract_to_upgrade: Address,
upgrade_args: <R as OdraContract>::UpgradeArgs,
) -> Result<<R as OdraContract>::HostRef, OdraError>
fn try_upgrade( env: &HostEnv, contract_to_upgrade: Address, upgrade_args: <R as OdraContract>::UpgradeArgs, ) -> Result<<R as OdraContract>::HostRef, OdraError>
Source§fn try_upgrade_with_cfg(
env: &HostEnv,
contract_to_upgrade: Address,
upgrade_args: <R as OdraContract>::UpgradeArgs,
cfg: UpgradeConfig,
) -> Result<<R as OdraContract>::HostRef, OdraError>
fn try_upgrade_with_cfg( env: &HostEnv, contract_to_upgrade: Address, upgrade_args: <R as OdraContract>::UpgradeArgs, cfg: UpgradeConfig, ) -> Result<<R as OdraContract>::HostRef, OdraError>
Source§impl<T> HostRefLoader<<T as OdraContract>::HostRef> for Twhere
T: OdraContract,
impl<T> HostRefLoader<<T as OdraContract>::HostRef> for Twhere
T: OdraContract,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more