sui::party
Party
Permissions
single_owner
transfer
public_transfer
empty
set_permissions
is_single_owner
into_native
use std::option;
use std::vector;
use sui::vec_map;
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
default: sui::party::Permissions
members
map.
members: sui::vec_map::VecMap<address, sui::party::Permissions>
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
0: u64
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;
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
public fun single_owner(owner: address): Party {
let mut mp = empty();
mp.set_permissions(owner, Permissions(ALL_PERMISSIONS));
mp
}
transfer
A helper macro
that calls sui::transfer::party_transfer
.
public macro fun transfer<$T: key>($self: sui::party::Party, $obj: $T)
public macro fun transfer<$T: key>($self: Party, $obj: $T) {
let mp = $self;
sui::transfer::party_transfer($obj, mp)
}
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)
public macro fun public_transfer<$T: key + store>($self: Party, $obj: $T) {
let mp = $self;
sui::transfer::public_party_transfer($obj, mp)
}
empty
fun empty(): sui::party::Party
fun empty(): Party {
Party {
default: Permissions(NO_PERMISSIONS),
members: vec_map::empty(),
}
}
set_permissions
fun set_permissions(p: &mut sui::party::Party, address: address, permissions: sui::party::Permissions)
fun set_permissions(p: &mut Party, address: address, permissions: Permissions) {
if (p.members.contains(&address)) {
p.members.remove(&address);
};
p.members.insert(address, permissions);
}
is_single_owner
public(package) fun is_single_owner(p: &sui::party::Party): bool
public(package) fun is_single_owner(p: &Party): bool {
p.default.0 == NO_PERMISSIONS &&
p.members.length() == 1 &&
{ let (_, m) = p.members.get_entry_by_idx(0); m.0 == ALL_PERMISSIONS }
}
into_native
public(package) fun into_native(p: sui::party::Party): (u64, vector<address>, vector<u64>)
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)
}