Module iota::dynamic_object_field
Similar to iota::dynamic_field
, this module allows for the access of dynamic fields. But
unlike, iota::dynamic_field
the values bound to these dynamic fields must be objects
themselves. This allows for the objects to still exist within in storage, which may be important
for external tools. The difference is otherwise not observable from within Move.
- Struct
Wrapper
- Function
add
- Function
borrow
- Function
borrow_mut
- Function
remove
- Function
exists_
- Function
exists_with_type
- Function
id
- Function
internal_add
- Function
internal_borrow
- Function
internal_borrow_mut
- Function
internal_remove
- Function
internal_exists_with_type
- Macro function
add_impl
- Macro function
borrow_impl
- Macro function
borrow_mut_impl
- Macro function
remove_impl
- Macro function
exists_with_type_impl
use iota::address;
use iota::dynamic_field;
use iota::hex;
use iota::object;
use iota::tx_context;
use std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::vector;
Struct Wrapper
public struct Wrapper<Name> has copy, drop, store
Fields
name: Name
Function add
Adds a dynamic object field to the object object: &mut UID
at field specified by name: Name
.
Aborts with EFieldAlreadyExists
if the object already has that field with that name.
public fun add<Name: copy, drop, store, Value: key, store>(object: &mut iota::object::UID, name: Name, value: Value)
Implementation
Function borrow
Immutably borrows the object
s dynamic object field with the name specified by name: Name
.
Aborts with EFieldDoesNotExist
if the object does not have a field with that name.
Aborts with EFieldTypeMismatch
if the field exists, but the value object does not have the
specified type.
public fun borrow<Name: copy, drop, store, Value: key, store>(object: &iota::object::UID, name: Name): &Value
Implementation
public fun borrow<Name: copy + drop + store, Value: key + store>(object: &UID, name: Name): &Value {
borrow_impl!(object, name)
}
Function borrow_mut
Mutably borrows the object
s dynamic object field with the name specified by name: Name
.
Aborts with EFieldDoesNotExist
if the object does not have a field with that name.
Aborts with EFieldTypeMismatch
if the field exists, but the value object does not have the
specified type.
public fun borrow_mut<Name: copy, drop, store, Value: key, store>(object: &mut iota::object::UID, name: Name): &mut Value
Implementation
public fun borrow_mut<Name: copy + drop + store, Value: key + store>(
object: &mut UID,
name: Name,
): &mut Value {
borrow_mut_impl!(object, name)
}
Function remove
Removes the object
s dynamic object field with the name specified by name: Name
and returns
the bound object.
Aborts with EFieldDoesNotExist
if the object does not have a field with that name.
Aborts with EFieldTypeMismatch
if the field exists, but the value object does not have the
specified type.
public fun remove<Name: copy, drop, store, Value: key, store>(object: &mut iota::object::UID, name: Name): Value
Implementation
public fun remove<Name: copy + drop + store, Value: key + store>(
object: &mut UID,
name: Name,
): Value {
remove_impl!(object, name)
}
Function exists_
Returns true if and only if the object
has a dynamic object field with the name specified by
name: Name
.
public fun exists_<Name: copy, drop, store>(object: &iota::object::UID, name: Name): bool
Implementation
Function exists_with_type
Returns true if and only if the object
has a dynamic field with the name specified by
name: Name
with an assigned value of type Value
.
public fun exists_with_type<Name: copy, drop, store, Value: key, store>(object: &iota::object::UID, name: Name): bool
Implementation
public fun exists_with_type<Name: copy + drop + store, Value: key + store>(
object: &UID,
name: Name,
): bool {
exists_with_type_impl!<_, Value>(object, name)
}
Function id
Returns the ID of the object associated with the dynamic object field Returns none otherwise
public fun id<Name: copy, drop, store>(object: &iota::object::UID, name: Name): std::option::Option<iota::object::ID>
Implementation
public fun id<Name: copy + drop + store>(object: &UID, name: Name): Option<ID> {
let key = Wrapper { name };
if (!field::exists_with_type<Wrapper<Name>, ID>(object, key)) return option::none();
let (_field, value_addr) = field::field_info<Wrapper<Name>>(object, key);
option::some(value_addr.to_id())
}
Function internal_add
public(package) fun internal_add<Name: copy, drop, store, Value: key>(object: &mut iota::object::UID, name: Name, value: Value)
Implementation
public(package) fun internal_add<Name: copy + drop + store, Value: key>(
// we use &mut UID in several spots for access control
object: &mut UID,
name: Name,
value: Value,
) {
add_impl!(object, name, value)
}
Function internal_borrow
public(package) fun internal_borrow<Name: copy, drop, store, Value: key>(object: &iota::object::UID, name: Name): &Value
Implementation
public(package) fun internal_borrow<Name: copy + drop + store, Value: key>(
object: &UID,
name: Name,
): &Value {
borrow_impl!(object, name)
}
Function internal_borrow_mut
public(package) fun internal_borrow_mut<Name: copy, drop, store, Value: key>(object: &mut iota::object::UID, name: Name): &mut Value
Implementation
public(package) fun internal_borrow_mut<Name: copy + drop + store, Value: key>(
object: &mut UID,
name: Name,
): &mut Value {
borrow_mut_impl!(object, name)
}
Function internal_remove
public(package) fun internal_remove<Name: copy, drop, store, Value: key>(object: &mut iota::object::UID, name: Name): Value
Implementation
public(package) fun internal_remove<Name: copy + drop + store, Value: key>(
object: &mut UID,
name: Name,
): Value {
remove_impl!(object, name)
}
Function internal_exists_with_type
public(package) fun internal_exists_with_type<Name: copy, drop, store, Value: key>(object: &iota::object::UID, name: Name): bool
Implementation
public(package) fun internal_exists_with_type<Name: copy + drop + store, Value: key>(
object: &UID,
name: Name,
): bool {
exists_with_type_impl!<_, Value>(object, name)
}
Macro function add_impl
macro fun add_impl<$Name: copy, drop, store, $Value: key>($object: &mut iota::object::UID, $name: $Name, $value: $Value)
Implementation
macro fun add_impl<$Name: copy + drop + store, $Value: key>(
// we use &mut UID in several spots for access control
$object: &mut UID,
$name: $Name,
$value: $Value,
) {
let object = $object;
let name = $name;
let value = $value;
let key = Wrapper { name };
let id = object::id(&value);
field::add(object, key, id);
let (field, _) = field::field_info<Wrapper<$Name>>(object, key);
add_child_object(field.to_address(), value);
}
Macro function borrow_impl
macro fun borrow_impl<$Name: copy, drop, store, $Value: key>($object: &iota::object::UID, $name: $Name): &$Value
Implementation
Macro function borrow_mut_impl
macro fun borrow_mut_impl<$Name: copy, drop, store, $Value: key>($object: &mut iota::object::UID, $name: $Name): &mut $Value
Implementation
macro fun borrow_mut_impl<$Name: copy + drop + store, $Value: key>(
$object: &mut UID,
$name: $Name,
): &mut $Value {
let object = $object;
let name = $name;
let key = Wrapper { name };
let (field, value_id) = field::field_info_mut<Wrapper<$Name>>(object, key);
borrow_child_object_mut<$Value>(field, value_id)
}
Macro function remove_impl
macro fun remove_impl<$Name: copy, drop, store, $Value: key>($object: &mut iota::object::UID, $name: $Name): $Value
Implementation
macro fun remove_impl<$Name: copy + drop + store, $Value: key>(
$object: &mut UID,
$name: $Name,
): $Value {
let object = $object;
let name = $name;
let key = Wrapper { name };
let (field, value_id) = field::field_info<Wrapper<$Name>>(object, key);
let value = remove_child_object<$Value>(field.to_address(), value_id);
field::remove<Wrapper<$Name>, ID>(object, key);
value
}
Macro function exists_with_type_impl
macro fun exists_with_type_impl<$Name: copy, drop, store, $Value: key>($object: &iota::object::UID, $name: $Name): bool
Implementation
macro fun exists_with_type_impl<$Name: copy + drop + store, $Value: key>(
$object: &UID,
$name: $Name,
): bool {
let object = $object;
let name = $name;
let key = Wrapper { name };
if (!field::exists_with_type<Wrapper<$Name>, ID>(object, key)) return false;
let (field, value_id) = field::field_info<Wrapper<$Name>>(object, key);
field::has_child_object_with_ty<$Value>(field.to_address(), value_id)
}