HookOn Field
Understanding the HookOn field
Section titled “Understanding the HookOn field”Each bit in this unsigned 256-bit integer indicates whether the Hook should execute on a particular transaction type. All bits are active low except bit 22 which is active high. Since 22 is ttHOOK_SET this means the default value of all 0’s will not fire on a SetHook transaction but will fire on every other transaction type. This is a deliberate design choice to help people avoid bricking their Xahau account with a misbehaving hook.
Bits are numbered from right to left:
- bit 0 - right most, i.e. the least significant bit.
- bit 63 - the left-most, i.e. the most significant bit.
Examples (assuming a 256-bit unsigned integer type):
- If we want to completely disable the hook:
~(1ULL << 22) /* every bit is 1 except bit 22 which is 0 */- If we want to disable the hook on everything except ttPAYMENT:
~(1ULL << 22) & ~(1ULL)- If we want to enable the hook on everything except ttHOOK_SET
0- If we want to enable hook firing on ttHOOK_SET (dangerous) and every other transaction type:
(1ULL << 22)HookOn Calculator
Section titled “HookOn Calculator”HookCanEmit Field
Section titled “HookCanEmit Field”(Added by the HookCanEmit amendment.)
HookCanEmit uses the same 256-bit bitmask syntax as HookOn but controls which transaction types a Hook is allowed to emit, rather than which types trigger it.
- Uses the same active-low semantics as
HookOn, with bit 22 (ttHOOK_SET) being active high. - If
HookCanEmitis absent, the Hook may emit any transaction type, includingSetHook.
HookOnIncoming and HookOnOutgoing Fields
Section titled “HookOnIncoming and HookOnOutgoing Fields”(Added by the HookOnV2 amendment.)
Instead of specifying a single HookOn field, Hooks may optionally replace it with two separate fields that differentiate the direction of the triggering transaction:
HookOnIncoming— triggers the Hook on transactions originating from another account (the Hook account is not the initiator).HookOnOutgoing— triggers the Hook on transactions originating from the Hook account itself.
Both fields use the same bit-field syntax as HookOn. HookOnIncoming and HookOnOutgoing are mutually exclusive with HookOn — you must use either HookOn alone or the HookOnIncoming/HookOnOutgoing pair, not both. If only one of the pair is specified, the Hook will not fire on the unspecified direction.
Note: The HookOnIncoming and HookOnOutgoing fields cannot be configured with exactly the same settings. If you need a Hook to respond to both directions using identical criteria, use the HookOn field instead, as it provides a simpler and more appropriate way to define shared trigger behavior.
Using HookOn alone continues to work exactly as before.