Assign Metadata Roles
  • 17 Oct 2023
  • 1 Minute to read
  • Dark
    Light
  • PDF

Assign Metadata Roles

  • Dark
    Light
  • PDF

Article summary

Assign AccessRules for Metadata Roles

Every component has Metadata and a set of Metadata Roles:

Role

Authority Description

Methods Accessible

metadata_setter

Update a metadata entry

Metadata::set(..)

Metadata::remove(..)

metadata_setter_updater

Update the AccessRule of the metadata_setter

RoleAssignment::set(ModuleId::Metadata, "metadata_setter", ..)

metadata_locker

Lock metadata entries such that they are no longer updateable

Metadata::lock(..)

metadata_locker_updater

Update the AccessRule of the metadata_locker

RoleAssignment::set(ModuleId::Metadata, "metadata_locker", ..)

By default, the Owner Role will inherit all Metadata Roles.

Assign Custom AccessRules for Metadata Roles

If custom access rules for each metadata role are required (rather than the Owner role inheriting all roles) then add roles to the metadata! macro during component globalization:

#[blueprint]
mod my_token_sale {
    enable_method_auth! {
        roles {
            super_admin_role => updatable_by: [];
            admin_role => updatable_by: [super_admin_role];
        },
        methods { .. }
    }

    struct MyTokenSale { .. }
    
    impl MyTokenSale {
        pub fn create() {
            let owner_badge: Bucket = { .. };
            let owner_access_rule: AccessRule = { .. };
            let metadata_setter_access_rule: AccessRule = { .. };

            MyTokenSale { .. }
                .instantiate()
                .prepare_to_globalize(OwnerRole::Fixed(owner_access_rule))
                .metadata(metadata! {
                    roles {
                        metadata_setter => metadata_setter_access_rule.clone(); // #1
                        metadata_setter_updater => metadata_setter_access_rule;
                        metadata_locker => OWNER; // #2
                        metadata_locker_updater => rule!(deny_all); // #3
                    }
                })
                .globalize()

          ..
        }
        ..
    }
}
  1. The metadata_setter_access_rule is assigned to the metadata_setter role

  2. Using OWNER specifies that the owner role will inherit the metadata_locker role

  3. The metadata_locker_updater role is not accessible by anyone effectively “locking” in the AccessRule of metadata_locker



Was this article helpful?