- 17 Oct 2023
- 1 Minute to read
- DarkLight
- PDF
Assign Metadata Roles
- Updated on 17 Oct 2023
- 1 Minute to read
- DarkLight
- PDF
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_setter_updater | Update the AccessRule of the metadata_setter |
|
metadata_locker | Lock metadata entries such that they are no longer updateable |
|
metadata_locker_updater | Update the AccessRule of the 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()
..
}
..
}
}
The
metadata_setter_access_rule
is assigned to themetadata_setter
roleUsing
OWNER
specifies that the owner role will inherit themetadata_locker
roleThe
metadata_locker_updater
role is not accessible by anyone effectively “locking” in the AccessRule ofmetadata_locker