Owner
It provides an Owner capability that stores the IDs of other objects, Modules can assert or check if a certain ID is stored in the Owner to prove its ownership. It is used to provide access control.
Structs
OwnerCap
struct OwnerCap<phantom T> has key, store {
id: UID,
of: VecSet<ID>
}of - A set of IDs to prove that the Owner Capability has privileged access to it.
Interface
new
It creates an OwnerCap capability.
public fun new<T: drop>(_: T, of: vector<ID>, ctx: &mut TxContext): OwnerCap<T>@param _: A witness to link an OwnerCap with the module that owns the witness.
@param of: Vector of
sui::object::IDthat this capability owns.@return OwnerCap.
contains
It checks if an ID is stored in the Owner Capability.
public fun contains<T: drop>(self: &OwnerCap<T>, x: ID): bool @param self: An OwnerCap object.
@param x: The
sui::object::IDof an object.@return bool. True if the
selfownsx.
of
Returns the vector of sui::object::ID that the self owns.
public fun of<T: drop>(self: &OwnerCap<T>): vector<ID>@param self: A {OwnerCap} object.
@return vector. The vector of
sui::object::ID.
add
Assigns the self OwnerCap as the owner of x.
public fun add<T: drop>(self: &mut OwnerCap<T>, _: T, x: ID)@param self: An OwnerCap object.
@param _: A witness to make sure only the allowed module can add
sui::object::IDto the self.@param x: The
sui::object::IDof the object, which theselfwill have ownership rights to.
remove
Removes the self OwnerCap as the owner of x.
public fun remove<T: drop>(self: &mut OwnerCap<T>, _: T, x: ID)@param self: An OwnerCap object.
@param _: A witness to make sure only the right module can add the
sui::object::IDto the self.@param x: The
sui::object::IDof the object, which theselfwill lose its ownership rights to.
destroy
Destroys an OwnerCap. It does not require the of vector to be empty.
public fun destroy<T: drop>(self: OwnerCap<T>)@param self: An OwnerCap object.
destroy_empty
Destroys an OwnerCap. It requires the of vector to be empty.
public fun destroy<T: drop>(self: OwnerCap<T>)@param self: A OwnerCap object.
Aborts
If
ofvector is not empty.
assert_ownership
Asserts that the self owns x.
public fun destroy<T: drop>(self: OwnerCap<T>)@param self: An OwnerCap object.
@param x: The
sui::object::IDof the object, which must belong to the capability.
Aborts
If the ID is not owned by the capability.
Last updated
Was this helpful?