Appearance
hook_hash
Summary. Write the 32-byte WASM hash of a hook in the current account's hook chain, identifying which code is (or will be) executed at a given position.
Signature.
c
int64_t hook_hash(uint32_t write_ptr, uint32_t write_len, int32_t hook_no);Parameters.
| Name | Type | Description |
|---|---|---|
write_ptr | uint32_t | Destination buffer. |
write_len | uint32_t | Buffer length; must be at least 32. |
hook_no | int32_t | Chain position to query, or -1 for the currently executing hook. |
Return value. Returns the number of bytes written (32) on success. Errors: TOO_SMALL (-4) if write_len < 32; OUT_OF_BOUNDS (-1) for a bad buffer; INTERNAL_ERROR (-2) if the account's hook object cannot be read; DOESNT_EXIST (-5) if hook_no is beyond the chain or that slot has no sfHookHash.
Common failure patterns.
- Querying a
hook_nothat isn't installed →DOESNT_EXIST. - Buffer shorter than 32 bytes →
TOO_SMALL.
Caveats / notes.
hook_no == -1returns the hash of the hook that is currently running (fromhookCtx.result.hookHash); other values read the on-ledgersfHooksarray.- The hash identifies the
HookDefinition(WASM bytecode), useful for detecting which hook in a multi-hook chain you are, or for feedinghook_skip.
Minimal example.
c
uint8_t h[32];
hook_hash((uint32_t)h, 32, -1); // hash of the current hookPractical example.
c
// Skip the next hook in the chain if it matches a known hash.
uint8_t other[32];
if (hook_hash((uint32_t)other, 32, hook_pos() + 1) == 32)
hook_skip((uint32_t)other, 32, 0);
accept(SBUF("done"), 0);