State Utils
The StateUtility
class in the SDK provides utility functions for working with hook states in the XRPL. It includes functions to retrieve hook states, hook definitions, and hook state directories.
Retrieving Hook State
The getHookState
function is used to retrieve the state of a hook in the XRPL. It takes in the following parameters:
client
: The XRPL client object.account
: The account that owns the hook.key
: The key of the hook state.namespace
: The namespace of the hook state.
Here is an example of retrieving the state of a hook:
import {
serverUrl,
setupClient,
StateUtility,
hexNamespace,
} from '@transia/hooks-toolkit'
const testContext = (await setupClient(
serverUrl
)) as XrplIntegrationTestContext
const hookState = await StateUtility.getHookState(
testContext.client,
'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
'state_key',
hexNamespace('hook_namespace')
)
console.log(hookState)
In the example above, we create a new XRPL client object and pass it to the getHookState
function along with the account, key, and namespace of the hook state we want to retrieve. The function returns the hook state object.
Retrieving Hook Definition
The getHookDefinition
function is used to retrieve the definition of a hook in the XRPL. It takes in the following parameters:
client
: The XRPL client object.hash
: The hash of the hook definition.
Here is an example of retrieving the definition of a hook:
import {
serverUrl,
setupClient,
StateUtility
} from '@transia/hooks-toolkit'
const testContext = (await setupClient(
serverUrl
)) as XrplIntegrationTestContext
const hookDefinition = await StateUtility.getHookDefinition(
testContext.client,
'hook_definition_hash'
)
console.log(hookDefinition)
In the example above, we create a new XRPL client object and pass it to the getHookDefinition
function along with the hash of the hook definition we want to retrieve. The function returns the hook definition object.
Retrieving Hook State Directory
The getHookStateDir
function is used to retrieve the directory of hook states for a specific account and namespace in the XRPL. It takes in the following parameters:
client
: The XRPL client object.account
: The account that owns the hook states.namespace
: The namespace of the hook states.
Here is an example of retrieving the directory of hook states:
import {
serverUrl,
setupClient,
StateUtility,
hexNamespace
} from '@transia/hooks-toolkit'
const testContext = (await setupClient(
serverUrl
)) as XrplIntegrationTestContext
const hookStateDir = await StateUtility.getHookStateDir(
testContext.client,
'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59',
hexNamespace('hook_namespace')
)
console.log(hookStateDir)
In the example above, we create a new XRPL client object and pass it to the getHookStateDir
function along with the account and namespace of the hook states we want to retrieve. The function returns the directory of hook states.
For more information on the structure of hook states and hook definitions, refer to the XRPL documentation.