Module 0x2::labeler
Defines a LabelerCap used for creating labels in a iota::timelock::Timelock
object.
The LabelerCap can be created only be consuming an OTW, making then labels unique for each cap.
use 0x2::object;
use 0x2::tx_context;
use 0x2::types;
Resource LabelerCap
LabelerCap
allows to create labels of the specific type L
.
Can be publicly transferred like any other object.
struct LabelerCap<L> has store, key
Fields
id: object::UID
Constants
Error code for when a type passed to the create_labeler_cap
function is not a one-time witness.
const ENotOneTimeWitness: u64 = 0;
Function create_labeler_cap
Create a LabelerCap
instance.
Can be created only by consuming a one time witness.
public fun create_labeler_cap<L: drop>(witness: L, ctx: &mut tx_context::TxContext): labeler::LabelerCap<L>
Implementation
public fun create_labeler_cap<L: drop>(witness: L, ctx: &mut TxContext): LabelerCap<L> {
assert!(iota::types::is_one_time_witness(&witness), ENotOneTimeWitness);
LabelerCap<L> {
id: object::new(ctx),
}
}
Function destroy_labeler_cap
Delete a LabelerCap
instance.
If a capability is destroyed, it is impossible to add the related labels.
public fun destroy_labeler_cap<L>(cap: labeler::LabelerCap<L>)
Implementation
public fun destroy_labeler_cap<L>(cap: LabelerCap<L>) {
let LabelerCap<L> {
id,
} = cap;
object::delete(id);
}