Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
The callback function of your hook
cbak
is a user defined function called by xahaud
in order to inform your hook about the status of a previously emitted transaction
State changes and further emit calls can be made from cbak but it cannot rollback
a transaction.
When cbak is executed the emitted transaction to which the callback relates is now the originating transaction.
C
C
what
uint32_t
if 0
:
- the emittted transaction to which this callback relates was successfully accepted into a ledger.
If 1
- the emitted transaction to which the callback relates was NOT successfully accepted into a ledger before it expired.
int64_t
An arbitrary return code you wish to return from your hook. This will be present in the metadata of the originating transaction.
The main function of your hook
hook
is a user defined function called by xahaud
in order to fire your hook.
Your hook
function calls either accept
or reject
to pass or reject the originating transaction.
If execution reaches the end of the function it is implicitly an accept
.
C
C
reserved
uint32_t
Reserved for future use.
int64_t
An arbitrary return code you wish to return from your hook. This will be present in the metadata of the originating transaction.
Execution Order
End the execution of the hook with status: reject.
Record a return string and return code in transaction metadata.
Discard all state changes.
Discard all emit()
transactions.
Disallow originating transaction to continue.
βοΈWarningThe originating transaction will fail with
tecHOOK_REJECTED
and a fee will be charged. See: Execution Order.
C
C
read_ptr
uint32_t
Pointer to a return string to be stored in execution metadata. This is any string the hook-developer wishes to return with the acceptance. May be null.
read_len
uint32_t
The length of the return string. At most 32. May be null.
error_code
uint64_t
A return code specific to this hook to be stored in execution metadata. Similar to the return code of an application on a *nix system. By convention non-success is non-zero.
int64_t
Rollback ends the hook, therefore no value is returned to the caller. By convention all Hook APIs return int64_t
, but in this case nothing is returned.
Convert an r-address into a 20 byte Account ID
Read an r-address from the read_ptr
Write a 20 byte Account ID to the write_ptr
C
C
write_ptr
uint32_t
Pointer to a buffer of a suitable size to store the output Account ID. Must be at least 20 bytes.
write_len
uint32_t
Length of the output buffer.
read_ptr
uint32_t
Pointer to the r-address.
read_len
uint32_t
The length of the r-address.
int64_t
The number of bytes written (the length of the output r-address).
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
INVALID_ARGUMENT
- read_ptr
pointed at something which wasn't a valid r-address.
TOO_SMALL
- write_len
was not large enough to store produced Account ID. (Should be 20 bytes).
TOO_BIG
- read_len
was longer than an r-address can be.
All Hook APIs follow a standard naming convention:
namespace
[ _ noun #1 ]
[ _ verb ]
[ _ noun #2 ]
This may look confusing at first but is actually quite simple:
If the first noun is missing then it is implicitly the same as the namespace
If the verb is missing then it is implicitly get
Thus:
state()
means: fetch a hook state.
state_set()
means: set a hook.
state_foreign()
means: fetch a foreign hook state.
Each Hook executes as a singular stack frame. All working memory must exist within this stackframe. There is no heap and no dynamic memory.
When Hooks communicate with xahaud
they can only pass integer values. Typically these integers are pointers within the Hook's memory. Since the Hook runs within xahaud, these points can then be resolved by xahaud and written to or read from as needed to perform the Hook API function.
Only two functions are allowed within a Hook: hook()
and cbak()
. Read about this here
All parameters passed to a Hook API must be one of: uint32_t, int32_t, uint64_t, int64_t
. Typically these are pointers and lengths of buffers within the Hook's stack frame. Sometimes they are Integer Encoded Floating Point Numbers (XFL) or other data.
The parameters to a Hook API are always in the following order:
Writing pointer if any
Writing length if any
Reading pointer if any
Reading length if any
Specifics / other fields if any
Some Hook APIs may only write or may only read from memory, and some might not do either and return a value only by return code.
All Hook APIs return a signed integer. Read about return codes here: Return codes
Compute an sha512-half over some data
Compute an SHA512
hash over the data pointed to by read_ptr
Write the first half of the hash to write_ptr
C
C
write_ptr
uint32_t
Pointer to a buffer the hash will be written to
write_len
uint32_t
Length of output buffer, should be at least 32.
read_ptr
uint32_t
Pointer to the buffer data will be read from (to compute the hash over)
read_len
uint32_t
Length of input data
int64_t
The number of bytes written, should always be 32.
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
TOO_SMALL
- Output buffer isn't large enough
Verify a cryptographic signature
Verify a cryptographic signature
If the public key is prefixed with 0xED
then use ED25519
Otherwise assume SECP256k1
C
C
dread_ptr
uint32_t
Pointer to the signed data
dread_len
uint32_t
Length of the signed data
sread_ptr
uint32_t
Pointer to the signature
sread_len
uint32_t
Length of the signature
kread_ptr
uint32_t
Pointer to the public key
kread_len
uint32_t
Length of the public key
int64_t
0
- validation failed, the signature is invalid.
1
- validation succeeded, the signature is valid.
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
Accept the originating transaction and commit any changes the hook made.
Execution Order
End the execution of the hook with status: success.
Record a return string and return code in transaction metadata.
Commit all state changes.
Submit all emit()
transactions.
Allow originating transaction to continue.
π§CautionIf the originating transaction is stopped for some other reason then this accept becomes a rollback. See: Execution Order.
C
C
read_ptr
uint32_t
Pointer to a return string to be stored in execution metadata. This is any string the hook-developer wishes to return with the acceptance. May be null.
read_len
uint32_t
The length of the return string. At most 32. May be null.
error_code
uint64_t
A return code specific to this hook to be stored in execution metadata. Similar to the return code of an application on a *nix system. By convention success is zero.
int64_t
Accept ends the hook, therefore no value is returned to the caller. By convention all Hook APIs return int64_t
, but in this case nothing is returned.
Emplace a field into an existing STObject at its canonical placement
Parse an STObject S
(source object) pointed to by sread_ptr
Parse an STObject F
(to inject/emplace) pointed to by fread_ptr
Write a new STObject to write_ptr
which places F
into S
at the canonical position field_id
π§Field ID encodingThe
sto_
apis accept afield_id
parameter encoded as follows:(type << 16U) + field
Thus type 1 field 2 would be0x10002U
.
C
C
write_ptr
uint32_t
The buffer to write the modified STObject to
write_len
uint32_t
The length of the output buffer
sread_ptr
uint32_t
The buffer to read the source STObject from
sread_len
uint32_t
The Length of the source object
fread_ptr
uint32_t
The buffer to read the field to be emplaced/injected from
fread_len
uint32_t
The length of the field to be emplaced/injected
field_id
uint32_t
The sf
code (location) to form the emplacement. If this already exists in the source object then the existing field is overriden. If it doesn't exist it is inserted.
int64_t
The number of bytes written to write_ptr
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
TOO_SMALL
- Output buffer must be at least as large as the source object + the injected field, even if the field is only being overriden.
TOO_BIG
- Field you are attempting to emplace is too large
PARSE_ERROR
- The supplied STObject is malformed or not an STObject.
Remove a field from an STObject
Parse an STObject pointed to by read_ptr
Write a new STObject to write_ptr
but without field_id
if it was present in the original object.
C
π§Field ID encodingThe
sto_
apis accept afield_id
parameter encoded as follows:(type << 16U) + field
Thus type 1 field 2 would be0x10002U
.
C
πEmplace equivalence
sto_erase
is the same assto_emplace
with0,0
forfield_ptr, field_len
parameters.
write_ptr
uint32_t
The buffer to write the modified STObject to
write_len
uint32_t
The length of the output buffer
read_ptr
uint32_t
The buffer to read the source STObject from
read_len
uint32_t
The Length of the source object
field_id
uint32_t
The sf
code (location) to erase
int64_t
The number of bytes written to write_ptr
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
TOO_SMALL
- Output buffer must be at least as large as the source object.
TOO_BIG
- Field you are attempting to erase from is too large
PARSE_ERROR
- The supplied STObject is malformed or not an STObject.
DOESNT_EXIST
- The specified field_id
isn't present in the STObject.
Web assembly allows for exceptions (traps) however this language feature is not used for Hooks. Instead there is only one way to return from any Hook API (you may think of every Hook API as being noexcept
).
To provide for efficient error handling:
All Hook API functions return a signed integer.
All negative return codes are an error.
All return codes 0
or greater are a function specific output, usually but not always the number of bytes read or written.
Error codes are global across all Hook APIs and may be found in the table below.
SUCCESS
>= 0
Non-negative return codes refer always to success and usually indicate the number of bytes written or events performed, depending on the specific API.
OUT_OF_BOUNDS
-1
A pointer or buffer length provided as a parameter described memory outside of the Hook's allowed memory region.
INTERNAL_ERROR
-2
Reserved for internal invariant trips, generally unrelated to inputs. These should be reported with an issue.
TOO_BIG
-3
Attempted to set a parameter or value larger than the allowed space.
TOO_SMALL
-4
The API was unable to produce output to the write_ptr because the specified write_len was too small.
DOESNT_EXIST
-5
The requested object or item wasn't found.
NO_FREE_SLOTS
-6
The Hook attempted to allocate an item into a slot, but there were no slots free. To avoid ensure re-use of existing slots. The maximum number of slots is 255.
INVALID_ARGUMENT
-7
One or more of the parameters to the API were invalid according to the individual API's specification.
ALREADY_SET
-8
Some APIs allow for a once-per-execution parameter to be set. A second attempt to set a once-per-execution parameter results in this error.
PREREQUISITE_NOT_MET
-9
An API required the Hook to do something before the API is allowed to be called. Check the API's documentation.
FEE_TOO_LARGE
-10
During fee calculation if an absurdly large fee is calculated this error is returned.
EMISSION_FAILURE
-11
An attempt to emit()
a TXN was unsccessful for any of a number of reasons. Check the trace
log of the rippled to which you are submitting the originating TXN.
TOO_MANY_NONCES
-12
A Hook may only use up to 256 calls to nonce()
per execution. Further calls result in this error code.
TOO_MANY_EMITTED_TXN
-13
A Hook must declare ahead of time how many TXN it intends to emit()
.
If it emits fewer than this many, this is allowed.
If it emits more than this many this error is returned.
NOT_IMPLEMENTED
-14
While Hooks is/was in development an API may return this if some or all of that API is planned but not yet implemented.
INVALID_ACCOUNT
-15
An API which accepts a 20 byte Account ID may return this if, in its opinion, the Account ID was not valid for any reason.
GUARD_VIOLATION
-16
All loops inside a Hook must declare at the top of the loop, as the first non trivial instruction, before any branch instruction, the promised maximum number of iterations of the loop. If this promise is violated the hook terminates immediately with this error code.
INVALID_FIELD
-17
The requested serialized field could not be found in the specified object.
PARSE_ERROR
-18
While parsing serialized content an error was encountered (typically indicating an invalidly serialized object).
RC_ROLLBACK
-19
Used internally to communicate a rollback event.
RC_ACCEPT
-20
Used internally to communicate an accept event.
NO_SUCH_KEYLET
-21
Specified keylet could not be found, or keylet is invalid
NOT_AN_ARRAY
-22
API was asked to assume object under analysis is an STArray but it was not.
NOT_AN_OBJECT
-23
API was asked to assume object under analysis is an STObject but it was not.
INVALID_FLOAT
-10024
A floating point operation resulted in Not-A-Number or API call attempted to specify an XFL floating point number outside of the expressible range of XFL.
DIVISION_BY_ZERO
-25
API call would result in a division by zero, so API ended early.
MANITSSA_OVERSIZED
-26
When attempting to create an XFL the mantissa must be 16 decimal digits.
MANTISSA_UNDERSIZED
-27
When attempting to create an XFL the mantissa must be 16 decimal digits.
EXPONENT_OVERSIZED
-28
When attempting to create an XFL the exponent must not exceed 80.
EXPONENT_UNDERSIZED
-29
When attempting to create an XFL the exponent must not be less than -96.
OVERFLOW
-30
A floating point operation done on an XFL resulted in a value larger than XFL format is able to represent.
NOT_IOU_AMOUNT
-31
An API assumed an STAmount was an IOU when in fact it was XRP.
NOT_AN_AMOUNT
-32
An API assumed an STObject was an STAmount when in fact it was not.
CANT_RETURN_NEGATIVE
-33
An API would have returned a negative integer except that negative integers are reserved for error codes (i.e. what you are reading.)
NOT_AUTHORIZED
-34
Hook attempted to set foreign state but was not authorized to do so (grant was missing or invalid.)
PREVIOUS_FAILURE_PREVENTS_RETRY
-35
Hook previously received a NOT_AUTHORIZED
return code and is not allowed to retry.
TOO_MANY_PARAMS
-36
Attempted to set a hook parameter for a later hook in the chain, but there are now too many parameters.
INVALID_TXN
-37
Serialized transaction was not a valid transaction (usually because of a missing required field or data corruption / truncation.)
RESERVE_INSUFFICIENT
-38
Setting an additional state object on this account would cause the reserve requirements to exceed the account's balance.
COMPLEX_NOT_SUPPORTED
-39
Hook API would be forced to return a complex number, which it cannot do.
DOES_NOT_MATCH
-40
Two arguments were required to be of the same type but are not.
INVALID_KEY
-41
The provided public key was not valid.
NOT_A_STRING
-42
The buffer did not contain a nul terminated string.
MEM_OVERLAP
-43
The writing pointer points to a buffer that overlaps with the reading pointer.
TOO_MANY_STATE_MODIFICATIONS
-44
More than 5000 modified state entries in the combined hook chains
TOO_MANY_NAMESPACES
-45
More than 256 namespaces on this account
Index into a xahaud serialized array and return the location and length of an index
Parse a STArray pointed to by read_ptr
Find the array index specified by array_id
Return the byte offset and length of the serialized field within the STObject, if it is found
π§Field ID encodingThe
sto_
apis accept afield_id
parameter encoded as follows:(type << 16U) + field
Thus type 1 field 2 would be0x10002U
.In the case of this array field ID is
array_id
.
C
C
πhookmacro.h already contains the
SUB_OFFSET
andSUB_LENGTH
macros.
read_ptr
uint32_t
Pointer to the buffer containing the STArray
read_len
uint32_t
Length of STArray
array_id
uint32_t
The index of the entry within the STArray you are seeking. Starts from 0.
int64_t
The location of the field within the specified buffer:
- The high 32 bits are the offset location.
- The low 32 bits are the length.
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
TOO_SMALL
- Input buffer isn't large enough to possibly contain a valid STArray.
DOESNT_EXIST
- The searched for index isn't present in the supplied STArray.
PARSE_ERROR
- The supplied STArray is malformed or not an STArray.
Compute a serialized keylet of a given type
πTipNot 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.
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
C
C
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
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)
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.
Produce an sfEmitDetails suitable for a soon-to-be emitted transaction
Generate and write a 105 byte sfEmitDetails object into the write_ptr
if cbak is not defined
Generate and write a 127 byte sfEmitDetails object into the write_ptr
if cbak is defined.
C
C
write_ptr
uint32_t
Pointer to the buffer receiving the sfEmitDetails record
write_len
uint32_t
Length of the buffer
int64_t
The number of bytes written.
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
TOO_SMALL
- Buffer isn't large enough to receive record
PREREQUISITE_NOT_MET
- The hook failed to call etxn_reserve(n)
first
FEE_TOO_LARGE
- The burden would be too high for the network to allow.
INTERNAL_ERROR
- A generic error in which rippled had trouble generating the required field.
Convert a 20 byte Account ID to an r-address
Read a 20 byte Account ID from the read_ptr
Write the equivalent r-address for that Account ID to write_ptr
C
C
write_ptr
uint32_t
Pointer to a buffer of a suitable size to store the output r-address. Recommend at least 35 bytes.
write_len
uint32_t
Length of the output buffer.
read_ptr
uint32_t
Pointer to the Account ID.
read_len
uint32_t
The length of the input. Always 20.
int64_t
The number of bytes written (the length of the output r-address).
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
INVALID_ARGUMENT
- read_len
was not 20.
TOO_SMALL
- write_len
was not large enough to store produced r-address in.
Estimate the required fee for a txn to be emitted successfully
Specifies a number of emitted transactions this hook might emit during execution.
C
C
count
uint32_t
The largest number of transactions this hook might emit during the course of one execution.
int64_t
The maximum number of emitted transactions this hook may emit. This will always be the same as the count
parameter or an error as below.
If negative, an error:
ALREADY_SET
- The hook already called this function earlier.
TOO_BIG
- The specified number of emitted transactions is too large.
Get the generation of a hypothetically emitted transaction
Return the generation an emitted transaction will carry.
C
C
None
int64_t
The generation an emitted transaction will need in order to be successfully passed to emit()
π§ WarningFees on a Hooks-enabled ledger are non trivial. See: Hook Fees for details.
Return the amount of the fee in drops recommended for a to-be emitted transaction.
C
C
read_ptr
uint32_t
Pointer to the buffer containing the serialized transaction you intend to emit. The fee field is required but ignored (you may use zero). Use the output of this function to populate the fee field correctly.
read_len
uint32_t
The length of the tx blob.
int64_t
The smallest number of drops that an emitted txn would need to be accepted.
If negative, an error:
OUT_OF_BOUNDS
- The provided buffer is not validly within the hook memory.
PREREQUISITE_NOT_MET
- etxn_reserve
has not been called first.
INVALID_TXN
- The provided buffer did not contain a valid serialized transaction. (Deserialization failed, or a required field was missing.)
Create a float from an exponent and mantissa
Compute an XFL (xls17) floating point from the provided exponent and mantissa
Return that XFL as an int64_t
C
C
exponent
int32_t
An exponent in the range -96
to 80
mantissa
int64_t
A mantissa. If negative then the sign of the float is negative.
π§CautionWhen setting a mantissa that is greater or fewer than 16 decimal digits the exponent will be adjusted to ensure the mantissa is exactly 16 digits. This adjustment may result in an
INVALID_FLOAT
in some circumstances.
πSpecial caseXFL canonical 0 is also 0 in the enclosing number. Thus there is never a need to call
float_set(0,0);
int64_t
The XFL (xls17) enclosing number
If negative, an error:
INVALID_FLOAT
- The adjustment of the mantissa to 16 digits produced an under or overflow.
Validate an STObject
Parse an STObject pointed to by read_ptr
Return 1 if the serialization is valid, 0 otherwise.
C
C
read_ptr
uint32_t
The buffer to read the source STObject from
read_len
uint32_t
The Length of the source object
int64_t
1
if the STObject pointed to by read_ptr
is a valid STObject.
0
if it isn't.
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
Negate an XFL floating point number
Multiply an XFL by -1
Return a new XFL as an int64_t
C
C
πSpecial caseThe negation of Canonical Zero is Canonical Zero. Unlike some floating point standards (such as IEEE) there is no "negative zero" in XFL.
float1
int64_t
An XFL floating point enclosing number
int64_t
The XFL (xls17) enclosing number
If negative, an error:
INVALID_FLOAT
- one of the supplied parameters was not a valid XFL enclosing number
Get the burden of a hypothetically emitted transaction
Return the burden an emitted transaction will carry.
C
C
None
int64_t
The burden an emitted transaction will need in order to be successfully passed to emit()
Multiply an XFL floating point by a non-XFL numerator and denominator
Compute the multiplication of an XFL (xls17) floating point number and the quotient of two integers
Return a new XFL as an int64_t
C
C
float1
int64_t
An XFL floating point enclosing number representing the first operand to the multiplication
round_up
uint32_t
If non-zero all computations will be rounded up
numerator
uint32_t
The numerator of the quotient that the float will be multiplied by
denominator
uint32_t
The denominator of the quotient that the float will be multiplied by
π§CautionCertain multiplications may overflow, which return with an
INVALID_FLOAT
error. However an underflow returns as XFL Canonical Zero (i.e. enclosing number = 0).
int64_t
The XFL (xls17) enclosing number
If negative, an error:
INVALID_FLOAT
- one of the supplied parameters was not a valid XFL enclosing number
OVERFLOW
- the result of the multiplication was too large to store in an XFL.
DIVISION_BY_ZERO
- the supplied denominator was zero.
Add two XFL numbers together
Compute the addition of two XFL (xls17) floating point numbers
Return a new XFL as an int64_t
C
C
float1
int64_t
An XFL floating point enclosing number representing the first operand to the addition
float2
int64_t
An XFL floating point enclosing number representing the second operand to the addition
πHintTo subtract two floats use
float_negate
on the second float then usefloat_sum
.
int64_t
The XFL (xls17) enclosing number
If negative, an error:
INVALID_FLOAT
- one of the supplied parameters was not a valid XFL enclosing number
OVERFLOW
- the result of the addition was too large to store in an XFL.
Output an XFL as a serialized object
Read an XFL floating point number and optionally a field code and currency code
Write a serialized amount to write_ptr
according to the parameters provided
C
C
write_ptr
uint32_t
Pointer to a buffer of a suitable size to store the serialized amount field. Recommend at least 48 bytes.
write_len
uint32_t
The length of the output buffer.
cread_ptr
uint32_t
Pointer to a buffer contianing the currency code to serialize into the output. May be null.
cread_len
uint32_t
The length of the currency code. This must be 20 or 3 or 0 (null).
iread_ptr
uint32_t
Pointer to a buffer containing the issuer's Account ID to serialize into the output. May be null.
iread_len
uint32_t
The length of the issuer's Account ID. This must be either 20 or 0 (null).
float1
int64_t
An XFL floating point enclosing number to serialize.
field_code
uint32_t
The sf
field code to prefix the serialized amount with. E.g. sfAmount
.
If this field is 0xFFFFFFFFU
(i.e. (uint32_t)(-1)
) then no field code is prepended to the output, and no issuer or currency code is appended, but serialization proceeds as a floating point amount.
If this field is 0 no field code is prepended to the output, and no issuer or currency code is appended, but serialization proceeds as though the amount is an XRP native amount rather than a floating point.
πHintTo output an
XAH
amount prepopulate the field code in the output buffer then pass the output buffer incremented to the new start and0
as field_code
int64_t
The number of bytes written to the output buffer.
If negative, an error:
INVALID_FLOAT
- the supplied float was not a valid XFL enclosing number
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
INVALID_ARGUMENT
- If instructed to output as XRP
or without field code
then all non-write pointers and lengths should be 0 (null).
TOO_SMALL
- The output buffer was too small to receive the serialized object.
XFL_OVERFLOW
- Expressing the output caused an overflow during normalization.
Index into a xahaud serialized object and return the location and length of a subfield
Parse a STObject pointed to by read_ptr
Find the field specified by field_id
If the field is found, and:
It is an array, then return the start and length of the array including the leadin/leadout bytes, or
It is not an array, then return the start and length of the PAYLOAD of the field (excluding the leadin bytes).
π§Field ID encodingThe
sto_
apis accept afield_id
parameter encoded as follows:(type << 16U) + field
Thus type 1 field 2 would be0x10002U
.
C
C
πhookmacro.h already contains the
SUB_OFFSET
andSUB_LENGTH
macros.
read_ptr
uint32_t
Pointer to the buffer containing the STObject
read_len
uint32_t
Length of STObject
field_id
uint32_t
The sf
code of the field you are searching for.
To compute this manually take the serialized type
and shift it into the 16 highest bits of uint32_t, then take the field
and place it in the 16 lowest bits.
For example:
sfEmitNonce
has type
5 and field
11 thus its value is 0x050BU
int64_t
The location of the field within the specified buffer:
- The high 32 bits are the offset location.
- The low 32 bits are the length.
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
TOO_SMALL
- Input buffer isn't large enough to possibly contain a valid STObject.
DOESNT_EXIST
- The searched for field isn't present in the supplied STObject.
PARSE_ERROR
- The supplied STObject is malformed or not an STObject.
Multiply two XFL numbers together
Compute the multiplication of two XFL (xls17) floating point numbers
Return a new XFL as an int64_t
C
C
π§CautionCertain multiplications may overflow, which return with an
INVALID_FLOAT
error. However an underflow returns as XFL Canonical Zero (i.e. enclosing number = 0).
Perform a comparison on two XFL floating point numbers
Evaluate a comparison of two XFL floating point numbers
Return the result of the comparison as a boolean encoded in an int64_t.
C
C
π§CautionAlways verify the function returned
1
rather thannon-zero
, as negative error codes will be classed asnon-zero
.
Get the exponent of an XFL enclosing number
π§ Replaced by macroThis function was replaced by a macro. Please use the macro below in your code instead. To check the validity of the XFL please use float_mantissa in conjunction with this macro.
Return the exponent part of an XFL as a signed integer
Because exponents can be negative, and because negatives are reserved for error states, exponents cannot be returned from functions. Therefore this function has become a macro as shown below.
C
C
Compute the nth root of an XFL
Compute a the nth
root of an XFL number
Return the new XFL
βοΈWarningDue to speed constraints,
float_root
converts the argument to an IEEE base-2 double precision floating point before applying n-th root. Therefore the returned result will often contain less precision than expected. If you need better precision you should consider dividing your XFL into a high and a low product then individually take the square roots of those products and multiply the results together.
C
C
π§WarningIf a negative number is passed the function will return
COMPLEX_NOT_SUPPORTED
if the root is an even root.
Convert an XFL floating point into an integer (floor)
Left shift (multiply by 10) the XFL by the number of specified decimal places
Convert the resulting XFL to an integer, discarding any remainder
Return the integer
C
C
πHintNegative return values are reserved for error codes. Therefore if you need to execute this function against a negative XFL you should use
absolute = 1
Get the sign of an XFL enclosing number
Compute the decimal log of an XFL
Compute a the decimal logarithm of an XFL number
Return the new XFL
βοΈWarningDue to speed constraints,
float_log
converts the argument to an IEEE base-2 double precision floating point before applying base 10 log. Therefore the returned result will often contain less precision than expected.
C
C
π§WarningIf a negative number is passed the function will return
COMPLEX_NOT_SUPPORTED
if the root is an even root.
float1
int64_t
An XFL floating point enclosing number representing the first operand to the multiplication
float2
int64_t
An XFL floating point enclosing number representing the second operand to the multiplication
int64_t
The XFL (xls17) enclosing number
If negative, an error:
INVALID_FLOAT
- one of the supplied parameters was not a valid XFL enclosing number
OVERFLOW
- the result of the multiplication was too large to store in an XFL.
float1
int64_t
An XFL floating point enclosing number
int64_t
The XFL (xls17) enclosing number
If negative, an error:
INVALID_FLOAT
- the supplied parameter was not a valid XFL enclosing number or the division resulted in an XFL that cannot be represented.
DIVISION_BY_ZERO
- the supplied parameter was zero.
float1
int64_t
An XFL floating point enclosing number representing the first operand to the comparison
float2
int64_t
An XFL floating point enclosing number representing the second operand to the comparison
mode
uint32_t
A bit-flag field consisting of any of (or any logically valid combination of) the following flags:
COMPARE_LESS
COMPARE_EQUAL
COMPARE_GREATER
Valid combinations are:
COMPARE_LESS
| COMPARE_GREATER
- Not equal
COMPARE_LESS
| COMPARE_EQUAL
- Less than or equal to
COMPARE_GREATER
| COMPARE_EQUAL
- Greater than or equal to
int64_t
0
if the comparison was logically false.
1
if the comparison was logically true.
If negative, an error:
INVALID_FLOAT
- one of the supplied parameters was not a valid XFL enclosing number
INVALID_ARGUMENT
- invalid combination of supplied comparison flags.
float1
int64_t
An XFL floating point enclosing number to act as numerator
float2
int64_t
An XFL floating point enclosing number to act as denominator
int64_t
The XFL (xls17) enclosing number
If negative, an error:
INVALID_FLOAT
- the supplied parameter was not a valid XFL enclosing number or the division resulted in an XFL that cannot be represented.
DIVISION_BY_ZERO
- the supplied parameter was zero.
float1
int64_t
An XFL floating point enclosing number
int64_t
The mantissa of the XFL
If negative, an error:
INVALID_FLOAT
- the supplied parameter was not a valid XFL enclosing number
int64_t
The XFL (xls17) enclosing number
float1
int64_t
An XFL floating point enclosing number
write_ptr
uint32_t
Pointer to a buffer to write the transaction hash to
write_len
uint32_t
The size of the buffer to write the transaction hash to (should be 32.)
read_ptr
uint32_t
Pointer to the transaction to emit
read_len
uint32_t
The length of the transaction
int64_t
On success, the number of bytes of transaction hash written (32), or:
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
PREREQUISITE_NOT_MET
- emit_reserve
must be called first
TOO_MANY_EMITTED_TXN
- the number of emitted transactions is now greater than the promise made when emit_reserve
was called earlier
EMISSION_FAILURE
- the transaction was malformed according to the emission rules.
int64_t
The fee base of the current ledger
read_ptr
uint32_t
Pointer to a buffer contianing the serialized XFL. May be null.
read_len
uint32_t
The length of the buffer.
int64_t
The number of bytes written to the output buffer.
If negative, an error:
NOT_AN_OBJECT
- the supplied buffer did not contain a valid serialized floating point number
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
float1
int64_t
An XFL floating point enclosing number representing the floating point number to take the square root of
n
uint32_t
The root to compute, for example 2
is a square root.
int64_t
The computed nth root
If negative, an error:
INVALID_FLOAT
- the supplied parameter was not a valid XFL enclosing number
COMPLEX_NOT_SUPPORTED
- the supplied parameter was a negative number which would result in a complex root.
float1
int64_t
An XFL floating point enclosing number representing the first operand to the addition
decimal_places
uint32_t
The number of places to shift the decimal to the right before computing the floor of the floating point.
absolute
uint32_t
If 1
also take the absolute of the value before returning it.
int64_t
The computed positive integer
If negative, an error:
INVALID_FLOAT
- one of the supplied parameters was not a valid XFL enclosing number
INVALID_ARGUMENT
- attempted to specify more than 15 decimal places.
CANT_RETURN_NEGATIVE
- attempted to return a negative integer but this is not allowed, use absolute = 1
write_ptr
uint32_t
Pointer to a buffer of a suitable size to store the output. Should be at least 32 bytes.
write_len
uint32_t
Length of the output buffer.
int64_t
The number of bytes written
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
float1
int64_t
An XFL floating point enclosing number
int64_t
The sign of the XFL:
0
if positive, 1
if negative.
If negative, an error:
INVALID_FLOAT
- the supplied parameter was not a valid XFL enclosing number
float1
int64_t
An XFL floating point enclosing number representing the floating point number to take the logarithm of
int64_t
The computed logarithm
If negative, an error:
INVALID_FLOAT
- the supplied parameter was not a valid XFL enclosing number
COMPLEX_NOT_SUPPORTED
- the supplied parameter was a negative number which would result in a complex return value.
Generate a 32 byte nonce for use in an emitted transaction
Write a 32 byte random value to the write_ptr
C
C
write_ptr
uint32_t
Pointer to a buffer of a suitable size to store the output. Should be at least 32 bytes.
write_len
uint32_t
Length of the output buffer.
int64_t
The number of bytes written
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
Retreive the 32 byte namespace biased SHA512H of the currently executing Hook
Look up the hash of the hook installed on hook account at position hook_no
Write the 32 byte hash to write_ptr
C
C
write_ptr
uint32_t
Pointer to a buffer of a suitable size to store the output. Should be at least 32 bytes.
write_len
uint32_t
Length of the output buffer.
hook_no
int32_t
The position in the hook chain the hook is located at, or -1 for the currently executing hook.
int64_t
The number of bytes written
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
DOESNT_EXIST
- The specified hook sequence number doesn't exist in the hook chain.
Retrieve the parameter value for a named hook parameter
Look up the value for a named parameter specified in read_ptr
Write the parameter's value to write_ptr
C
C
write_ptr
uint32_t
Pointer to a buffer of a suitable size to store the output. Should be at least 32 bytes.
write_len
uint32_t
Length of the output buffer.
read_ptr
uint32_t
Pointer to a buffer containing the parameter's name
read_len
uint32_t
Length of the parameter's name
int64_t
The number of bytes written
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
DOESNT_EXIST
- The specified paramater doesn't exist or is null
TOO_SMALL
- The parameter name can't be null
TOO_BIG
- The parameter name is greater than 32 bytes
Fetch the last closed ledger's timestamp
Return the Xahau Timestamp from the last closed ledger.
πTipXahau timestamps are identical to a unix timestamps except that they are offset by
-946684800
.The equivalent unix timestamp is:
ledger_last_time() + 946684800;
C
C
This API takes no parameters.
int64_t
The XRPL timestamp of the last closed ledger
Search for a keylet within a specified range on the current ledger
Read a 34 byte Keylet from the lread_ptr
Read a 32 byte Keylet from the hread_ptr
Search the ledger for the first (lowest) Keylet of this type in this range.
If any matching Keylet is found, write it to write_ptr
.
C
C
write_ptr
uint32_t
Pointer to a buffer to store the output serialised Keylet. .
write_len
uint32_t
Length of the output buffer. Must be 34 bytes
lread_ptr
uint32_t
Pointer to the 34 byte serialised Keylet that represents the lower boundary of the Keylet range to search.
lread_len
uint32_t
Always 34 bytes
hread_ptr
uint32_t
Pointer to the 34 byte serialised Keylet that represents the upper boundary of the Keylet range to search.
hread_len
uint32_t
Always 34 bytes
int64_t
The number of bytes written (34 bytes) on success.
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
TOO_SMALL
/ TOO_BIG
- write_len
, lread_len
or hread_len
was not 34 bytes
INVALID_ARGUMENT
- One or more of the provided Keylets was not a valid serialised Keylet
DOES_NOT_MATCH
- The two provided Keylets were not of the same Keylet Type.
DOESNT_EXIST
- No matching Keylet was found in the specified range.
Retreive the 20 byte Account ID the Hook is executing on
Write the 20 byte Account ID to the write_ptr
C
C
write_ptr
uint32_t
Pointer to a buffer of a suitable size to store the output. Should be at least 20 bytes.
write_len
uint32_t
Length of the output buffer.
int64_t
The number of bytes written
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
Retreive the 32 byte namespace biased SHA512H of the last closed ledger
Write the 32 byte Hash to the write_ptr
C
C
write_ptr
uint32_t
Pointer to a buffer of a suitable size to store the output. Should be at least 32 bytes.
write_len
uint32_t
Length of the output buffer.
int64_t
The number of bytes written
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
Set or delete a parameter on a hook on the same account further down the execution chain
Serialize and output a slotted object
Serialize the object currently occupying the specified slot
Write the serialized version of the object to the output buffer
π Alternative useFor small objects you may avoid using a buffer. Specify
0, 0
forwrite_ptr, write_len
to attempt to return the slotted object as big endian packed data in theint64_t
return code. Up to 63 bits of data may be returned this way.
C
C
Returns the position in the hook chain the currently executing hook occupies
Index into a slotted object and assign a sub-object to another slot
Retrieve the field code of an object in a slot and, optionally, some other information
Index into a slotted array and assign a sub-object to another slot
Set the Hook State on another account for a given key, value and namespace
Read a 32 byte Hook State key from the kread_ptr
Read an arbitrary amount of data from read_ptr
(the value)
Read a 32 byte Namespace from the nread_ptr
Read a 20 byte Account ID from aread_ptr
Update the Hook State key on the specified account within the specified namespace with the value
But only if a on that account allows this.
If the Hook Account is specified in aread_ptr
then the behaviour is that of state_set but still allows specification of namespace through nread_ptr
C
C
π§CautionXRPL sets internally a maximum hook data size. At time of writing and for public testnet this is hard coded at 128 bytes, however in future it will be a validator-votable number.
Retrieve the data pointed to, on another account, by a Hook State key and write it to an output buffer
Read a 20 byte Account ID from the aread_ptr
Read a 32 byte Hook State key from the kread_ptr
Write the data (value) at that key at that Account ID to the buffer pointed to by write_ptr
C
C
πHintEnsure you check the return value. A state lookup can fail of a range of reasons and the buffer will then contain whatever it did before the call (typically all zeros).
Serialize and output a field from the originating transaction
Find the specified sf
field in the originating transaction
Write the serialized version of the field to the output buffer
C
C
βοΈImportantThe field code is not written to the output buffer, only the payload of the field is.
At time of writing for Hooks Public Testnet,
STI_ACCOUNT
fields likesfAccount
are returned without the leading variable length byte.
Retrieve the data pointed to by a Hook State key and write it to an output buffer
Read a 32 byte Hook State key from the kread_ptr
Write the data (value) at that key to the buffer pointed to by write_ptr
C
C
πHintEnsure you check the return value. A state lookup can fail of a range of reasons and the buffer will then contain whatever it did before the call (typically all zeros).
Output the canonical hash of the originating transaction
Use the account_namespace
websocket API to query the Hook State Objects on a particular account in a particular namespace.
Usage:
JSON
Example query:
JSON
Example result:
JSON
read_ptr
uint32_t
Pointer to parameter value
read_len
uint32_t
Length of the parameter value
kread_ptr
uint32_t
Pointer to the parameter name
kread_len
uint32_t
Length of the parameter name
hread_ptr
uint32_t
Pointer to hook hash
hread_len
uint32_t
Length of hook hash (always 32)
int64_t
The length of the parameter value successfully set
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
TOO_SMALL
- The parameter name can't be null
TOO_BIG
- The parameter name is greater than 32 bytes
write_ptr
uint32_t
Pointer to a buffer of a suitable size to store the output.
write_len
uint32_t
Length of the output buffer.
slot_no
uint32_t
The slot number
int64_t
The number of bytes written
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
TOO_SMALL
- output buffer was not large enough to hold the serialized object
read_ptr
uint32_t
Pointer to a buffer containing the hook hash
read_len
uint32_t
Length of the hook hash (always 32)
flags
uint32_t
If 0: - add the hash to the hook skip list If 1 - remove the hash from the hook skip list
int64_t
If successful 1
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
DOESNT_EXIST
- The specified paramater doesn't exist or is null
INVALID_ARGUMENT
- Hash is not 32 bytes
parent_slot
uint32_t
Slot the parent object is in
field_id
uint32_t
The sf
code of the field you are searching for.
To compute this manually take the serialized type
and shift it into the 16 highest bits of uint32_t, then take the field
and place it in the 16 lowest bits.
For example:
sfEmitNonce
has type
5 and field
11 thus its value is 0x050BU
new_slot
uint32_t
New slot number to place the object from the selected field into. If null, choose the next available slot. May be null.
int64_t
The slot number of the newly allocated object
If negative, an error:
DOESNT_EXIST
- The searched for field isn't present in the parent slot or the parent slot is unfilled.
NO_FREE_SLOTS
- The API would require a new slot to be allocated but the Hook is already at the maximum number of slots.
INVALID_FIELD
- The specified field is not a valid sf
field.
NOT_AN_OBJECT
- The slotted object is not a valid STObject.
int64_t
The slot number the object was inserted into
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
INVALID_ARGUMENT
- read_len
must be either 32 or 34 bytes depending on whether a txn hash or a keylet is being used in read_ptr
- the hash or keylet was invalid
DOESNT_EXIST
- the requested object was not found
int64_t
If flags
is 0
then:
The sf
field code of the slotted object
If flags
is 1
then:
1
if and only if the slotted object is an STI_AMOUNT
and the type of the amount is XRP.
If negative, an error:
DOESNT_EXIST
- the specified slot_no
does not contain an object.
NOT_AN_AMOUNT
- flags
was set to 1
but the slotted object is not an STI_AMOUNT
object
parent_slot
uint32_t
Slot the parent array is in
array_id
uint32_t
The sf
code of the field you are searching for.
To compute this manually take the serialized type
and shift it into the 16 highest bits of uint32_t, then take the field
and place it in the 16 lowest bits.
For example:
sfEmitNonce
has type
5 and field
11 thus its value is 0x050BU
new_slot
uint32_t
New slot number to place the object from the selected array index into. If null, choose the next available slot. May be null.
int64_t
The slot number of the newly allocated object
If negative, an error:
DOESNT_EXIST
- The specified array_id
doesn't exist in the array pointed to by parent_slot
NO_FREE_SLOTS
- The API would require a new slot to be allocated but the Hook is already at the maximum number of slots.
NOT_AN_ARRAY
- The specified parent_slot
does not contain an STArray.
read_ptr
uint32_t
Pointer to the data (value) to write into Hook State.
If this is 0
(null) then delete the data at this key. May be null.
read_len
uint32_t
The length of the data.
If this is 0
(null) then delete the data at this key. May be null.
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.)
nread_ptr
uint32_t
A pointer to the namespace which the key belongs to.
nread_len
uint32_t
The length of the namespace. (Should always be 32.)
aread_ptr
uint32_t
A pointer to the Account ID whose state we are trying to modify.
aread_len
uint32_t
The length of the Account ID. (Should always be 20.)
int64_t
The number of bytes written to Hook State (the length of the data.)
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
TOO_BIG
- kread_len
was greater than 32, or
- read_len
was greater than the maximum hook data size.
TOO_SMALL
- kread_len
was 0.
NOT_AUTHORIZED
- no appropriate HookGrant was present on the foreign account to allow this state mutation.
PREVIOUS_FAILURE_PREVENTS_RETRY
- during this execution a previous state_foreign_set
failed with NOT_AUTHORIZED, and consequently no further calls to this API are allowed during this execution.
write_ptr
uint32_t
A pointer to the buffer to write the data in the Hook State into.
write_len
uint32_t
The length of the write buffer.
kread_ptr
uint32_t
Pointer to a buffer containing the Hook State key.
kread_len
uint32_t
The length of the Hook State key. (Should be 32.)
nread_ptr
uint32_t
A pointer to the buffer containing the 32 byte Namespace to lookup the state on
nread_len
uint32_t
The length of the namespace buffer (Should be 32).
aread_ptr
uint32_t
A pointer to a buffer containing the 20 byte Account ID to look up state on.
aread_len
uint32_t
The length of the Account buffer. (Should always be 20).
int64_t
The number of bytes written to the write buffer.
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
DOESNT_EXIST
- the specified Hook State key doesn't have an associated value on the ledger at the time of the call.
TOO_BIG
- the key specified by read_ptr
and read_len
was larger than 32 bytes.
TOO_SMALL
- the output buffer was too small to store the Hook State data.
INVALID_ACCOUNT
- the account specified at aread_ptr
is invalid or does not exist.
int64_t
0
if successful
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
int64_t
The number of bytes written
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
TOO_SMALL
- output buffer was not large enough to hold the serialized field
INVALID_FIELD
- the sf
field_id was invalid
DOESNT_EXIST
- the field was not found in the originating transaction
write_ptr
uint32_t
A pointer to the buffer to write the data in the Hook State into.
write_len
uint32_t
The length of the write buffer.
kread_ptr
uint32_t
Pointer to a buffer containing the Hook State key.
kread_len
uint32_t
The length of the Hook State key. (Should be 32.)
int64_t
The number of bytes written to the write buffer.
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
DOESNT_EXIST
- the specified Hook State key doesn't have an associated value on the ledger at the time of the call.
TOO_BIG
- the key specified by read_ptr
and read_len
was larger than 32 bytes.
TOO_SMALL
- the output buffer was too small to store the Hook State data.
write_ptr
uint32_t
Pointer to a buffer of to store the hash.
write_len
uint32_t
Length of the output buffer. Should be at least 32 bytes.
flags
uint32_t
If 0
:
Write the canonical hash of the originating transaction.
If 1
AND the originating transaction is an EMIT_FAILURE:
Write the canonical hash of the emitting transaction.
int64_t
The number of bytes written
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
TOO_SMALL
- output buffer was not large enough to hold the serialized object
int64_t
0
if successful
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
write_ptr
uint32_t
Pointer to a buffer of a suitable size to store the output. Should be at least 32 bytes.
write_len
uint32_t
Length of the output buffer.
read_ptr
uint32_t
Pointer to a buffer containing the parameter's name
read_len
uint32_t
Length of the parameter's name
int64_t
The number of bytes written
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
DOESNT_EXIST
- The specified paramater doesn't exist or is null
TOO_SMALL
- The parameter name can't be null
TOO_BIG
- The parameter name is greater than 32 bytes
ttPAYMENT
0
ttESCROW_CREATE
1
ttESCROW_FINISH
2
ttACCOUNT_SET
3
ttESCROW_CANCEL
4
ttREGULAR_KEY_SET
5
ttOFFER_CREATE
7
ttOFFER_CANCEL
8
ttTICKET_CREATE
10
ttTICKET_CANCEL
11
ttSIGNER_LIST_SET
12
ttPAYCHAN_CREATE
13
ttPAYCHAN_FUND
14
ttPAYCHAN_CLAIM
15
ttCHECK_CREATE
16
ttCHECK_CASH
17
ttCHECK_CANCEL
18
ttDEPOSIT_PREAUTH
19
ttTRUST_SET
20
ttACCOUNT_DELETE
21
ttHOOK_SET
22
ttURITOKEN_MINT
45
ttURITOKEN_BURN
46
ttURITOKEN_BUY
47
ttURITOKEN_CREATE_SELL_OFFER
48
ttURITOKEN_CANCEL_SELL_OFFER
49
ttGENESIS_MINT
96
ttIMPORT
97
ttCLAIM_REWARD
98
ttINVOKE
99
ttAMENDMENT
100
ttFEE
101
ttUNL_MODIFY
102
ttEMIT_FAILURE
103
ttUNL_REPORT
104
int64_t
PREREQUISITE_NOT_MET
- The originating tx type was not Import
.
NO_FREE_SLOTS
- The API would require a new slot to be allocated but the Hook is already at the maximum number of slots.
slot_no
uint32_t
The slot number
int64_t
1
or an error
If negative, an error:
DOESNT_EXIST
- the specified slot does not contain any object or it is an invalid slot
int64_t
The position in the chain the currently executing hook occupies. The first position is 0.
int64_t
1
iff successfully flagged for Again As Weak.
PREREQUISITE_NOT_MET
- This hook is already being executed weakly at the time of the call.
ALREADY_SET
- The function was already called this execution.
slot_no
uint32_t
The slot number
int64_t
The number of bytes the object occupies when serialized
If negative, an error:
DOESNT_EXIST
- the specified slot does not contain any object or it is an invalid slot
slot_no
uint32_t
The slot number
int64_t
The number of elements inside the slotted array
If negative, an error:
DOESNT_EXIST
- the specified slot does not contain any object or it is an invalid slot
NOT_AN_ARRAY
- the specified slot does not contain an array object
read_ptr
uint32_t
Pointer to a buffer containing the keylet of the object to locate. This can also be a txn hash.
read_len
uint32_t
Length of the read buffer. Should always be 32 or 34.
slot_no
uint32_t
The slot number to emplace into, or 0 if you wish to pick the next available.
slot_no
uint32_t
The slot number
flags
uin32_t
For normal operation this should be 0
.
To determine whether or not an STI_AMOUNT
type contains a native (XRP) amount or a floating point (IOU) amount set to 1
.
rmead_ptr
uint32_t
Pointer to a message to output before the hex-encoded serialized object found in the slot. May be null.
mread_len
uint32_t
Length of the message. May be null.
number
int64_t
The number.
slot_no
uint32_t
The slot number
int64_t
The XFL enclosing number
If negative, an error:
DOESNT_EXIST
- the specified slot does not contain any object or it is an invalid slot
NOT_AN_AMOUNT
- the specified slot does not contain an STI_AMOUNT
object
write_ptr
uint32_t
Pointer to a buffer of a suitable size to store the output.
write_len
uint32_t
Length of the output buffer.
field_id
uint32_t
The sf
code of the field you are searching for.
To compute this manually take the serialized type
and shift it into the 16 highest bits of uint32_t, then take the field
and place it in the 16 lowest bits.
For example:
sfEmitNonce
has type
5 and field
11 thus its value is 0x050BU
rmead_ptr
uint32_t
Pointer to a message to output before the hex-encoded serialized object found in the slot. May be null.
mread_len
uint32_t
Length of the message. May be null.
float1
int64_t
The enclosing XFL integer.
slot_no
uint32_t
The slot number to emplace into, or 0 if you wish to pick the next available.
int64_t
The slot the otxn was placed in
INVALID_ARGUMENT
- specified slot number exceeds the largest possible slot number
NO_FREE_SLOTS
- the request could not granted because no free slot was avaialble to place the originating transaction into.
PREREQUISITE_NOT_MET
- The hook is being Strongly Executed and therefore no transactional metadata is available.
int64_t
The generation of the originating transaction, or 1
if no generation was present on the originating transaction.
int64_t
The burden of the originating transaction, or 1
if no burden was present on the originating transaction.
int64_t
The Transaction Type of the originating transaction. Check the table below for a list of known Transaction Types at time of writing
slot_no_tx
uint32_t
The slot number to emplace the tx blob into.
slot_no_meta
uin32_t
The slot number to emplace the meta blob into.
slot_no
uint32_t
The slot number to emplace into, or 0 if you wish to pick the next available.
int64_t
The slot the otxn was placed in
INVALID_ARGUMENT
- specified slot number exceeds the largest possible slot number
NO_FREE_SLOTS
- the request could not granted because no free slot was avaialble to place the originating transaction into.
Write the contents of a buffer to the XRPLD trace log
Write a buffer from inside the Hook to the trace log along with a message (if any)
C
C
mread_ptr
uint32_t
Pointer to a message to output before the buffer. May be null.
mread_len
uint32_t
Length of the message. May be null.
dread_ptr
uint32_t
Pointer to the buffer to output.
dread_len
uint32_t
Length of the buffer to output.
as_hex
uint32_t
If 1
output the buffer as hex.
If 0
output the buffer as utf-8.
int64_t
0
if successful
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
Set the Hook State for a given key and value
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
C
C
πHintTo delete the state use
state_set(0, 0, SBUF(key);
.
read_ptr
uint32_t
Pointer to the data (value) to write into Hook State.
If this is 0
(null) then delete the data at this key. May be null.
read_len
uint32_t
The length of the data.
If this is 0
(null) then delete the data at this key. May be null.
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.)
π§ CautionXrpl sets internally a maximum hook data size. At time of writing and for public testnet this is hard coded at 128 bytes, however in future it will be a validator-votable number.
int64_t
The number of bytes written to Hook State (the length of the data.)
If negative, an error:
OUT_OF_BOUNDS
- pointers/lengths specified outside of hook memory.
TOO_BIG
- kread_len
was greater than 32, or
- read_len
was greater than the maximum hook data size.
TOO_SMALL
- kread_len
was 0.