state_set
Behaviour
Section titled “Behaviour”- Read a 32 byte Hook State key from the
kread_ptr - Read an arbitrary amount of data from
read_ptr(the value) - Update the Hook State key with the value
- Sets the Hook State with the specified value and key.
- Returns the number of bytes written to Hook State (the length of the data), negative on error.
Definition
Section titled “Definition”int64_t state_set ( uint32_t read_ptr, uint32_t read_len, uint32_t kread_ptr, uint32_t kread_len);function state_set( value: ByteArray | HexString | undefined | null, key: ByteArray | HexString ): ErrorCode | numberExample
Section titled “Example”#define SBUF(str) (uint32_t)(str), sizeof(str)if (state_set(SBUF(vault), SBUF(vault_key)) < 0) rollback(SBUF("Error: could not set state!"), 1);const result = state_set(vault, vault_key)if (result < 0) rollback("Error: could not set state!", 1);Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| read_ptr | uint32_t | Pointer to the data (value) to write into Hook State. |
| read_len | uint32_t | The length of the data. |
| kread_ptr | uint32_t | A pointer to the Hook State key at which to store the value. |
| kread_len | uint32_t | The length of the key. (Should always be 32.) |
| Name | Type | Description |
|---|---|---|
| value | ByteArray or HexString | The value of data to persist. |
| key | ByteArray or HexString | The key of the Hook State to set the value for. |
Return Code
Section titled “Return Code”| Type | Description |
|---|---|
| int64_t | The number of bytes written to Hook State (the length of the data.) |
| Type | Description |
|---|---|
| number or ErrorCode | Returns the number of bytes written to Hook State (the length of the data), negative on error. |