Skip to main content

Module iota::object

IOTA object identifiers

use iota::address; use iota::hex; use iota::tx_context; use std::ascii; use std::bcs; use std::option; use std::string; use std::vector;

Module Functions​

pub borrow_id​

Borrow the underlying ID of obj

public fun borrow_id<T: key>(obj: &T): &iota::object::ID

Implementation

public fun borrow_id<T: key>(obj: &T): &ID {     &borrow_uid(obj).id }

pub id​

Get the underlying ID of obj

public fun id<T: key>(obj: &T): iota::object::ID

Implementation

public fun id<T: key>(obj: &T): ID {     borrow_uid(obj).id }

pub id_address​

Get the inner bytes for the underlying ID of obj

public fun id_address<T: key>(obj: &T): address

Implementation

public fun id_address<T: key>(obj: &T): address {     borrow_uid(obj).id.bytes }

pub id_bytes​

Get the raw bytes for the underlying ID of obj

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) }

pub id_from_address​

Make an ID from an address.

public fun id_from_address(bytes: address): iota::object::ID

Implementation

public fun id_from_address(bytes: address): ID {     ID { bytes } }

pub id_from_bytes​

Make an ID from raw bytes.

public fun id_from_bytes(bytes: vector<u8>): iota::object::ID

Implementation

public fun id_from_bytes(bytes: vector<u8>): ID {     address::from_bytes(bytes).to_id() }

pub new​

Create a new object. Returns the UID that must be stored in an IOTA object. This is the only way to create UIDs.

public fun new(ctx: &mut iota::tx_context::TxContext): iota::object::UID

Implementation

public fun new(ctx: &mut TxContext): UID {     UID {         id: ID { bytes: ctx.fresh_object_address() },     } }

pub(pkg) authenticator_state​

Create the UID for the singleton AuthenticatorState object. This should only be called once from authenticator_state.

public(package) fun authenticator_state(): iota::object::UID

Implementation

public(package) fun authenticator_state(): UID {     UID {         id: ID { bytes: IOTA_AUTHENTICATOR_STATE_ID },     } }

pub(pkg) clock​

Create the UID for the singleton Clock object. This should only be called once from clock.

public(package) fun clock(): iota::object::UID

Implementation

public(package) fun clock(): UID {     UID {         id: ID { bytes: IOTA_CLOCK_OBJECT_ID },     } }

pub(pkg) iota_deny_list_object_id​

Create the UID for the singleton DenyList object. This should only be called once from deny_list.

public(package) fun iota_deny_list_object_id(): iota::object::UID

Implementation

public(package) fun iota_deny_list_object_id(): UID {     UID {         id: ID { bytes: IOTA_DENY_LIST_OBJECT_ID },     } }

pub(pkg) 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): iota::object::UID

Implementation

public(package) fun new_uid_from_hash(bytes: address): UID {     record_new_uid(bytes);     UID { id: ID { bytes } } }

pub(pkg) randomness_state​

Create the UID for the singleton Random object. This should only be called once from random.

public(package) fun randomness_state(): iota::object::UID

Implementation

public(package) fun randomness_state(): UID {     UID {         id: ID { bytes: IOTA_RANDOM_ID },     } }

pub(pkg) transaction_deny_rules​

Create the UID for the singleton TransactionDenyRules object. This should only be called once from transaction_deny_rules.

public(package) fun transaction_deny_rules(): iota::object::UID

Implementation

public(package) fun transaction_deny_rules(): UID {     UID {         id: ID { bytes: IOTA_TRANSACTION_DENY_RULES_OBJECT_ID },     } }

prv borrow_uid​

Get the UID for obj. Safe because IOTA has an extra bytecode verifier pass that forces every struct with the key ability to have a distinguished UID field. Cannot be made public as the access to UID for a given object must be privileged, and restrictable in the object's module.

fun borrow_uid<T: key>(obj: &T): &iota::object::UID

Implementation

native fun borrow_uid<T: key>(obj: &T): &UID;

prv delete_impl​

fun delete_impl(id: address)

Implementation

native fun delete_impl(id: address);

prv iota_system_state​

Create the UID for the singleton IotaSystemState object. This should only be called once from iota_system.

fun iota_system_state(ctx: &iota::tx_context::TxContext): iota::object::UID

Implementation

fun iota_system_state(ctx: &TxContext): UID {     assert!(ctx.sender() == @0x0, ENotSystemAddress);     UID {         id: ID { bytes: IOTA_SYSTEM_STATE_OBJECT_ID },     } }

prv record_new_uid​

fun record_new_uid(id: address)

Implementation

native fun record_new_uid(id: address);

Structs​

struct ID​

An object ID. This is used to reference IOTA Objects. This is not guaranteed to be globally unique--anyone can create an ID from a UID or from an object, and ID's can be freely copied and dropped. Here, the values are not globally unique because there can be multiple values of type ID with the same underlying bytes. For example, object::id(&obj) can be called as many times as you want for a given obj, and each ID value will be identical.

public struct ID has copy, drop, store

Fields
bytes: address

pub id_to_address​

Get the inner bytes of id as an address.

public fun id_to_address(id: &iota::object::ID): address

Implementation

public fun id_to_address(id: &ID): address {     id.bytes }

pub id_to_bytes​

Get the raw bytes of a ID

public fun id_to_bytes(id: &iota::object::ID): vector<u8>

Implementation

public fun id_to_bytes(id: &ID): vector<u8> {     bcs::to_bytes(&id.bytes) }

struct UID​

Globally unique IDs that define an object's ID in storage. Any IOTA Object, that is a struct with the key ability, must have id: UID as its first field. These are globally unique in the sense that no two values of type UID are ever equal, in other words for any two values id1: UID and id2: UID, id1 != id2. This is a privileged type that can only be derived from a TxContext. UID doesn't have the drop ability, so deleting a UID requires a call to delete.

public struct UID has store

Fields

pub delete​

Delete the object and it's UID. This is the only way to eliminate a UID. This exists to inform IOTA of object deletions. When an object gets unpacked, the programmer will have to do something with its UID. The implementation of this function emits a deleted system event so IOTA knows to process the object deletion

public fun delete(id: iota::object::UID)

Implementation

public fun delete(id: UID) {     let UID { id: ID { bytes } } = id;     delete_impl(bytes) }

pub uid_as_inner​

Get the inner ID of uid

public fun uid_as_inner(uid: &iota::object::UID): &iota::object::ID

Implementation

public fun uid_as_inner(uid: &UID): &ID {     &uid.id }

pub uid_to_address​

Get the inner bytes of id as an address.

public fun uid_to_address(uid: &iota::object::UID): address

Implementation

public fun uid_to_address(uid: &UID): address {     uid.id.bytes }

pub uid_to_bytes​

Get the raw bytes of a UID

public fun uid_to_bytes(uid: &iota::object::UID): vector<u8>

Implementation

public fun uid_to_bytes(uid: &UID): vector<u8> {     bcs::to_bytes(&uid.id.bytes) }

pub uid_to_inner​

Get the raw bytes of a uid's inner ID

public fun uid_to_inner(uid: &iota::object::UID): iota::object::ID

Implementation

public fun uid_to_inner(uid: &UID): ID {     uid.id }

Constants​

const IOTA_SYSTEM_STATE_OBJECT_ID​

The hardcoded ID for the singleton IOTA System State Object.

const IOTA_SYSTEM_STATE_OBJECT_ID: address = 0x5;

const IOTA_CLOCK_OBJECT_ID​

The hardcoded ID for the singleton Clock Object.

const IOTA_CLOCK_OBJECT_ID: address = 0x6;

const IOTA_AUTHENTICATOR_STATE_ID​

The hardcoded ID for the singleton AuthenticatorState Object.

const IOTA_AUTHENTICATOR_STATE_ID: address = 0x7;

const IOTA_RANDOM_ID​

The hardcoded ID for the singleton Random Object.

const IOTA_RANDOM_ID: address = 0x8;

const IOTA_DENY_LIST_OBJECT_ID​

The hardcoded ID for the singleton DenyList.

const IOTA_DENY_LIST_OBJECT_ID: address = 0x403;

const IOTA_TRANSACTION_DENY_RULES_OBJECT_ID​

The hardcoded ID for the singleton TransactionDenyRules.

const IOTA_TRANSACTION_DENY_RULES_OBJECT_ID: address = 0xde9;

err ENotSystemAddress​

Sender is not @0x0 the system address.

const ENotSystemAddress: u64 = 0;