pub struct AccessControlClient<'a> {
pub env: Env,
pub address: Address,
/* private fields */
}Expand description
AccessControlClient is a client for calling the contract defined in “AccessControl”.
Fields§
§env: Env§address: AddressImplementations§
Source§impl<'a> AccessControlClient<'a>
impl<'a> AccessControlClient<'a>
Sourcepub fn has_role(&self, account: &Address, role: &Symbol) -> Option<u32>
pub fn has_role(&self, account: &Address, role: &Symbol) -> Option<u32>
Returns Some(index) if the account has the specified role,
where index is the position of the account for that role,
and can be used to query AccessControl::get_role_member().
Returns None if the account does not have the specified role.
§Arguments
e- Access to Soroban environment.account- The account to check.role- The role to check for.
Sourcepub fn try_has_role(
&self,
account: &Address,
role: &Symbol,
) -> Result<Result<Option<u32>, <Option<u32> as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
pub fn try_has_role( &self, account: &Address, role: &Symbol, ) -> Result<Result<Option<u32>, <Option<u32> as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
Returns Some(index) if the account has the specified role,
where index is the position of the account for that role,
and can be used to query AccessControl::get_role_member().
Returns None if the account does not have the specified role.
§Arguments
e- Access to Soroban environment.account- The account to check.role- The role to check for.
Sourcepub fn get_existing_roles(&self) -> Vec<Symbol>
pub fn get_existing_roles(&self) -> Vec<Symbol>
Sourcepub fn try_get_existing_roles(
&self,
) -> Result<Result<Vec<Symbol>, <Vec<Symbol> as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
pub fn try_get_existing_roles( &self, ) -> Result<Result<Vec<Symbol>, <Vec<Symbol> as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
Sourcepub fn get_role_member_count(&self, role: &Symbol) -> u32
pub fn get_role_member_count(&self, role: &Symbol) -> u32
Returns the total number of accounts that have the specified role. If the role does not exist, returns 0.
§Arguments
e- Access to Soroban environment.role- The role to get the count for.
Sourcepub fn try_get_role_member_count(
&self,
role: &Symbol,
) -> Result<Result<u32, <u32 as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
pub fn try_get_role_member_count( &self, role: &Symbol, ) -> Result<Result<u32, <u32 as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
Returns the total number of accounts that have the specified role. If the role does not exist, returns 0.
§Arguments
e- Access to Soroban environment.role- The role to get the count for.
Sourcepub fn get_role_member(&self, role: &Symbol, index: &u32) -> Address
pub fn get_role_member(&self, role: &Symbol, index: &u32) -> Address
Returns the account at the specified index for a given role.
We do not provide a function to get all the members of a role,
since that would be unbounded. If you need to enumerate all the
members of a role, you can use
AccessControl::get_role_member_count() to get the total number
of members and then use AccessControl::get_role_member() to get
each member one by one.
§Arguments
e- Access to Soroban environment.role- The role to query.index- The index of the account to retrieve.
§Errors
AccessControlError::IndexOutOfBounds- If the index is out of bounds for the role’s member list.
Sourcepub fn try_get_role_member(
&self,
role: &Symbol,
index: &u32,
) -> Result<Result<Address, <Address as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
pub fn try_get_role_member( &self, role: &Symbol, index: &u32, ) -> Result<Result<Address, <Address as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
Returns the account at the specified index for a given role.
We do not provide a function to get all the members of a role,
since that would be unbounded. If you need to enumerate all the
members of a role, you can use
AccessControl::get_role_member_count() to get the total number
of members and then use AccessControl::get_role_member() to get
each member one by one.
§Arguments
e- Access to Soroban environment.role- The role to query.index- The index of the account to retrieve.
§Errors
AccessControlError::IndexOutOfBounds- If the index is out of bounds for the role’s member list.
Sourcepub fn get_role_admin(&self, role: &Symbol) -> Option<Symbol>
pub fn get_role_admin(&self, role: &Symbol) -> Option<Symbol>
Returns the admin role for a specific role.
If no admin role is explicitly set, returns None.
§Arguments
e- Access to Soroban environment.role- The role to query the admin role for.
Sourcepub fn try_get_role_admin(
&self,
role: &Symbol,
) -> Result<Result<Option<Symbol>, <Option<Symbol> as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
pub fn try_get_role_admin( &self, role: &Symbol, ) -> Result<Result<Option<Symbol>, <Option<Symbol> as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
Returns the admin role for a specific role.
If no admin role is explicitly set, returns None.
§Arguments
e- Access to Soroban environment.role- The role to query the admin role for.
Sourcepub fn try_get_admin(
&self,
) -> Result<Result<Option<Address>, <Option<Address> as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
pub fn try_get_admin( &self, ) -> Result<Result<Option<Address>, <Option<Address> as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
Sourcepub fn grant_role(&self, account: &Address, role: &Symbol, caller: &Address)
pub fn grant_role(&self, account: &Address, role: &Symbol, caller: &Address)
Grants a role to an account.
§Arguments
e- Access to Soroban environment.account- The account to grant the role to.role- The role to grant.caller- The address of the caller, must be the admin or have theRoleAdminfor therole.
§Errors
AccessControlError::Unauthorized- If the caller does not have enough privileges.AccessControlError::MaxRolesExceeded- If adding a new role would exceed the maximum allowed number of roles.
§Events
- topics -
["role_granted", role: Symbol, account: Address] - data -
[caller: Address]
Sourcepub fn try_grant_role(
&self,
account: &Address,
role: &Symbol,
caller: &Address,
) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
pub fn try_grant_role( &self, account: &Address, role: &Symbol, caller: &Address, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
Grants a role to an account.
§Arguments
e- Access to Soroban environment.account- The account to grant the role to.role- The role to grant.caller- The address of the caller, must be the admin or have theRoleAdminfor therole.
§Errors
AccessControlError::Unauthorized- If the caller does not have enough privileges.AccessControlError::MaxRolesExceeded- If adding a new role would exceed the maximum allowed number of roles.
§Events
- topics -
["role_granted", role: Symbol, account: Address] - data -
[caller: Address]
Sourcepub fn revoke_role(&self, account: &Address, role: &Symbol, caller: &Address)
pub fn revoke_role(&self, account: &Address, role: &Symbol, caller: &Address)
Revokes a role from an account.
To revoke your own role, please use AccessControl::renounce_role()
instead.
§Arguments
e- Access to Soroban environment.account- The account to revoke the role from.role- The role to revoke.caller- The address of the caller, must be the admin or has theRoleAdminfor therole.
§Errors
AccessControlError::Unauthorized- If thecallerdoes not have enough privileges.AccessControlError::RoleNotHeld- If theaccountdoesn’t have the role.AccessControlError::RoleIsEmpty- If the role has no members.
§Events
- topics -
["role_revoked", role: Symbol, account: Address] - data -
[caller: Address]
Sourcepub fn try_revoke_role(
&self,
account: &Address,
role: &Symbol,
caller: &Address,
) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
pub fn try_revoke_role( &self, account: &Address, role: &Symbol, caller: &Address, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
Revokes a role from an account.
To revoke your own role, please use AccessControl::renounce_role()
instead.
§Arguments
e- Access to Soroban environment.account- The account to revoke the role from.role- The role to revoke.caller- The address of the caller, must be the admin or has theRoleAdminfor therole.
§Errors
AccessControlError::Unauthorized- If thecallerdoes not have enough privileges.AccessControlError::RoleNotHeld- If theaccountdoesn’t have the role.AccessControlError::RoleIsEmpty- If the role has no members.
§Events
- topics -
["role_revoked", role: Symbol, account: Address] - data -
[caller: Address]
Sourcepub fn renounce_role(&self, role: &Symbol, caller: &Address)
pub fn renounce_role(&self, role: &Symbol, caller: &Address)
Allows an account to renounce a role assigned to itself. Users can only renounce roles for their own account.
§Arguments
e- Access to Soroban environment.role- The role to renounce.caller- The address of the caller, must be the account that has the role.
§Errors
AccessControlError::RoleNotHeld- If thecallerdoesn’t have the role.AccessControlError::RoleIsEmpty- If the role has no members.
§Events
- topics -
["role_revoked", role: Symbol, account: Address] - data -
[caller: Address]
Sourcepub fn try_renounce_role(
&self,
role: &Symbol,
caller: &Address,
) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
pub fn try_renounce_role( &self, role: &Symbol, caller: &Address, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
Allows an account to renounce a role assigned to itself. Users can only renounce roles for their own account.
§Arguments
e- Access to Soroban environment.role- The role to renounce.caller- The address of the caller, must be the account that has the role.
§Errors
AccessControlError::RoleNotHeld- If thecallerdoesn’t have the role.AccessControlError::RoleIsEmpty- If the role has no members.
§Events
- topics -
["role_revoked", role: Symbol, account: Address] - data -
[caller: Address]
Sourcepub fn accept_admin_transfer(&self)
pub fn accept_admin_transfer(&self)
Initiates the admin role transfer. Admin privileges for the current admin are not revoked until the recipient accepts the transfer. Overrides the previous pending transfer if there is one.
§Arguments
e- Access to Soroban environment.new_admin- The account to transfer the admin privileges to.live_until_ledger- The ledger number at which the pending transfer expires. Iflive_until_ledgeris0, the pending transfer is cancelled.live_until_ledgerargument is implicitly bounded by the maximum allowed TTL extension for a temporary storage entry and specifying a higher value will cause the code to panic.
§Errors
crate::role_transfer::RoleTransferError::NoPendingTransfer- If trying to cancel a transfer that doesn’t exist.crate::role_transfer::RoleTransferError::InvalidLiveUntilLedger- If the specified ledger is in the past.crate::role_transfer::RoleTransferError::InvalidPendingAccount- If the specified pending account is not the same as the providednewaddress.AccessControlError::AdminNotSet- If admin account is not set.
§Events
- topics -
["admin_transfer_initiated", current_admin: Address] - data -
[new_admin: Address, live_until_ledger: u32]
§Notes
- Authorization for the current admin is required.
Sourcepub fn try_accept_admin_transfer(
&self,
) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
pub fn try_accept_admin_transfer( &self, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
Initiates the admin role transfer. Admin privileges for the current admin are not revoked until the recipient accepts the transfer. Overrides the previous pending transfer if there is one.
§Arguments
e- Access to Soroban environment.new_admin- The account to transfer the admin privileges to.live_until_ledger- The ledger number at which the pending transfer expires. Iflive_until_ledgeris0, the pending transfer is cancelled.live_until_ledgerargument is implicitly bounded by the maximum allowed TTL extension for a temporary storage entry and specifying a higher value will cause the code to panic.
§Errors
crate::role_transfer::RoleTransferError::NoPendingTransfer- If trying to cancel a transfer that doesn’t exist.crate::role_transfer::RoleTransferError::InvalidLiveUntilLedger- If the specified ledger is in the past.crate::role_transfer::RoleTransferError::InvalidPendingAccount- If the specified pending account is not the same as the providednewaddress.AccessControlError::AdminNotSet- If admin account is not set.
§Events
- topics -
["admin_transfer_initiated", current_admin: Address] - data -
[new_admin: Address, live_until_ledger: u32]
§Notes
- Authorization for the current admin is required.
Sourcepub fn transfer_admin_role(&self, new_admin: &Address, live_until_ledger: &u32)
pub fn transfer_admin_role(&self, new_admin: &Address, live_until_ledger: &u32)
Completes the 2-step admin transfer.
§Arguments
e- Access to Soroban environment.
§Events
- topics -
["admin_transfer_completed", new_admin: Address] - data -
[previous_admin: Address]
§Errors
crate::role_transfer::RoleTransferError::NoPendingTransfer- If there is no pending transfer to accept.AccessControlError::AdminNotSet- If admin account is not set.
Sourcepub fn try_transfer_admin_role(
&self,
new_admin: &Address,
live_until_ledger: &u32,
) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
pub fn try_transfer_admin_role( &self, new_admin: &Address, live_until_ledger: &u32, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
Completes the 2-step admin transfer.
§Arguments
e- Access to Soroban environment.
§Events
- topics -
["admin_transfer_completed", new_admin: Address] - data -
[previous_admin: Address]
§Errors
crate::role_transfer::RoleTransferError::NoPendingTransfer- If there is no pending transfer to accept.AccessControlError::AdminNotSet- If admin account is not set.
Sourcepub fn set_role_admin(&self, role: &Symbol, admin_role: &Symbol)
pub fn set_role_admin(&self, role: &Symbol, admin_role: &Symbol)
Sets admin_role as the admin role of role.
§Arguments
e- Access to Soroban environment.role- The role to set the admin for.admin_role- The new admin role.
§Events
- topics -
["role_admin_changed", role: Symbol] - data -
[previous_admin_role: Symbol, new_admin_role: Symbol]
§Errors
AccessControlError::AdminNotSet- If admin account is not set.
§Notes
- Authorization for the current admin is required.
Sourcepub fn try_set_role_admin(
&self,
role: &Symbol,
admin_role: &Symbol,
) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
pub fn try_set_role_admin( &self, role: &Symbol, admin_role: &Symbol, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
Sets admin_role as the admin role of role.
§Arguments
e- Access to Soroban environment.role- The role to set the admin for.admin_role- The new admin role.
§Events
- topics -
["role_admin_changed", role: Symbol] - data -
[previous_admin_role: Symbol, new_admin_role: Symbol]
§Errors
AccessControlError::AdminNotSet- If admin account is not set.
§Notes
- Authorization for the current admin is required.
Sourcepub fn renounce_admin(&self)
pub fn renounce_admin(&self)
Allows the current admin to renounce their role, making the contract permanently admin-less. This is useful for decentralization purposes or when the admin role is no longer needed. Once the admin is renounced, it cannot be reinstated.
§Arguments
e- Access to Soroban environment.
§Errors
AccessControlError::AdminNotSet- If no admin account is set.
§Events
- topics -
["admin_renounced", admin: Address] - data -
[]
§Notes
- Authorization for the current admin is required.
Sourcepub fn try_renounce_admin(
&self,
) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
pub fn try_renounce_admin( &self, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>
Allows the current admin to renounce their role, making the contract permanently admin-less. This is useful for decentralization purposes or when the admin role is no longer needed. Once the admin is renounced, it cannot be reinstated.
§Arguments
e- Access to Soroban environment.
§Errors
AccessControlError::AdminNotSet- If no admin account is set.
§Events
- topics -
["admin_renounced", admin: Address] - data -
[]
§Notes
- Authorization for the current admin is required.
Auto Trait Implementations§
impl<'a> Freeze for AccessControlClient<'a>
impl<'a> !RefUnwindSafe for AccessControlClient<'a>
impl<'a> !Send for AccessControlClient<'a>
impl<'a> !Sync for AccessControlClient<'a>
impl<'a> Unpin for AccessControlClient<'a>
impl<'a> !UnwindSafe for AccessControlClient<'a>
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<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W), b: &(T, U, V, W), ) -> Result<Ordering, <C as Compare<(T, U, V, W)>>::Error>
Source§impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W, X), b: &(T, U, V, W, X), ) -> Result<Ordering, <C as Compare<(T, U, V, W, X)>>::Error>
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.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