Xahau Network
Testnet FaucetExplorerHooks API Docs
Xahau Network
Xahau Network
  • 🪝Xahau Documentation
    • XRPL/Xahau: What is Different?
  • 🪝Hooks
  • 🚨Concepts
    • Introduction
      • Example Usage
      • Xahau Testnet
      • Xahau Testnet Explorer
      • Examples (source code)
      • Blogs (concepts)
    • Terminology
    • Loops and Guarding
    • Compiling Hooks
    • Chaining
    • Weak and Strong
    • Collect Call
    • SetHook Transaction
    • Parameters
    • Namespaces
    • Grants
    • HookOn Field
    • Reference Counted Hook Definitions
    • Hook Fees
    • Execution Metadata
    • Debugging Hooks
    • State Management
    • Slots and Keylets
    • Floating Point Numbers (XFL)
    • Emitted Transactions
    • Serialized Objects
  • Features
    • Public Nodes (RPC)
    • Amendments
    • Transaction Signing
      • Transaction Fees
    • Developer Tooling
      • Curated Tooling
      • Client Libraries
      • Developer Tricks
    • HTTP / WebSocket APIs
      • Request Formatting Guide
      • Response Formatting Guide
      • Considerations
      • Public API Methods
      • Admin API Methods
    • Network Features
      • Account Managment
      • Balance Rewards
      • Check
      • Escrow
      • Hooks
      • Offer
      • Payments
      • URIToken
    • Faucet & Explorers
    • Data API's
  • Infrastructure
    • Node Requirements
    • Running a Node
      • Running a Mainnet Node
      • Running a Testnet Node
    • Building Xahau (Dev)
      • Ubuntu - 22.04
      • Mac OS - 15.3.2 (24D81)
  • Technical
    • 📐Hooks Functions
      • Overview
        • Hook API Conventions
        • Return Codes
      • Developer Defined
        • hook
        • cbak / Callback
      • Control
        • accept
        • rollback
      • Utilities
        • util_raddr
        • util_accid
        • util_verify
        • util_sha512h
        • util_keylet
      • Serialization
        • sto_subfield
        • sto_to_json
        • sto_from_json
        • sto_subarray
        • sto_emplace
        • sto_erase
        • sto_validate
      • Emitted Transaction
        • etxn_burden
        • etxn_details
        • etxn_fee_base
        • etxn_nonce
        • etxn_reserve
        • etxn_generation
        • prepare
        • emit
      • Float
        • float_set
        • float_multiply
        • float_mulratio
        • float_negate
        • float_compare
        • float_sum
        • float_sto
        • float_sto_set
        • float_invert
        • float_divide
        • float_one
        • float_exponent
        • float_mantissa
        • float_sign
        • float_int
        • float_root
        • float_log
      • Ledger
        • fee_base
        • ledger_seq
        • ledger_last_hash
        • ledger_last_time
        • ledger_nonce
        • ledger_keylet
      • Hook Context
        • hook_account
        • hook_hash
        • hook_param
        • hook_param_set
        • hook_skip
        • hook_pos
        • hook_again
      • Slot
        • slot
        • slot_clear
        • slot_count
        • slot_set
        • slot_size
        • slot_subarray
        • slot_subfield
        • slot_type
        • xpop_slot
        • slot_float
      • State
        • state
        • state_set
        • state_foreign
        • state_foreign_set
      • Trace (Debug)
        • trace
        • trace_num
        • trace_float
      • Originating Transaction
        • otxn_burden
        • otxn_field
        • otxn_generation
        • otxn_id
        • otxn_type
        • otxn_slot
        • otxn_param
        • otxn_json
        • meta_slot
      • Websocket APIs
        • account_info
        • account_namespace
    • Protocol Reference
      • Transactions
        • Transaction Common Fields
        • Transaction Types
          • AccountDelete
          • AccountSet
          • CheckCancel
          • CheckCash
          • CheckCreate
          • ClaimReward
          • DepositPreauth
          • EscrowCancel
          • EscrowCreate
          • EscrowFinish
          • GenesisMint - (Emitted Txn)
          • Import
          • Invoke
          • OfferCancel
          • OfferCreate
          • Payment
          • PaymentChannelClaim
          • PaymentChannelCreate
          • PaymentChannelFund
          • Remit
          • SetHook
          • SetRegularKey
          • SignerListSet
          • TicketCreate
          • TrustSet
          • URITokenBurn
          • URITokenBuy
          • URITokenCancelSellOffer
          • URITokenCreateSellOffer
          • URITokenMint
        • Pseudo Transaction Types
          • EmitFailure
          • UNLReport
          • UNLModify
          • SetFee
          • EnableAmendment
        • Transaction Results
          • TES Codes
          • TER Codes
          • TEM Codes
          • TEL Codes
          • TEF Codes
          • TEC Codes
        • Transaction Metadata
      • Ledger Data
        • Ledger Objects Types
          • AccountRoot
          • Amendments
          • Check
          • Deposit Pre Auth
          • Directory Node
          • Emitted Txn
          • Escrow
          • Fee Settings
          • Hook
          • Hook Definition
          • Hook State
          • Import VL Sequence
          • Ledger Hashes
          • Negative UNL
          • Offer
          • Pay Channel
          • Ripple State
          • Signers List
          • Ticket
          • UNL Report
          • URIToken
        • Ledger Header
        • Ledger Object IDs
      • Data Types
        • Currency Formats
        • Base 58 Encodings
      • Binary Format
    • Balance Adjustments
    • Governance Game
    • Burn 2 Mint (B2M)
    • Versioning Process
  • Compliance
    • Security Audits
      • Responsible Disclosure
  • Support
    • Help Us
Powered by GitBook
On this page
  • Concepts
  • Behaviour
  • Definition
  • Example
  • Parameters
  • Keylet Table
  • Return Code

Was this helpful?

Edit on GitHub
Export as PDF
  1. Technical
  2. Hooks Functions
  3. Utilities

util_keylet

Compute a serialized keylet of a given type

Last updated 2 months ago

Was this helpful?

Concepts

📘Tip

Not every Keylet type is supported by this utility function. If you need another Keylet type you can derive it yourself using and by checking the required fields . A further Keylet tool may

Behaviour

  • Compute a keylet of the specified keylet_type according to the parameters a through f depending on type.

  • Write the serialized 34 byte keylet into write_ptr

Definition

int64_t util_keylet (
    uint32_t write_ptr,
    uint32_t write_len,
    uint32_t keylet_type,
    uint32_t a,
    uint32_t b,
    uint32_t c,
    uint32_t d,
    uint32_t e,
    uint32_t f
);

function util_keylet(
    keylet_type: number,
    accountid: ByteArray | HexString,
    statekey: ByteArray | HexString,
    namespace: ByteArray | HexString
  ): ErrorCode | ByteArray

Example

uint8_t keylet[34];
if (util_keylet(keylet, 34, KEYLET_LINE,
              hook_accid, 20,
              account_field, 20,
              currency_code, 20) != 34)
	rollback("Keylet Failed.", 14, 1);

if (util_keylet(
        KEYLET_LINE, hook_accid, account_field, currency_code
        ).length < 34) 
    rollback("Keylet Failed.", 1)

Parameters

Name
Type
Description

write_ptr

uint32_t

Pointer to a buffer the serialized keylet will be written to

write_len

uint32_t

Length of output buffer, should be at least 34.

keylet_type

uint32_t

One of the keylet types as defined in hookapi.h e.g. KEYLET_LINE for a trustline.

a

uint32_t

See keylet table below

b

uint32_t

See keylet table below

c

uint32_t

See keylet table below

d

uint32_t

See keylet table below

e

uint32_t

See keylet table below

f

uint32_t

See keylet table below

Name
Type
Description

keylet_type

The type of the keylet to create

accountid

(Optional) First piece of data for the keylet, can be an array of numbers, a string, or a number.

statekey

(Optional) Second piece of data for the keylet, can be an array of numbers, a string, or a number.

namespace

(Optional) Third piece of data for the keylet, can be an array of numbers, a string, or a number.

Keylet Table

Keylet Type
Parameters

KEYLET_HOOK_STATE

a points to an Account ID b is the length of the Account ID (should be 20) c points to a hook state key d is the length of the key (should be 32) e points to a hook state namespace f is the length of the namespace (should be 32)

KEYLET_AMENDMENTS KEYLET_FEES KEYLET_NEGATIVE_UNL KEYLET_EMITTED_DIR

a, b, c, d, e, f must all be zero

KEYLET_SKIP

Either: a, b, c, d, e, f all zero Or: a is a LedgerIndex b is 1 c, d, e, f must all ​be zero

KEYLET_LINE

a points to the High Account ID b is the length of the above (should be 20) c points to the Low Account ID d is the length of the above (should be 20) e points to the Currency Code f is the length of the above (should be 20)

KEYLET_QUALITY

a points to a serialized keylet b is the length of the above (should be 34) c is the high 32 bits of the uint64 to pass d is the low 32 bits of the uint64 to pass e, f must all be zero

KEYLET_DEPOSIT_PREAUTH

a points to an Account ID b is the length (should be 20) c points to an Account ID d is the length (should be 20) e, f must all be zero

KEYLET_UNCHECKED KEYLET_CHILD KEYLET_EMITTED_TXN

a points to a key. b is the length of the key (should be 32.) c, d, e, f must both ​be zero

KEYLET_OWNER_DIR KEYLET_SIGNERS KEYLET_ACCOUNT KEYLET_HOOK

a points to an Account ID. b is the length (should be 20.) c, d, e, f must all be zero.

KEYLET_PAGE

a points to a key. b is the length of the key (should be 32.) c is the high 32 bits of the uint64 to pass d is the low 32 bits of the uint64 to pass e, f must both ​be zero

KEYLET_OFFER KEYLET_CHECK KEYLET_ESCROW KEYLET_NFT_OFFER

a points to an Account ID. b is the length (should be 20.) And Either: c is a 32bit unsigned integer (sequence) d is 0 Or: c points to a 32 byte key d is the length of the key (32). In both cases: e and f must be 0.

KEYLET_PAYCHAN

a points to an Account ID b is the length (should be 20) c points to an Account ID d is the length (should be 20) And Either: e 32bit unsigned int to pass f is zero Or: e points to a 32 byte key f is the length of the key (32)

Return Code

Type
Description

int64_t

The number of bytes written, should always be 34. If negative, an error: OUT_OF_BOUNDS - pointers/lengths specified outside of hook memory. INVALID_ARGUMENT - Call didn't comply with the above table. TOO_SMALL - Writing buffer was smaller than 34 bytes.

Type
Description

number

ErrorCode if there is an error in creating the keylet, otherwise returns the generated keylet as an array of numbers.

📐
Slots and Keylets
util_sha512h
here
assist you.