Stellar Macros
Macros for Stellar contracts.
Modules
Default Implementation
The #[default_impl] macro generates missing default implementations for traits provided by the Stellar library.
Usage Examples
use ;
use ;
use default_impl;
;
Supported Traits
FungibleTokenFungibleBurnableNonFungibleTokenNonFungibleBurnableNonFungibleEnumerableAccessControlOwnable
Access Control Macros
Macros for role-based and ownership-based access control.
Usage Examples
use ;
use ;
;
Available Macros
#[only_admin]: Restricts access to admin only#[only_role(account, "role")]: Role check with authorization#[has_role(account, "role")]: Role check without authorization#[has_any_role(account, ["role1", "role2"])]: Multiple role check without authorization#[only_any_role(account, ["role1", "role2"])]: Multiple role check with authorization#[only_owner]: Restricts access to owner only
Important: Some macros perform role checking without authorization, while others include both:
- Role Check Only (
#[has_role],#[has_any_role]): Verify role membership but don't callrequire_auth() - Role Check + Auth (
#[only_role],#[only_any_role]): Verify role membership AND callrequire_auth()
Use role-only macros when your function already contains require_auth() calls to avoid duplicate authorization panics.
Pausable Macros
Macros for implementing pausable functionality in contracts.
Usage Examples
use ;
use ;
;
Available Macros
#[when_not_paused]: Function executes only when contract is not paused#[when_paused]: Function executes only when contract is paused
Upgradeable Macros
Derive macros for implementing contract upgradeability.
Usage Examples
use ;
use UpgradeableInternal;
use Upgradeable;
;
Available Derives
#[derive(Upgradeable)]: Basic contract upgradeability#[derive(UpgradeableMigratable)]: Upgradeability with migration support
Installation
Add this to your Cargo.toml:
[]
# We recommend pinning to a specific version, because rapid iterations are expected as the library is in an active development phase.
= "=0.4.0"
Examples
See the following examples in the repository:
examples/fungible-pausable/- Pausable macros usageexamples/nft-access-control/- Access control macrosexamples/upgradeable/- Upgradeable derive macros
License
This package is part of the Stellar Contracts library and follows the same licensing terms.