Skip to content

slot_subfield ​

Summary. Extract a named subfield of a slotted object into a (new or specified) slot.

Signature.

c
int64_t slot_subfield(uint32_t parent_slot, uint32_t field_id, uint32_t new_slot);

Parameters.

NameTypeDescription
parent_slotuint32_tSlot holding the parent object.
field_iduint32_tSerialized field code of the subfield (e.g. sfAmount).
new_slotuint32_tDestination slot, or 0 to allocate a free slot.

Return value. Returns the destination slot number on success. Errors: DOESNT_EXIST (-5) if the parent slot is empty or the field is not present; INVALID_FIELD (-17) if field_id is sfInvalid; INVALID_ARGUMENT (-7) if new_slot exceeds max_slots; NO_FREE_SLOTS (-6) if new_slot == 0 and none are free; INTERNAL_ERROR (-2) if the parent entry is corrupt; NOT_AN_OBJECT (-23) if the parent is not an object.

Common failure patterns.

  • Requesting a field the object does not carry → DOESNT_EXIST.
  • Passing a field code of 0 / sfInvalid → INVALID_FIELD.
  • Drilling into a leaf (non-object) slot → NOT_AN_OBJECT.

Caveats / notes.

  • Field codes are (type << 16) | index; the same codes used by otxn_field and defined in hook/sfcodes.h.
  • If new_slot equals parent_slot, the child replaces the parent in place; otherwise the parent slot is left intact.
  • When new_slot == 0, the free-slot check runs right after the parent-slot lookup: a missing parent slot still returns DOESNT_EXIST, but with a full slot pool an invalid field_id or a field absent from the parent returns NO_FREE_SLOTS rather than INVALID_FIELD / DOESNT_EXIST.

Minimal example.

c
uint32_t amt = slot_subfield(txn_slot, sfAmount, 0);

Practical example.

c
// Load the originating transaction, then drill to its Amount field.
int64_t txn_slot = otxn_slot(0);
ASSERT(txn_slot > 0);

int64_t amt = slot_subfield(txn_slot, sfAmount, 0);
ASSERT(amt > 0);
ASSERT(slot_size(amt) > 0);

Related APIs. slot_subarray, slot, slot_float.