Skip to main content

Module sui::party

use std::option;
use std::vector;
use sui::vec_map;

Struct Party

The permissions that apply to a party object. If the transaction sender has an entry in the members map, the permissions in that entry apply. Otherwise, the default permissions are used. If the party has the READ permission, the object can be taken as an immutable input. If the party has the WRITE, DELETE, or TRANSFER permissions, the object can be taken as a mutable input. Additional restrictions pertaining to each permission are checked at the end of transaction execution.

public struct Party has copy, drop
Click to open
Fields
default: sui::party::Permissions
The permissions that apply if no specific permissions are set in the members map.
members: sui::vec_map::VecMap<address, sui::party::Permissions>
The permissions per transaction sender.

Struct Permissions

The permissions that a party has. The permissions are a bitset of the READ, WRITE, DELETE, and TRANSFER constants.

public struct Permissions has copy, drop
Click to open
Fields
0: u64

Constants

A party can read the object, taking it as an immutable argument. This restriction is checked when sending the transaction.

const READ: u8 = 1;

The party can mutate the object, but not change its owner or delete it. This is checked at end end of transaction execution.

const WRITE: u8 = 2;

The party can delete the object, but not otherwise modify it. This is checked at the end of transaction execution.

const DELETE: u8 = 4;

The party can change the owner of the object, but not otherwise modify it. This is checked at the end of transaction execution.

const TRANSFER: u8 = 8;

No permissions.

const NO_PERMISSIONS: u64 = 0;

All permissions.

const ALL_PERMISSIONS: u64 = 15;

Function single_owner

Creates a Party value with a single "owner" that has all permissions. No other party has any permissions. And there are no default permissions.

public fun single_owner(owner: address): sui::party::Party
Click to open
Implementation
public fun single_owner(owner: address): Party {
    let mut mp = empty();
    mp.set_permissions(owner, Permissions(ALL_PERMISSIONS));
    mp
}

Macro function transfer

A helper macro that calls sui::transfer::party_transfer.

public macro fun transfer<$T: key>($self: sui::party::Party, $obj: $T)
Click to open
Implementation
public macro fun transfer<$T: key>($self: Party, $obj: $T) {
    let mp = $self;
    sui::transfer::party_transfer($obj, mp)
}

Macro function public_transfer

A helper macro that calls sui::transfer::public_party_transfer.

public macro fun public_transfer<$T: key, store>($self: sui::party::Party, $obj: $T)
Click to open
Implementation
public macro fun public_transfer<$T: key + store>($self: Party, $obj: $T) {
    let mp = $self;
    sui::transfer::public_party_transfer($obj, mp)
}

Function empty

fun empty(): sui::party::Party
Click to open
Implementation
fun empty(): Party {
Party {
default: Permissions(NO_PERMISSIONS),
members: vec_map::empty(),
}
}

Function set_permissions

fun set_permissions(p: &mut sui::party::Party, address: address, permissions: sui::party::Permissions)
Click to open
Implementation
fun set_permissions(p: &mut Party, address: address, permissions: Permissions) {
if (p.members.contains(&address)) {
p.members.remove(&address);
};
p.members.insert(address, permissions);
}

Function is_single_owner

public(package) fun is_single_owner(p: &sui::party::Party): bool
Click to open
Implementation
public(package) fun is_single_owner(p: &Party): bool {
    p.default.0 == NO_PERMISSIONS &&
    p.members.size() == 1 &&
    { let (_, m) = p.members.get_entry_by_idx(0); m.0 == ALL_PERMISSIONS }
}

Function into_native

public(package) fun into_native(p: sui::party::Party): (u64, vector<address>, vector<u64>)
Click to open
Implementation
public(package) fun into_native(p: Party): (u64, vector<address>, vector<u64>) {
    let Party { default, members } = p;
    let (addresses, permissions) = members.into_keys_values();
    let permissions = permissions.map!(|Permissions(x)| x);
    (default.0, addresses, permissions)
}