XRPL-Labs / xrpld-hooks

ISC License
94 stars 28 forks source link

Support 'account_objects' request with HookState filter. #31

Closed ravinsp closed 1 year ago

ravinsp commented 2 years ago

Summary

Rippled only supports the types check, escrow, offer, payment_channel, signer_list and state for filtering out account objects by type. We need to introduce a filter type for "HookState" objects to avoid having to featch-all and client side filteration.

  const req= {
      command: "account_objects",
      account: "<address>",
      ledger_index: "validated",
      type: "hook_state"
  }
  const response = await api.connection.request(req);

The above throws:

  data: {
    error: 'invalidParams',
    error_code: 31,
    error_message: "Invalid field 'type'.",
    id: 1,
    request: {
      account: 'rpTA2MtFV7L6hLzjSBYc1FBgYqTs6APVdz',
      command: 'account_objects',
      id: 1,
      ledger_index: 'validated',
      type: 'hookstate'
    },
    status: 'error',
    type: 'response'
  }

Workaround

We can omit the 'type' filter in the request to get all account objects and apply the filter at client side.

Motivation

If a client application needs to get just the Hook State objects it has to multiple requests to fetch all results pages containing lot of objects of all types and then perform the Hook State filter at client side. This is bad for client performance and user experience.

Solution

Rippled can support 'hook_state' type filter so it only returns HookState objects.

RichardAH commented 1 year ago

This is no longer relevant because now the hook state objects live inside hook namespaces and are fetched only with account_namespace api.