Module sui::object
Sui object identifiers
- Struct ID
- Struct UID
- Constants
- Function id_to_bytes
- Function id_to_address
- Function id_from_bytes
- Function id_from_address
- Function sui_system_state
- Function clock
- Function authenticator_state
- Function randomness_state
- Function sui_deny_list_object_id
- Function sui_accumulator_root_object_id
- Function sui_accumulator_root_address
- Function sui_coin_registry_object_id
- Function sui_coin_registry_address
- Function bridge
- Function uid_as_inner
- Function uid_to_inner
- Function uid_to_bytes
- Function uid_to_address
- Function new
- Function delete
- Function id
- Function borrow_id
- Function id_bytes
- Function id_address
- Function borrow_uid
- Function new_uid_from_hash
- Function delete_impl
- Function record_new_uid
use std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::vector;
use sui::address;
use sui::hex;
use sui::tx_context;
Struct ID
An object ID. This is used to reference Sui Objects. This is not guaranteed to be globally unique--anyone can create an
IDUIDIDobject::id(&obj)obj, and each IDpublic struct ID has copy, drop, store
Fields
- 
bytes: address
Struct UID
Globally unique IDs that define an object's ID in storage. Any Sui Object, that is a struct
with the key ability, must have 
id: UIDUIDid1: UIDid2: UIDid1 != id2.
This is a privileged type that can only be derived from a TxContext.
UIDdrop ability, so deleting a UIDdeletepublic struct UID has store
Fields
Constants
The hardcoded ID for the singleton Sui System State Object.
const SUI_SYSTEM_STATE_OBJECT_ID: address = 0x5;
The hardcoded ID for the singleton Clock Object.
const SUI_CLOCK_OBJECT_ID: address = 0x6;
The hardcoded ID for the singleton AuthenticatorState Object.
const SUI_AUTHENTICATOR_STATE_ID: address = 0x7;
The hardcoded ID for the singleton Random Object.
const SUI_RANDOM_ID: address = 0x8;
The hardcoded ID for the singleton DenyList.
const SUI_DENY_LIST_OBJECT_ID: address = 0x403;
The hardcoded ID for the singleton AccumulatorRoot Object.
const SUI_ACCUMULATOR_ROOT_OBJECT_ID: address = 0xacc;
The hardcoded ID for the Bridge Object.
const SUI_BRIDGE_ID: address = 0x9;
The hardcoded ID for the Coin Registry Object.
const SUI_COIN_REGISTRY_OBJECT_ID: address = 0xc;
Sender is not @0x0 the system address.
const ENotSystemAddress: u64 = 0;
Function id_to_bytes
Get the raw bytes of a
IDpublic fun id_to_bytes(id: &sui::object::ID): vector<u8>
Implementation
public fun id_to_bytes(id: &ID): vector<u8> {
    bcs::to_bytes(&id.bytes)
}
Function id_to_address
Get the inner bytes of
idpublic fun id_to_address(id: &sui::object::ID): address
Implementation
public fun id_to_address(id: &ID): address {
    id.bytes
}
Function id_from_bytes
Make an
IDpublic fun id_from_bytes(bytes: vector<u8>): sui::object::ID
Implementation
public fun id_from_bytes(bytes: vector<u8>): ID {
    address::from_bytes(bytes).to_id()
}
Function id_from_address
Make an
IDpublic fun id_from_address(bytes: address): sui::object::ID
Implementation
public fun id_from_address(bytes: address): ID {
    ID { bytes }
}
Function sui_system_state
Create the
UIDSuiSystemState object.
This should only be called once from sui_system.
fun sui_system_state(ctx: &sui::tx_context::TxContext): sui::object::UID
Implementation
fun sui_system_state(ctx: &TxContext): UID {
    assert!(ctx.sender() == @0x0, ENotSystemAddress);
    UID {
        id: ID { bytes: SUI_SYSTEM_STATE_OBJECT_ID },
    }
}
Function clock
Create the
UIDClock object.
This should only be called once from clockpublic(package) fun clock(): sui::object::UID
Function authenticator_state
Create the
UIDAuthenticatorState object.
This should only be called once from authenticator_statepublic(package) fun authenticator_state(): sui::object::UID
Implementation
public(package) fun authenticator_state(): UID {
    UID {
        id: ID { bytes: SUI_AUTHENTICATOR_STATE_ID },
    }
}
Function randomness_state
Create the
UIDRandom object.
This should only be called once from randompublic(package) fun randomness_state(): sui::object::UID
Implementation
public(package) fun randomness_state(): UID {
    UID {
        id: ID { bytes: SUI_RANDOM_ID },
    }
}
Function sui_deny_list_object_id
Create the
UIDDenyList object.
This should only be called once from deny_listpublic(package) fun sui_deny_list_object_id(): sui::object::UID
Implementation
public(package) fun sui_deny_list_object_id(): UID {
    UID {
        id: ID { bytes: SUI_DENY_LIST_OBJECT_ID },
    }
}
Function sui_accumulator_root_object_id
public(package) fun sui_accumulator_root_object_id(): sui::object::UID
Implementation
public(package) fun sui_accumulator_root_object_id(): UID {
    UID {
        id: ID { bytes: SUI_ACCUMULATOR_ROOT_OBJECT_ID },
    }
}
Function sui_accumulator_root_address
public(package) fun sui_accumulator_root_address(): address
Implementation
public(package) fun sui_accumulator_root_address(): address {
    SUI_ACCUMULATOR_ROOT_OBJECT_ID
}
Function sui_coin_registry_object_id
Create the
UIDCoinRegistry object.
This should only be called once from coin_registrypublic(package) fun sui_coin_registry_object_id(): sui::object::UID
Implementation
public(package) fun sui_coin_registry_object_id(): UID {
    UID {
        id: ID { bytes: SUI_COIN_REGISTRY_OBJECT_ID },
    }
}
Function sui_coin_registry_address
public(package) fun sui_coin_registry_address(): address
Implementation
public(package) fun sui_coin_registry_address(): address {
    SUI_COIN_REGISTRY_OBJECT_ID
}
Function bridge
Create the
UIDBridge object.
This should only be called once from bridgefun bridge(): sui::object::UID
Function uid_as_inner
Get the inner
IDuid
public fun uid_as_inner(uid: &sui::object::UID): &sui::object::ID
Implementation
public fun uid_as_inner(uid: &UID): &ID {
    &uid.id
}
Function uid_to_inner
Get the raw bytes of a uid's inner 
IDpublic fun uid_to_inner(uid: &sui::object::UID): sui::object::ID
Implementation
public fun uid_to_inner(uid: &UID): ID {
    uid.id
}
Function uid_to_bytes
Get the raw bytes of a
UIDpublic fun uid_to_bytes(uid: &sui::object::UID): vector<u8>
Implementation
public fun uid_to_bytes(uid: &UID): vector<u8> {
    bcs::to_bytes(&uid.id.bytes)
}
Function uid_to_address
Get the inner bytes of
idpublic fun uid_to_address(uid: &sui::object::UID): address
Implementation
public fun uid_to_address(uid: &UID): address {
    uid.id.bytes
}
Function new
Create a new object. Returns the
UIDUIDpublic fun new(ctx: &mut sui::tx_context::TxContext): sui::object::UID
Function delete
Delete the object and its
UIDUIDUIDpublic fun delete(id: sui::object::UID)
Function id
Get the underlying
IDobj
public fun id<T: key>(obj: &T): sui::object::ID
Implementation
public fun id<T: key>(obj: &T): ID {
    borrow_uid(obj).id
}
Function borrow_id
Borrow the underlying
IDobj
public fun borrow_id<T: key>(obj: &T): &sui::object::ID
Implementation
public fun borrow_id<T: key>(obj: &T): &ID {
    &borrow_uid(obj).id
}
Function id_bytes
Get the raw bytes for the underlying
IDobj
public fun id_bytes<T: key>(obj: &T): vector<u8>
Implementation
public fun id_bytes<T: key>(obj: &T): vector<u8> {
    bcs::to_bytes(&borrow_uid(obj).id)
}
Function id_address
Get the inner bytes for the underlying
IDobj
public fun id_address<T: key>(obj: &T): address
Implementation
public fun id_address<T: key>(obj: &T): address {
    borrow_uid(obj).id.bytes
}
Function borrow_uid
Get the
UIDobj.
Safe because Sui has an extra bytecode verifier pass that forces every struct with
the key ability to have a distinguished UIDUIDfun borrow_uid<T: key>(obj: &T): &sui::object::UID
Implementation
native fun borrow_uid<T: key>(obj: &T): &UID;
Function new_uid_from_hash
Generate a new UID specifically used for creating a UID from a hash
public(package) fun new_uid_from_hash(bytes: address): sui::object::UID
Implementation
public(package) fun new_uid_from_hash(bytes: address): UID {
    record_new_uid(bytes);
    UID { id: ID { bytes } }
}
Function delete_impl
fun delete_impl(id: address)
Implementation
native fun delete_impl(id: address);
Function record_new_uid
fun record_new_uid(id: address)
Implementation
native fun record_new_uid(id: address);