Manipulate raw serialized xahaud objects!
The XRP Ledger has canonical serialized forms of all objects subject to consensus. When writing a Hook it is inevitable you will come across serialized objects. These manifest as buffers containing what might appear to the developer as opaque binary blobs. In fact you can read these with the XRPL-Binary-Visualiser.
For example an sfAmount
field serializes to a collection of bytes like 61D50F26109A32B7EC
To assist Hook developers in working with serialized objects the sto
namespace was created within the Hooks API. These functions manipulate pointers within a Hook-provided buffer. See table below.
Index into a xrpld serialized object and return the location and length of a subfield
Index into a xrpld serialized array and return the location and length of an index
Emplace a field into an existing STObject at its canonical placement
Remove a field from an STObject
Validate an STObject
Where applicable these APIs return an offset and a length encoded into a single int64_t. See individual documentation for details.
At typical scenario in which you would use the STO API is in processing memos on an Originating Transaction. Since you will likely need access to the whole memo anyway, an efficient way to process a set of memos is simply to dump the whole sfMemos
field into a buffer then index around within it. While it is also possible to use the slot API to do this by slotting the Originating Transaction it would result in additional code and additional copying.
You may notice some overlap between slot APIs and STO APIs. The key difference here is who owns the underlying data:
If you are using slots then xrpld owns the object you are interacting with.
If you are using the STO API then the Hook owns the buffer you are interacting with.
Both sets of functions index into a Serialized Object without unnecessary copying.