Skip to content

state

  • Read a 32 byte Hook State key from the kread_ptr
  • Write the data (value) at that key to the buffer pointed to by write_ptr
int64_t state (
uint32_t write_ptr,
uint32_t write_len,
uint32_t kread_ptr,
uint32_t kread_len
);
#define SBUF(str) (uint32_t)(str), sizeof(str)
if (state(SBUF(vault), SBUF(vault_key)) != 16)
rollback(SBUF("Error: could not read state!"), 1);
NameTypeDescription
write_ptruint32_tA pointer to the buffer to write the data in the Hook State into.
write_lenuint32_tThe length of the write buffer.
kread_ptruint32_tPointer to a buffer containing the Hook State key.
kread_lenuint32_tThe length of the Hook State key. (Should be 32.)
TypeDescription
int64_t

The number of bytes written to the write buffer.

If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.

DOESNT_EXIST
- the specified Hook State key doesn’t have an associated value on the ledger at the time of the call.

TOO_BIG
- the key specified by read_ptr and read_len was larger than 32 bytes.

TOO_SMALL
- the output buffer was too small to store the Hook State data.