Module 0x2::object
Iota object identifiers
- Struct
ID
- Struct
UID
- Constants
- Function
id_to_bytes
- Function
id_to_address
- Function
id_from_bytes
- Function
id_from_address
- Function
iota_system_state
- Function
clock
- Function
authenticator_state
- Function
randomness_state
- Function
iota_deny_list_object_id
- 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 0x1::bcs;
use 0x2::address;
use 0x2::tx_context;
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.
struct ID has copy, drop, store
Fields
bytes: address
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
.
struct UID has store
Fields
id: object::ID
Constants
Sender is not @0x0 the system address.
const ENotSystemAddress: u64 = 0;
The hardcoded ID for the singleton AuthenticatorState Object.
const IOTA_AUTHENTICATOR_STATE_ID: address = 7;
The hardcoded ID for the Bridge Object.
const IOTA_BRIDGE_ID: address = 9;
The hardcoded ID for the singleton Clock Object.
const IOTA_CLOCK_OBJECT_ID: address = 6;
The hardcoded ID for the singleton DenyList.
const IOTA_DENY_LIST_OBJECT_ID: address = 403;
The hardcoded ID for the singleton Random Object.
const IOTA_RANDOM_ID: address = 8;
The hardcoded ID for the singleton Iota System State Object.
const IOTA_SYSTEM_STATE_OBJECT_ID: address = 5;
Function id_to_bytes
Get the raw bytes of a ID
public fun id_to_bytes(id: &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 id
as an address.
public fun id_to_address(id: &object::ID): address
Implementation
public fun id_to_address(id: &ID): address {
id.bytes
}
Function id_from_bytes
Make an ID
from raw bytes.
public fun id_from_bytes(bytes: vector<u8>): object::ID
Implementation
public fun id_from_bytes(bytes: vector<u8>): ID {
address::from_bytes(bytes).to_id()
}
Function id_from_address
Make an ID
from an address.
public fun id_from_address(bytes: address): object::ID
Implementation
public fun id_from_address(bytes: address): ID {
ID { bytes }
}
Function 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: &tx_context::TxContext): object::UID
Implementation
fun iota_system_state(ctx: &TxContext): UID {
assert!(ctx.sender() == @0x0, ENotSystemAddress);
UID {
id: ID { bytes: IOTA_SYSTEM_STATE_OBJECT_ID },
}
}
Function clock
Create the UID
for the singleton Clock
object.
This should only be called once from clock
.
public(friend) fun clock(): object::UID
Implementation
public(package) fun clock(): UID {
UID {
id: ID { bytes: IOTA_CLOCK_OBJECT_ID }
}
}
Function authenticator_state
Create the UID
for the singleton AuthenticatorState
object.
This should only be called once from authenticator_state
.
public(friend) fun authenticator_state(): object::UID
Implementation
public(package) fun authenticator_state(): UID {
UID {
id: ID { bytes: IOTA_AUTHENTICATOR_STATE_ID }
}
}
Function randomness_state
Create the UID
for the singleton Random
object.
This should only be called once from random
.
public(friend) fun randomness_state(): object::UID
Implementation
public(package) fun randomness_state(): UID {
UID {
id: ID { bytes: IOTA_RANDOM_ID }
}
}