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
  • Behaviour
  • Definition
  • Example
  • Parameters
  • Return Code

Was this helpful?

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

state_foreign_set

Set the Hook State on another account for a given key, value and namespace

Last updated 2 months ago

Was this helpful?

Behaviour

  • 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

  • Sets the Foreign Hook State with the specified value, key, namespace, and account ID.

  • This operation requires authorization and a Grant to allow this action.

  • Returns the number of bytes written to Hook State (the length of the data), negative on error.

Definition

int64_t state_foreign_set (
    uint32_t read_ptr,
    uint32_t read_len,
    uint32_t kread_ptr,
    uint32_t kread_len,
    uint32_t nread_ptr,
    uint32_t nread_len,
    uint32_t aread_ptr,
    uint32_t aread_len  
);
function state_foreign_set(
    value: ByteArray | HexString | undefined | null,
    key: ByteArray | HexString,
    namespace: ByteArray | HexString | undefined | null,
    accountid: ByteArray | HexString | undefined | null
  ): ErrorCode | number

Example

#define SBUF(str) (uint32_t)(str), sizeof(str)
if (state_foreign_set(SBUF(vault), SBUF(vault_key), SBUF(namespace), SBUF(account)) < 0)
    rollback(SBUF("Error: could not set foreign state!"), 1);
if (state_foreign_set(vault, vault_key, namespace, account) < 0)
    rollback("Error: could not set foreign state!", 1);

Parameters

Name
Type
Description

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

🚧Caution

Xahau 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.

Name
Type
Description

value

ByteArray or HexString

The value of data to persist.

key

ByteArray or HexString

The key of the Hook State to set the value for.

namespace

ByteArray or HexString

The Hook namespace to look in.

accountid

ByteArray or HexString

The owner of the state.

Return Code

Type
Description

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.

Type
Description

number or ErrorCode

Returns the number of bytes written to Hook State (the length of the data), negative on error.

📐
Grant