#[has_role]Expand description
A procedural macro that ensures the parameter has the specified role.
§Security Warning
IMPORTANT: This macro checks role membership but does NOT enforce
authorization. This design prevents duplicate require_auth() calls which
would cause panics in Stellar contracts. Use this macro when:
- The function already contains a
require_auth()call - Additional role-based access control is needed
If both role checking AND authorization are needed, use #[only_role]
instead.
§Usage
#[has_role(account, "minter")]
pub fn mint_tokens(e: &Env, amount: u32, account: Address) {
// Function body
}This will expand to:
pub fn mint_tokens(e: &Env, amount: u32, account: Address) {
stellar_access::access_control::ensure_role(
e,
&account,
&soroban_sdk::Symbol::new(e, "minter"),
);
// Function body
}