These docs are for v2.0. Click to read the latest docs for v3.0.

Compute a serialized keylet of a given type

Concepts

📘

Tip

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

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
);

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);

Parameters

NameTypeDescription
write_ptruint32_tPointer to a buffer the serialized keylet will be written to
write_lenuint32_tLength of output buffer, should be at least 34.
keylet_typeuint32_tOne of the keylet types as defined in hookapi.h e.g. KEYLET_LINE for a trustline.
auint32_tSee keylet table below
buint32_tSee keylet table below
cuint32_tSee keylet table below
duint32_tSee keylet table below
euint32_tSee keylet table below
fuint32_tSee keylet table below

Keylet Table

Keylet TypeParameters
KEYLET_HOOK_STATEa 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_SKIPEither:
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_LINEa 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_QUALITYa 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_PREAUTHa 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_PAGEa 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_PAYCHANa 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

TypeDescription
int64_tThe 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.