state
Behaviour
Section titled “Behaviour”- 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
- Retrieves the Hook State value associated with the specified key.
- Returns an error code or the Hook State value for the key.
Definition
Section titled “Definition”int64_t state ( uint32_t write_ptr, uint32_t write_len, uint32_t kread_ptr, uint32_t kread_len);function state(key: ByteArray | HexString): ErrorCode | ByteArrayExample
Section titled “Example”#define SBUF(str) (uint32_t)(str), sizeof(str)if (state(SBUF(vault), SBUF(vault_key)) != 16) rollback(SBUF("Error: could not read state!"), 1);const value = state(SBUF(vault), SBUF(vault_key))if (typeof value === 'number' || value.length != 16) rollback("Error: could not read state!", 1);Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| write_ptr | uint32_t | A pointer to the buffer to write the data in the Hook State into. |
| write_len | uint32_t | The length of the write buffer. |
| kread_ptr | uint32_t | Pointer to a buffer containing the Hook State key. |
| kread_len | uint32_t | The length of the Hook State key. (Should be 32.) |
| Name | Type | Description |
|---|---|---|
| key | ByteArray or HexString | The key of the Hook State to retrieve the value from. |
Return Code
Section titled “Return Code”| Type | Description |
|---|---|
| int64_t | The number of bytes written to the write buffer. |
| Type | Description |
|---|---|
| ByteArray or ErrorCode | Returns an error code or the Hook State value for the key. |