Slots and Keylets
Inspect and manipulate on-ledger objects.
Background
Xahau contains numerous heterogenous object types which a Hook has read-access to. For example: transactions, accounts, ledgers, and the subcomponents of each of these, to name just a few.
It is very easy to carelessly program a computer to do a lot of needless copy operations when disciplined access to the same underlying data (i.e. through a view) would suffice. The deliberate avoidance of copy operations in programming is referred to as Zero copy in programming.
With Hooks the same principle applies. We want to avoid copying where possible. In particular we want to avoid as much as possible needlessly copying large objects such as whole ledgers, we also want to avoid serializaing and unserializing these where possible.
What are slots?
Slots are part of the Hook API and provide a zero-copy heterogenous access system for on-ledger objects and transactions.
Each Hook has access to 255 slots during runtime.
Each slot may be empty or may contain a slotted object.
The slot API allows traversal into inner objects, and allows these inner objects themselves to be slotted.
The slot API allows slotted objects to be dumped to a buffer or otherwise read by the Hook.
The avilable slot APIs are:
Serialize and output a slotted object
Free up a currently occupied slot
Count the elements of an array object in a slot
slot_id
Compute the canonical hash of the slotted object and return it
Locate an object based on its keylet and place it into a slot
Index into a slotted array and assign a sub-object to another slot
Index into a slotted object and assign a sub-object to another slot
Retrieve the field code of an object in a slot and, optionally, some other information
Parse the STI_AMOUNT in the specified slot and return it as an XFL enclosed number
Compute the serialized size of an object in a slot
What are keylets?
Keylets are used to locate (point to) on-ledger objects. In brief they are a hash of identifying information from the object, which is the canonical handle for that object.
Hooks use a serialized 34 byte keylet format which can be derrived using the important util_keylet function. Without this looking up and slotting objects would be generally impossible.
🚧 Tip
The Hook APIs which accept a 34 byte keylet will also generally accept a 32 byte canonical transaction hash.
Example
In the following example a 34 byte keylet for a signers
object is used to slot that object.
Last updated